From e6d78d583075d96781b354a670cb1afe0df7f3ed Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 7 May 2021 16:06:51 +1000 Subject: [PATCH] fallback to envelope timestamp if dataMessage.timestamp is 0 --- js/background.js | 1 + ts/receiver/dataMessage.ts | 12 +++++++----- ts/receiver/receiver.ts | 6 +++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/js/background.js b/js/background.js index 5a8bb4606..78dd264b0 100644 --- a/js/background.js +++ b/js/background.js @@ -752,6 +752,7 @@ initAPIs(); await initSpecialConversations(); messageReceiver = new textsecure.MessageReceiver(); + // those handleMessageEvent calls are only used by opengroupv1 messageReceiver.addEventListener('message', window.DataMessageReceiver.handleMessageEvent); messageReceiver.addEventListener('sent', window.DataMessageReceiver.handleMessageEvent); messageReceiver.addEventListener('reconnect', onReconnect); diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index 63e45080f..bc43ae2f7 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -230,6 +230,11 @@ export async function processDecrypted( cleanAttachments(decrypted); + // if the decrypted dataMessage timestamp is not set, copy the one from the envelope + if (!_.toNumber(decrypted?.timestamp)) { + decrypted.timestamp = envelope.timestamp; + } + return decrypted as SignalService.DataMessage; /* tslint:disable:no-bitwise */ } @@ -325,6 +330,7 @@ export async function handleDataMessage( } ev.confirm = () => removeFromCache(envelope); + ev.data = { source: senderPubKey, destination: isMe ? message.syncTarget : undefined, @@ -416,17 +422,13 @@ export const isDuplicate = ( ) => { // The username in this case is the users pubKey const sameUsername = m.attributes.source === source; - // testedMessage.id is needed as long as we support opengroupv1 - const sameServerId = - m.attributes.serverId !== undefined && - (testedMessage.serverId || testedMessage.id) === m.attributes.serverId; const sameText = m.attributes.body === testedMessage.body; // Don't filter out messages that are too far apart from each other const timestampsSimilar = Math.abs(m.attributes.sent_at - testedMessage.timestamp) <= PUBLICCHAT_MIN_TIME_BETWEEN_DUPLICATE_MESSAGES; - return sameUsername && sameText && (timestampsSimilar || sameServerId); + return sameUsername && sameText && timestampsSimilar; }; async function handleProfileUpdate( diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index c37e8ecb7..2f375b3f4 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -273,6 +273,10 @@ async function handleDecryptedEnvelope(envelope: EnvelopePlus, plaintext: ArrayB } } +/** + * Only used for opengroupv1 it seems. + * To be removed soon + */ export async function handlePublicMessage(messageData: any) { const { source } = messageData; const { group, profile, profileKey } = messageData.message; @@ -302,7 +306,7 @@ export async function handlePublicMessage(messageData: any) { }, }; - await handleMessageEvent(ev); // open groups + await handleMessageEvent(ev); // open groups v1 } export async function handleOpenGroupV2Message(