From dd2e9a1c1fd75c9fa5cfa827f04cb192c94a456c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 12 Aug 2024 12:00:47 +1000 Subject: [PATCH] fix: use latestenvelopetimestamp of userprofile conf for nts message --- ts/receiver/contentMessage.ts | 53 ++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index f930dc4d2..a413a1cb0 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -314,7 +314,6 @@ async function shouldDropIncomingPrivateMessage( ); const isSyncedMessage = isUsFromCache(envelope.source); - if (moreRecentOrNah === 'wrapper_more_recent') { // we need to check if that conversation is already in the wrapper try { @@ -324,30 +323,50 @@ async function shouldDropIncomingPrivateMessage( ? content.dataMessage?.syncTarget || undefined : envelope.source; + // handle the `us` case first, as we will never find ourselves in the contacts wrapper. The NTS details are in the UserProfile wrapper. + if (isUs) { + const us = getConversationController().get(envelope.source); + const ourPriority = us?.get('priority') || CONVERSATION_PRIORITIES.default; + if (us && ourPriority <= CONVERSATION_PRIORITIES.hidden) { + // if the wrapper data is more recent than this message and the NTS conversation is hidden, just drop this incoming message to avoid showing the NTS conversation again. + window.log.info( + `shouldDropIncomingPrivateMessage: received message in NTS which appears to be hidden in our most recent libsession userconfig, sentAt: ${sentAtTimestamp}. Dropping it` + ); + return true; + } + window.log.info( + `shouldDropIncomingPrivateMessage: received message on conversation ${syncTargetOrSource} which appears to NOT be hidden/removed in our most recent libsession userconfig, sentAt: ${sentAtTimestamp}. ` + ); + return false; + } + 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. + if (syncTargetOrSource.startsWith('05')) { + 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( + `shouldDropIncomingPrivateMessage: 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( + `shouldDropIncomingPrivateMessage: received message on conversation ${syncTargetOrSource} which appears to NOT be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. ` + ); + } else { window.log.info( - `received message on conversation ${syncTargetOrSource} which appears to be hidden/removed in our most recent libsession contactconfig, sentAt: ${sentAtTimestamp}. Dropping it` + `shouldDropIncomingPrivateMessage: received message on conversation ${syncTargetOrSource} but neither NTS not 05. Probably nothing to do but let it through. ` ); - return true; } - - window.log.info( - `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( - 'ContactsWrapperActions.get in handleSwarmDataMessage failed with', - e.message - ); + window.log.warn('shouldDropIncomingPrivateMessage: failed with', e.message); } } return false;