From aeefc530d25b8b7bab9c73cd482ac888c7e95ef6 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 7 Jun 2017 12:20:25 -0700 Subject: [PATCH] Conversation.markRead: Remove checks for unread We will now always attempt to mark things unread if this method. If the conversation's unreadCount gets out of date, set to zero, we will still do it. If we go through the motions, and nothing is newly marked read, we will still set the unreadCount to zero. --- js/models/conversations.js | 60 ++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 451070b777f1..0e6cb1a2ae6b 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -305,42 +305,38 @@ options = options || {}; _.defaults(options, {sendReadReceipts: true}); - if (this.get('unreadCount') > 0) { - var conversationId = this.id; - Whisper.Notifications.remove(Whisper.Notifications.where({ - conversationId: conversationId - })); + var conversationId = this.id; + Whisper.Notifications.remove(Whisper.Notifications.where({ + conversationId: conversationId + })); - this.getUnread().then(function(unreadMessages) { - var oldUnread = unreadMessages.filter(function(message) { - return message.get('received_at') <= newestUnreadDate; - }); + this.getUnread().then(function(unreadMessages) { + var oldUnread = unreadMessages.filter(function(message) { + return message.get('received_at') <= newestUnreadDate; + }); - var read = _.map(oldUnread, function(m) { - if (this.messageCollection.get(m.id)) { - m = this.messageCollection.get(m.id); - } else { - console.log('Marked a message as read in the database, but ' + - 'it was not in messageCollection.'); - } - m.markRead(); - return { - sender : m.get('source'), - timestamp : m.get('sent_at') - }; - }.bind(this)); - - if (read.length > 0) { - var unreadCount = unreadMessages.length - read.length; - this.save({ unreadCount: unreadCount }); - - if (options.sendReadReceipts) { - console.log('Sending', read.length, 'read receipts'); - textsecure.messaging.syncReadMessages(read); - } + var read = _.map(oldUnread, function(m) { + if (this.messageCollection.get(m.id)) { + m = this.messageCollection.get(m.id); + } else { + console.log('Marked a message as read in the database, but ' + + 'it was not in messageCollection.'); } + m.markRead(); + return { + sender : m.get('source'), + timestamp : m.get('sent_at') + }; }.bind(this)); - } + + var unreadCount = unreadMessages.length - read.length; + this.save({ unreadCount: unreadCount }); + + if (read.length && options.sendReadReceipts) { + console.log('Sending', read.length, 'read receipts'); + textsecure.messaging.syncReadMessages(read); + } + }.bind(this)); }, fetchMessages: function() {