From e98c9720c80ddddb9dc151128ff3689241c1c342 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 5 Sep 2023 16:40:16 +1000 Subject: [PATCH] fix: fix synced messages sometimes not appearing --- ts/receiver/contentMessage.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 1a1ff95cd..d7b7db7ca 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -35,6 +35,7 @@ import { getAllCachedECKeyPair, sentAtMoreRecentThanWrapper } from './closedGrou import { ConfigMessageHandler } from './configMessage'; import { ECKeyPair } from './keypairs'; import { ContactsWrapperActions } from '../webworker/workers/browser/libsession_worker_interface'; +import { isUsFromCache } from '../session/utils/User'; export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageHash: string) { try { @@ -292,27 +293,42 @@ async function decrypt(envelope: EnvelopePlus): Promise { return plaintext; } -async function shouldDropIncomingPrivateMessage(sentAtTimestamp: number, envelope: EnvelopePlus) { +async function shouldDropIncomingPrivateMessage( + sentAtTimestamp: number, + envelope: EnvelopePlus, + content: SignalService.Content +) { // sentAtMoreRecentThanWrapper is going to be true, if the latest contact wrapper we processed was roughly more recent that this message timestamp const moreRecentOrNah = await sentAtMoreRecentThanWrapper(sentAtTimestamp, 'ContactsConfig'); + const isSyncedMessage = isUsFromCache(envelope.source); if (moreRecentOrNah === 'wrapper_more_recent') { - // we need to check if that conversation is already in the wrapper, and if yes + // we need to check if that conversation is already in the wrapper try { - const privateConvoInWrapper = await ContactsWrapperActions.get(envelope.source); + // let's check if the corresponding conversation is hidden in the contacts wrapper or not. + // the corresponding conversation is syncTarget when this is a synced message only, so we need to rely on it first, then the envelope.source. + const syncTargetOrSource = isSyncedMessage + ? content.dataMessage?.syncTarget || undefined + : envelope.source; + + if (!syncTargetOrSource) { + return false; + } + + const privateConvoInWrapper = await ContactsWrapperActions.get(syncTargetOrSource); if ( !privateConvoInWrapper || privateConvoInWrapper.priority <= CONVERSATION_PRIORITIES.hidden ) { // the wrapper is more recent that this message and there is no such private conversation. Just drop this incoming message. window.log.info( - `received message from contact ${envelope.source} which appears to be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. Dropping it` + `received message on conversation ${syncTargetOrSource} which appears to be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. Dropping it` ); return true; } window.log.info( - `received message from contact ${envelope.source} which appears to NOT be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. ` + `received message on conversation ${syncTargetOrSource} which appears to NOT be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. ` ); } catch (e) { window.log.warn( @@ -409,7 +425,7 @@ export async function innerHandleSwarmContentMessage( const isPrivateConversationMessage = !envelope.senderIdentity; if (isPrivateConversationMessage) { - if (await shouldDropIncomingPrivateMessage(sentAtTimestamp, envelope)) { + if (await shouldDropIncomingPrivateMessage(sentAtTimestamp, envelope, content)) { await removeFromCache(envelope); return; }