Conversation.markRead() - wait for all database saves are complete
FREEBIE
This commit is contained in:
@@ -584,6 +584,7 @@
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
return this.getUnread().then(function(unreadMessages) {
|
return this.getUnread().then(function(unreadMessages) {
|
||||||
|
var promises = [];
|
||||||
var oldUnread = unreadMessages.filter(function(message) {
|
var oldUnread = unreadMessages.filter(function(message) {
|
||||||
return message.get('received_at') <= newestUnreadDate;
|
return message.get('received_at') <= newestUnreadDate;
|
||||||
});
|
});
|
||||||
@@ -595,7 +596,7 @@
|
|||||||
console.log('Marked a message as read in the database, but ' +
|
console.log('Marked a message as read in the database, but ' +
|
||||||
'it was not in messageCollection.');
|
'it was not in messageCollection.');
|
||||||
}
|
}
|
||||||
m.markRead();
|
promises.push(m.markRead());
|
||||||
return {
|
return {
|
||||||
sender : m.get('source'),
|
sender : m.get('source'),
|
||||||
timestamp : m.get('sent_at')
|
timestamp : m.get('sent_at')
|
||||||
@@ -611,12 +612,17 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
var unreadCount = unreadMessages.length - read.length;
|
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) {
|
if (read.length && options.sendReadReceipts) {
|
||||||
console.log('Sending', read.length, 'read receipts');
|
console.log('Sending', read.length, 'read receipts');
|
||||||
textsecure.messaging.syncReadMessages(read);
|
promises.push(textsecure.messaging.syncReadMessages(read));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -533,7 +533,9 @@
|
|||||||
Whisper.Notifications.remove(Whisper.Notifications.where({
|
Whisper.Notifications.remove(Whisper.Notifications.where({
|
||||||
messageId: this.id
|
messageId: this.id
|
||||||
}));
|
}));
|
||||||
return this.save();
|
return new Promise(function(resolve, reject) {
|
||||||
|
this.save().then(resolve, reject);
|
||||||
|
}.bind(this));
|
||||||
},
|
},
|
||||||
isExpiring: function() {
|
isExpiring: function() {
|
||||||
return this.get('expireTimer') && this.get('expirationStartTimestamp');
|
return this.get('expireTimer') && this.get('expirationStartTimestamp');
|
||||||
|
Reference in New Issue
Block a user