diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 37359a22a..14ae62f85 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -802,6 +802,18 @@ export class ConversationModel extends Backbone.Model { } // tslint:disable: cyclomatic-complexity + /** + * Updates the disappearing message settings for this conversation and sends an ExpirationTimerUpdate message if required + * @param providedDisappearingMode + * @param providedExpireTimer + * @param providedChangeTimestamp the timestamp of when the change was made + * @param providedSource the pubkey of the user who made the change + * @param receivedAt the timestamp of when the change was received + * @param fromSync if the change was made from a sync message + * @param shouldCommit if the change should be committed to the DB + * @param existingMessage if we have an existing message model to update + * @returns true, if the change was made or false if it was ignored + */ public async updateExpireTimer({ providedDisappearingMode, providedExpireTimer, @@ -820,10 +832,10 @@ export class ConversationModel extends Backbone.Model { fromSync?: boolean; shouldCommit?: boolean; existingMessage?: MessageModel; - }): Promise { + }): Promise { if (this.isPublic()) { window.log.warn("updateExpireTimer() Disappearing messages aren't supported in communities"); - return; + return false; } let expirationMode = providedDisappearingMode; let expireTimer = providedExpireTimer; @@ -844,7 +856,7 @@ export class ConversationModel extends Backbone.Model { 'WIP: updateExpireTimer() This is an outdated disappearing message setting', `fromSync: ${fromSync}` ); - return; + return false; } // NOTE: We don' mind if the message is the same, we still want to update the conversation because we want to show visible control messages we receive an ExpirationTimerUpdate @@ -858,7 +870,7 @@ export class ConversationModel extends Backbone.Model { fromSync ? 'config/sync ' : '' }message as we already have the same one set.` ); - return; + return false; } const isOutgoing = Boolean(!receivedAt); @@ -935,16 +947,22 @@ export class ConversationModel extends Backbone.Model { window.log.debug( `WIP: updateExpireTimer() We dont send an ExpireTimerUpdate because this was a remote change receivedAt: ${receivedAt} fromSync: ${fromSync}` ); - if (expirationMode !== 'off' && !message.getExpirationStartTimestamp()) { - message.set({ - expirationStartTimestamp: setExpirationStartTimestamp( - expirationMode, - message.get('sent_at'), - 'updateExpireTimer() remote change' - ), - }); + if (!message.getExpirationStartTimestamp()) { + const canBeDeleteAfterSend = this.isMe() || this.isGroup(); + if ( + (canBeDeleteAfterSend && expirationMode === 'legacy') || + expirationMode === 'deleteAfterSend' + ) { + message.set({ + expirationStartTimestamp: setExpirationStartTimestamp( + expirationMode, + message.get('sent_at'), + 'updateExpireTimer() remote change' + ), + }); + } } - return; + return true; } const expireUpdate = { @@ -959,7 +977,7 @@ export class ConversationModel extends Backbone.Model { // TODO Check that the args are correct if (expireUpdate.expirationType === 'deleteAfterRead') { window.log.info('Note to Self messages cannot be delete after read!'); - return; + return true; } const expirationTimerMessage = new ExpirationTimerUpdateMessage(expireUpdate); @@ -970,7 +988,7 @@ export class ConversationModel extends Backbone.Model { // ); await message?.sendSyncMessageOnly(expirationTimerMessage); - return; + return true; } if (this.isPrivate()) { @@ -987,7 +1005,7 @@ export class ConversationModel extends Backbone.Model { expirationTimerMessage, SnodeNamespaces.UserMessages ); - return; + return true; } if (this.isClosedGroup()) { const expireUpdateForGroup = { @@ -1006,7 +1024,7 @@ export class ConversationModel extends Backbone.Model { message: expirationTimerMessage, namespace: SnodeNamespaces.ClosedGroupMessage, }); - return; + return true; } throw new Error('Communities should not use disappearing messages'); } diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index c4bdbb471..7f2db5a76 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -231,7 +231,7 @@ async function handleUserProfileUpdate(result: IncomingConfResult): Promise 0 ? ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached() @@ -245,16 +245,20 @@ async function handleUserProfileUpdate(result: IncomingConfResult): Promise 0 - ? ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached() - ? 'deleteAfterSend' - : 'legacy' - : 'off' - } wrapperNoteToSelfExpirySeconds: ${wrapperNoteToSelfExpirySeconds}` - ); + changes = success; + if (success) { + window.log.debug( + `WIP: [userProfileWrapper] updating disappearing messages for\nconvoId:${ + ourConvo.id + } expiratonMode: ${ + wrapperNoteToSelfExpirySeconds && wrapperNoteToSelfExpirySeconds > 0 + ? ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached() + ? 'deleteAfterSend' + : 'legacy' + : 'off' + } wrapperNoteToSelfExpirySeconds: ${wrapperNoteToSelfExpirySeconds}` + ); + } } // make sure to write the changes to the database now as the `AvatarDownloadJob` triggered by updateOurProfileLegacyOrViaLibSession might take some time before getting run @@ -391,7 +395,7 @@ async function handleContactsUpdate(result: IncomingConfResult): Promise 0 - ? 'deleteAfterSend' - : 'unknown', - expireTimer: fromWrapper.disappearingTimerSeconds, }; await ClosedGroup.updateOrCreateClosedGroup(groupDetails); let changes = await legacyGroupConvo.setPriorityFromWrapper(fromWrapper.priority, false); + if (fromWrapper.disappearingTimerSeconds !== legacyGroupConvo.getExpireTimer()) { + // TODO legacy messages support will be removed in a future release + const success = await legacyGroupConvo.updateExpireTimer({ + providedDisappearingMode: + fromWrapper.disappearingTimerSeconds && fromWrapper.disappearingTimerSeconds > 0 + ? ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached() + ? 'deleteAfterSend' + : 'legacy' + : 'off', + providedExpireTimer: fromWrapper.disappearingTimerSeconds, + providedChangeTimestamp: latestEnvelopeTimestamp, + providedSource: legacyGroupConvo.id, + receivedAt: latestEnvelopeTimestamp, + fromSync: true, + shouldCommit: false, + }); + changes = success; + if (success) { + window.log.debug( + `WIP: [userGroupWrapper] updating disappearing messages for\nconvoId:${ + legacyGroupConvo.id + } expiratonMode: ${ + fromWrapper.disappearingTimerSeconds && fromWrapper.disappearingTimerSeconds > 0 + ? ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached() + ? 'deleteAfterSend' + : 'legacy' + : 'off' + } wrapperNoteToSelfExpirySeconds: ${fromWrapper.disappearingTimerSeconds}` + ); + } + } + const existingTimestampMs = legacyGroupConvo.get('lastJoinedTimestamp'); const existingJoinedAtSeconds = Math.floor(existingTimestampMs / 1000); if (existingJoinedAtSeconds !== fromWrapper.joinedAtSeconds) { @@ -671,7 +704,6 @@ async function handleUserGroupsUpdate(result: IncomingConfResult): Promise