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