Conversation.markRead() - wait for all database saves are complete
FREEBIE
This commit is contained in:
parent
0b4d14e5ac
commit
6f1a2a9b3e
2 changed files with 12 additions and 4 deletions
|
@ -584,6 +584,7 @@
|
|||
}));
|
||||
|
||||
return this.getUnread().then(function(unreadMessages) {
|
||||
var promises = [];
|
||||
var oldUnread = unreadMessages.filter(function(message) {
|
||||
return message.get('received_at') <= newestUnreadDate;
|
||||
});
|
||||
|
@ -595,7 +596,7 @@
|
|||
console.log('Marked a message as read in the database, but ' +
|
||||
'it was not in messageCollection.');
|
||||
}
|
||||
m.markRead();
|
||||
promises.push(m.markRead());
|
||||
return {
|
||||
sender : m.get('source'),
|
||||
timestamp : m.get('sent_at')
|
||||
|
@ -611,12 +612,17 @@
|
|||
});
|
||||
|
||||
var unreadCount = unreadMessages.length - read.length;
|
||||
this.save({ unreadCount: unreadCount });
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
this.save({ unreadCount: unreadCount }).then(resolve, reject);
|
||||
}.bind(this));
|
||||
promises.push(promise);
|
||||
|
||||
if (read.length && options.sendReadReceipts) {
|
||||
console.log('Sending', read.length, 'read receipts');
|
||||
textsecure.messaging.syncReadMessages(read);
|
||||
promises.push(textsecure.messaging.syncReadMessages(read));
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue