From b77d5df4f24bbfc7e672b89ccfbb301fea68c095 Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 26 Feb 2016 12:35:02 -0800 Subject: [PATCH] Fix markRead when messages have not been loaded yet Query the database and not just the in-memory messages. // FREEBIE --- js/models/conversations.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 643b421387e..d432bdfb597 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -210,18 +210,18 @@ conversationId: conversationId })); - var readReceipts = this.messageCollection.where({ - type: 'incoming', unread: 1 - }).map(function(m) { - m.markRead(); - return { - sender : m.get('source'), - timestamp : m.get('sent_at') - }; - }.bind(this)); - if (readReceipts.length > 0) { - textsecure.messaging.sendReadReceipts(readReceipts); - } + this.getUnread().then(function(unreadMessages) { + var read = unreadMessages.map(function(m) { + m.markRead(); + return { + sender : m.get('source'), + timestamp : m.get('sent_at') + }; + }); + if (read.length > 0) { + textsecure.messaging.sendReadReceipts(read); + } + }); } },