From 1998f5f6cc5655bee8b62cbc3204d0c5cb316168 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 9 Aug 2024 16:11:17 +1000 Subject: [PATCH 1/3] fix: postpone first sync after start --- ts/receiver/contentMessage.ts | 7 ++++++- .../job_runners/jobs/ConfigurationSyncJob.ts | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 2f1a15962..f930dc4d2 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -306,10 +306,15 @@ async function shouldDropIncomingPrivateMessage( envelope: EnvelopePlus, content: SignalService.Content ) { + const isUs = UserUtils.isUsFromCache(envelope.source); // 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 moreRecentOrNah = await sentAtMoreRecentThanWrapper( + sentAtTimestamp, + isUs ? 'UserConfig' : 'ContactsConfig' + ); const isSyncedMessage = isUsFromCache(envelope.source); + if (moreRecentOrNah === 'wrapper_more_recent') { // we need to check if that conversation is already in the wrapper try { diff --git a/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts b/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts index 9692cba80..f2dbdfe20 100644 --- a/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts +++ b/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts @@ -21,6 +21,7 @@ import { PersistedJob, RunJobResult, } from '../PersistedJob'; +import { DURATION } from '../../../constants'; const defaultMsBetweenRetries = 15000; // a long time between retries, to avoid running multiple jobs at the same time, when one was postponed at the same time as one already planned (5s) const defaultMaxAttempts = 2; @@ -55,6 +56,8 @@ async function retrieveSingleDestinationChanges( return { messages: outgoingConfResults, allOldHashes: compactedHashes }; } +let firstJobStart: number | undefined; + /** * This function is run once we get the results from the multiple batch-send. */ @@ -191,6 +194,18 @@ class ConfigurationSyncJob extends PersistedJob return RunJobResult.Success; } const singleDestChanges = await retrieveSingleDestinationChanges(thisJobDestination); + if (!firstJobStart) { + firstJobStart = Date.now(); + } + + // not ideal, but we need to postpone the first sync job to after we've handled the incoming config messages + // otherwise we are pushing an incomplete config to the network, which will need to be merged and that action alone + // will bump the timestamp of the config. + // We rely on the timestamp of configs to know when to drop messages that would unhide/unremove a conversation. + // The whole thing is a dirty fix of a dirty fix, that will **eventually** need proper fixing + if (Date.now() - firstJobStart <= 20 * DURATION.SECONDS) { + return RunJobResult.RetryJobIfPossible; + } // If there are no pending changes then the job can just complete (next time something // is updated we want to try and run immediately so don't scuedule another run in this case) From 61f20985b1c6b36ed4771fdb653f5f0c7f287d46 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 12 Aug 2024 12:00:30 +1000 Subject: [PATCH 2/3] fix: allow userprofile modal to be clickable --- stylesheets/_session.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/stylesheets/_session.scss b/stylesheets/_session.scss index 6e5344f39..0be7eaefe 100644 --- a/stylesheets/_session.scss +++ b/stylesheets/_session.scss @@ -184,6 +184,7 @@ label { box-shadow: var(--modal-drop-shadow); overflow: hidden; + overflow-y: auto; display: flex; flex-direction: column; From dd2e9a1c1fd75c9fa5cfa827f04cb192c94a456c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 12 Aug 2024 12:00:47 +1000 Subject: [PATCH 3/3] 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;