Avoid querying groups on delivery receipts if possible

This commit is contained in:
lilia 2017-02-22 13:19:44 -08:00
parent c8a0fe5a92
commit b7fac17ec8

View file

@ -41,17 +41,23 @@
},
onReceipt: function(receipt) {
var messages = new Whisper.MessageCollection();
var groups = new GroupCollection();
Promise.all([
groups.fetchGroups(receipt.get('source')),
messages.fetchSentAt(receipt.get('timestamp'))
]).then(function() {
var ids = groups.pluck('id');
ids.push(receipt.get('source'));
messages.fetchSentAt(receipt.get('timestamp')).then(function() {
if (messages.length === 0) { return; }
var message = messages.find(function(message) {
return (!message.isIncoming() &&
_.contains(ids, message.get('conversationId')));
return (!message.isIncoming() && receipt.get('source') === message.get('conversationId'));
});
if (message) { return message; }
var groups = new GroupCollection();
return groups.fetchGroups(receipt.get('source')).then(function() {
var ids = groups.pluck('id');
ids.push(receipt.get('source'));
return messages.find(function(message) {
return (!message.isIncoming() &&
_.contains(ids, message.get('conversationId')));
});
});
}).then(function(message) {
if (message) {
this.remove(receipt);
var deliveries = message.get('delivered') || 0;