From 93b450ce56df6e35db8e6108f9d15c985dad21f1 Mon Sep 17 00:00:00 2001 From: William Grant Date: Tue, 26 Sep 2023 18:13:06 +1000 Subject: [PATCH] feat: hit expire endpoint for read messages for now it will hit the expire endpoint twice --- ts/models/conversation.ts | 3 ++- ts/models/message.ts | 9 +++++++-- ts/session/sending/MessageSender.ts | 2 +- ts/util/expiringMessages.ts | 11 +++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 31c0da668..b046d80d7 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -2058,7 +2058,8 @@ export class ConversationModel extends Backbone.Model { const readDetails = []; // eslint-disable-next-line no-restricted-syntax for (const nowRead of oldUnreadNowRead) { - nowRead.markMessageReadNoCommit(readAt); + // eslint-disable-next-line no-await-in-loop + await nowRead.markMessageReadNoCommit(readAt); const validTimestamp = nowRead.get('sent_at') || nowRead.get('serverTimestamp'); if (nowRead.get('source') && validTimestamp && isFinite(validTimestamp)) { diff --git a/ts/models/message.ts b/ts/models/message.ts index 610be597b..7b7c3ef54 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -93,6 +93,7 @@ import { setExpirationStartTimestamp, changeToDisappearingMessageConversationType, checkForExpireUpdateInContentMessage, + updateMessageExpiryOnSwarm, } from '../util/expiringMessages'; import { LinkPreviews } from '../util/linkPreviews'; import { Notifications } from '../util/notifications'; @@ -1092,7 +1093,7 @@ export class MessageModel extends Backbone.Model { } public async markMessageAsRead(readAt: number) { - this.markMessageReadNoCommit(readAt); + await this.markMessageReadNoCommit(readAt); await this.commit(); // the line below makes sure that getNextExpiringMessage will find this message as expiring. // getNextExpiringMessage is used on app start to clean already expired messages which should have been removed already, but are not @@ -1101,7 +1102,7 @@ export class MessageModel extends Backbone.Model { await this.getConversation()?.refreshInMemoryDetails(); } - public markMessageReadNoCommit(readAt: number) { + public async markMessageReadNoCommit(readAt: number) { this.set({ unread: READ_MESSAGE_STATE.read }); const convo = this.getConversation(); @@ -1117,6 +1118,10 @@ export class MessageModel extends Backbone.Model { ); if (expirationMode === 'legacy' || expirationMode === 'deleteAfterRead') { + if (this.isIncoming() && !this.isExpiring()) { + await updateMessageExpiryOnSwarm(this, 'markMessageReadNoCommit()', true); + } + this.set({ expirationStartTimestamp: setExpirationStartTimestamp( expirationMode, diff --git a/ts/session/sending/MessageSender.ts b/ts/session/sending/MessageSender.ts index ec5a642cf..232275754 100644 --- a/ts/session/sending/MessageSender.ts +++ b/ts/session/sending/MessageSender.ts @@ -185,7 +185,7 @@ async function send( canBeDeleteAfterRead && (expirationMode === 'legacy' || expirationMode === 'deleteAfterRead') ) { - foundMessage = await updateMessageExpiryOnSwarm(foundMessage); + foundMessage = await updateMessageExpiryOnSwarm(foundMessage, 'send()'); } } diff --git a/ts/util/expiringMessages.ts b/ts/util/expiringMessages.ts index c7f4c4905..50823c65c 100644 --- a/ts/util/expiringMessages.ts +++ b/ts/util/expiringMessages.ts @@ -637,8 +637,15 @@ export async function checkHasOutdatedDisappearingMessageClient( } } -export async function updateMessageExpiryOnSwarm(message: MessageModel, shouldCommit?: boolean) { - window.log.debug(`WIP: [updateMessageExpiryOnSwarm]\nmessage: ${JSON.stringify(message)}`); +export async function updateMessageExpiryOnSwarm( + message: MessageModel, + callLocation?: string, // this is for debugging purposes + shouldCommit?: boolean +) { + if (callLocation) { + window.log.debug(`WIP: [updateMessageExpiryOnSwarm] called from: ${callLocation} `); + } + // window.log.debug(`WIP: [updateMessageExpiryOnSwarm]\nmessage: ${JSON.stringify(message)}`); const messageHash = message.get('messageHash'); const expiresAt = message.get('expires_at');