DRY up early receipt processing

// FREEBIE
This commit is contained in:
lilia 2016-03-14 16:44:58 -07:00
parent 67900753d1
commit f9a3c7817e

View file

@ -305,29 +305,21 @@
} }
if (type === 'outgoing') { if (type === 'outgoing') {
// lazy hack - check for receipts that arrived early. // lazy hack - check for receipts that arrived early.
var recipients;
if (dataMessage.group && dataMessage.group.id) { // group sync if (dataMessage.group && dataMessage.group.id) { // group sync
var members = conversation.get('members') || []; recipients = conversation.get('members') || [];
var receipts = window.receipts.where({ timestamp: timestamp });
for (var i in receipts) {
if (members.indexOf(receipts[i].get('source')) > -1) {
window.receipts.remove(receipts[i]);
message.set({
delivered: (message.get('delivered') || 0) + 1
});
}
}
} else { } else {
var receipt = window.receipts.findWhere({ recipients = [ conversation.id ];
timestamp: timestamp, }
source: conversationId window.receipts.filter(function(receipt) {
}); return (receipt.get('timestamp') === timestamp) &&
if (receipt) { (recipients.indexOf(receipt.get('source')) > -1);
}).forEach(function(receipt) {
window.receipts.remove(receipt); window.receipts.remove(receipt);
message.set({ message.set({
delivered: (message.get('delivered') || 0) + 1 delivered: (message.get('delivered') || 0) + 1
}); });
} });
}
} }
attributes.active_at = now; attributes.active_at = now;
if (type === 'incoming') { if (type === 'incoming') {