From f9a3c7817e0c4645506b7d9d87b4e5acf8a332a9 Mon Sep 17 00:00:00 2001 From: lilia Date: Mon, 14 Mar 2016 16:44:58 -0700 Subject: [PATCH] DRY up early receipt processing // FREEBIE --- js/models/messages.js | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index b017956d..deb10655 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -305,29 +305,21 @@ } if (type === 'outgoing') { // lazy hack - check for receipts that arrived early. + var recipients; if (dataMessage.group && dataMessage.group.id) { // group sync - var members = 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 - }); - } - } + recipients = conversation.get('members') || []; } else { - var receipt = window.receipts.findWhere({ - timestamp: timestamp, - source: conversationId - }); - if (receipt) { - window.receipts.remove(receipt); - message.set({ - delivered: (message.get('delivered') || 0) + 1 - }); - } + 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); + message.set({ + delivered: (message.get('delivered') || 0) + 1 + }); + }); } attributes.active_at = now; if (type === 'incoming') {