From 6fbdd63e7eb98e486d0bf49d3e13b593406881f6 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 7 Jun 2017 12:06:23 -0700 Subject: [PATCH] Conversation.onReadMessage - queue job, don't send read receipts We queue the job because we often get a whole lot of read receipts at once, and their markRead calls could very easily overlap given the async pull from DB. We also disable read receipts for any message marked read due to a read receipt. That's a notification explosion we don't need. FREEBIE --- js/models/conversations.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 82f96c618..451070b77 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -71,7 +71,15 @@ // the desktop app, so the desktop app only gets read receipts, we can very // easily end up with messages never marked as read (our previous early read // receipt handling, read receipts never sent because app was offline) - return this.markRead(message.get('received_at')); + + // We queue it because we often get a whole lot of read receipts at once, and + // their markRead calls could very easily overlap given the async pull from DB. + + // Lastly, we don't send read receipts for any message marked read due to a read + // receipt. That's a notification explosion we don't need. + this.queueJob(function() { + return this.markRead(message.get('received_at'), {sendReadReceipts: false}); + }.bind(this)); }, getUnread: function() { @@ -293,7 +301,10 @@ } }, - markRead: function(newestUnreadDate) { + markRead: function(newestUnreadDate, options) { + options = options || {}; + _.defaults(options, {sendReadReceipts: true}); + if (this.get('unreadCount') > 0) { var conversationId = this.id; Whisper.Notifications.remove(Whisper.Notifications.where({ @@ -323,8 +334,10 @@ var unreadCount = unreadMessages.length - read.length; this.save({ unreadCount: unreadCount }); - console.log('Sending', read.length, 'read receipts'); - textsecure.messaging.syncReadMessages(read); + if (options.sendReadReceipts) { + console.log('Sending', read.length, 'read receipts'); + textsecure.messaging.syncReadMessages(read); + } } }.bind(this)); }