Read/Delivery Receipts: Wait for resolution in main queue

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-08-03 18:10:45 -07:00
parent 92ba295d52
commit 7faf83bc01
3 changed files with 23 additions and 20 deletions

View file

@ -5,9 +5,6 @@
'use strict';
window.Whisper = window.Whisper || {};
Whisper.ReadReceipts = new (Backbone.Collection.extend({
initialize: function() {
this.on('add', this.onReceipt);
},
forMessage: function(message) {
var receipt = this.findWhere({
sender: message.get('source'),
@ -21,13 +18,13 @@
},
onReceipt: function(receipt) {
var messages = new Whisper.MessageCollection();
messages.fetchSentAt(receipt.get('timestamp')).then(function() {
return messages.fetchSentAt(receipt.get('timestamp')).then(function() {
var message = messages.find(function(message) {
return (message.isIncoming() && message.isUnread() &&
message.get('source') === receipt.get('sender'));
});
if (message) {
message.markRead(receipt.get('read_at')).then(function() {
return message.markRead(receipt.get('read_at')).then(function() {
this.notifyConversation(message);
this.remove(receipt);
}.bind(this));