Refactor delivery receipt tracking

Move code for matching receipts to messages (and vice versa) to its own
file.

// FREEBIE
This commit is contained in:
lilia 2016-04-11 15:06:06 -07:00
parent 18012688ea
commit d1e9534542
5 changed files with 80 additions and 56 deletions

View file

@ -317,18 +317,8 @@
}
}
if (type === 'outgoing') {
// lazy hack - check for receipts that arrived early.
var recipients;
if (dataMessage.group && dataMessage.group.id) { // group sync
recipients = conversation.get('members') || [];
} else {
recipients = [ conversation.id ];
}
window.receipts.filter(function(receipt) {
return (receipt.get('timestamp') === timestamp) &&
(recipients.indexOf(receipt.get('source')) > -1);
}).forEach(function(receipt) {
window.receipts.remove(receipt);
var receipts = Whisper.DeliveryReceipts.forMessage(conversation, message);
receipts.forEach(function(receipt) {
message.set({
delivered: (message.get('delivered') || 0) + 1
});
@ -402,13 +392,15 @@
},
fetchSentAt: function(timestamp) {
return this.fetch({
index: {
// 'receipt' index on sent_at
name: 'receipt',
only: timestamp
}
});
return new Promise(function(resolve) {
return this.fetch({
index: {
// 'receipt' index on sent_at
name: 'receipt',
only: timestamp
}
}).always(resolve);
}.bind(this));
},
fetchConversation: function(conversationId, limit) {