From 60aac9be85d31346cdf5bce3fc1470eecf4989f7 Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 19 Sep 2023 17:49:14 +1000 Subject: [PATCH] fix: regular messages correctly sync again --- ts/models/message.ts | 28 +++++++++------------------- ts/session/utils/sync/syncUtils.ts | 25 ++++++++++++++++++++----- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ts/models/message.ts b/ts/models/message.ts index 9cb3c059c..f9c11f393 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -1011,7 +1011,6 @@ export class MessageModel extends Backbone.Model { } const { dataMessage } = content; - // TODO maybe we need to account for lastDisappearingMessageChangeTimestamp? if ( dataMessage && (dataMessage.body?.length || @@ -1028,32 +1027,23 @@ export class MessageModel extends Backbone.Model { // ); const expireUpdate = await checkForExpireUpdateInContentMessage(content, conversation, true); - if ( - !isEmpty(expireUpdate) && - !expireUpdate.isOutdated && - expireUpdate.lastDisappearingMessageChangeTimestamp - ) { - const syncMessage = buildSyncMessage( - this.id, - dataMessage as SignalService.DataMessage, - conversation.id, - sentTimestamp, - expireUpdate - ); + const syncMessage = buildSyncMessage( + this.id, + dataMessage as SignalService.DataMessage, + conversation.id, + sentTimestamp, + expireUpdate + ); + if (syncMessage) { await getMessageQueue().sendSyncMessage({ namespace: SnodeNamespaces.UserMessages, message: syncMessage, }); } - } else { - // NOTE if the expireUpdate is not defined then this settings is most likely out of date so we should not sync it - return; } - this.set({ - sentSync: true, - }); + this.set({ sentSync: true }); await this.commit(); } diff --git a/ts/session/utils/sync/syncUtils.ts b/ts/session/utils/sync/syncUtils.ts index b27d1b4dc..5323a1445 100644 --- a/ts/session/utils/sync/syncUtils.ts +++ b/ts/session/utils/sync/syncUtils.ts @@ -371,7 +371,7 @@ export const buildSyncMessage = ( syncTarget: string, sentTimestamp: number, expireUpdate?: DisappearingMessageUpdate -): VisibleMessage | ExpirationTimerUpdateMessage => { +): VisibleMessage | ExpirationTimerUpdateMessage | null => { if ( (data as any).constructor.name !== 'DataMessage' && !(data instanceof SignalService.DataMessage) @@ -392,17 +392,32 @@ export const buildSyncMessage = ( !isEmpty(expireUpdate) && expireUpdate.lastDisappearingMessageChangeTimestamp ) { - const syncExpireTimerMessage = buildSyncExpireTimerMessage( + if (expireUpdate.isOutdated) { + window.log.debug(`WIP: buildSyncMessage: \nexpireUpdate is outdated`); + return null; + } + + const expireTimerSyncMessage = buildSyncExpireTimerMessage( identifier, expireUpdate, timestamp, syncTarget ); + window.log.warn( - `WIP: buildSyncMessage: \nsyncExpireTimerMessage: ${JSON.stringify(syncExpireTimerMessage)}` + `WIP: buildSyncMessage: \nexpireTimerSyncMessage: ${JSON.stringify(expireTimerSyncMessage)}` ); - return syncExpireTimerMessage; + return expireTimerSyncMessage; } - return buildSyncVisibleMessage(identifier, dataMessage, timestamp, syncTarget); + const visibleSyncMessage = buildSyncVisibleMessage( + identifier, + dataMessage, + timestamp, + syncTarget + ); + window.log.warn( + `WIP: buildSyncMessage: \nvisibleSyncMessage: ${JSON.stringify(visibleSyncMessage)}` + ); + return visibleSyncMessage; };