From 19decad7663a80d2002f0bffa29b838769ed6f95 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 19 May 2022 16:28:31 +1000 Subject: [PATCH] fix: send read receipt when settings ON and window focused --- .../message/message-item/ReadableMessage.tsx | 9 +++++++++ ts/models/conversation.ts | 13 ++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ts/components/conversation/message/message-item/ReadableMessage.tsx b/ts/components/conversation/message/message-item/ReadableMessage.tsx index 9365a09ff..af0ce7584 100644 --- a/ts/components/conversation/message/message-item/ReadableMessage.tsx +++ b/ts/components/conversation/message/message-item/ReadableMessage.tsx @@ -144,9 +144,18 @@ export const ReadableMessage = (props: ReadableMessageProps) => { const found = await getMessageById(messageId); if (found && Boolean(found.get('unread'))) { + const foundReceivedAt = found.get('received_at'); // mark the message as read. // this will trigger the expire timer. await found.markRead(Date.now()); + + // we should stack those and send them in a single message once every 5secs or something. + // this would be part of an redesign of the sending pipeline + if (foundReceivedAt) { + void getConversationController() + .get(found.id) + ?.sendReadReceiptsIfNeeded([foundReceivedAt]); + } } } } diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index b5860ba01..cfcab74c7 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1146,7 +1146,14 @@ export class ConversationModel extends Backbone.Model { // conversation is viewed, another error message shows up for the contact read = read.filter(item => !item.hasErrors); - if (!this.isPrivate() || !read.length || !options.sendReadReceipts) { + if (read.length && options.sendReadReceipts) { + const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array; + await this.sendReadReceiptsIfNeeded(timestamps); + } + } + + public async sendReadReceiptsIfNeeded(timestamps: Array) { + if (!this.isPrivate() || !timestamps.length) { return; } const settingsReadReceiptEnabled = Storage.get(SettingsKey.settingsReadReceipt) || false; @@ -1154,9 +1161,9 @@ export class ConversationModel extends Backbone.Model { settingsReadReceiptEnabled && !this.isBlocked() && !this.isIncomingRequest(); if (sendReceipt) { - window?.log?.info(`Sending ${read.length} read receipts.`); + window?.log?.info(`Sending ${timestamps.length} read receipts.`); + // we should probably stack read receipts and send them every 5 seconds for instance per conversation - const timestamps = _.map(read, 'timestamp').filter(t => !!t) as Array; const receiptMessage = new ReadReceiptMessage({ timestamp: Date.now(), timestamps,