Avoid querying groups on delivery receipts if possible
This commit is contained in:
parent
c8a0fe5a92
commit
b7fac17ec8
1 changed files with 15 additions and 9 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue