Delivery receipts
This commit is contained in:
parent
1a4811fcef
commit
6cbde7894a
3 changed files with 38 additions and 0 deletions
|
@ -158,6 +158,25 @@
|
|||
|
||||
function onDeliveryReceipt(pushMessage) {
|
||||
console.log('delivery receipt', pushMessage.source, timestamp);
|
||||
var timestamp = pushMessage.timestamp.toNumber();
|
||||
var messages = new Whisper.MessageCollection();
|
||||
var groups = new Whisper.ConversationCollection();
|
||||
messages.fetchSentAt(timestamp).then(function() {
|
||||
groups.fetchGroups(pushMessage.source).then(function() {
|
||||
for (var message in messages.where({type: 'outgoing'})) {
|
||||
var deliveries = message.get('delivered') || 0;
|
||||
var conversationId = message.get('conversationId');
|
||||
if (conversationId === pushMessage.source || groups.get(conversationId)) {
|
||||
message.save({delivered: deliveries + 1});
|
||||
return;
|
||||
// TODO: consider keeping a list of numbers we've
|
||||
// successfully delivered to?
|
||||
}
|
||||
}
|
||||
});
|
||||
}).fail(function() {
|
||||
console.log('got delivery receipt for unknown message', pushMessage.source, timestamp);
|
||||
});
|
||||
};
|
||||
|
||||
})();
|
||||
|
|
|
@ -178,6 +178,15 @@
|
|||
m.destroy().then(resolve).fail(reject);
|
||||
});
|
||||
}));
|
||||
},
|
||||
|
||||
fetchGroups: function(number) {
|
||||
return this.fetch({
|
||||
index: {
|
||||
name: 'group',
|
||||
only: number
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -47,6 +47,16 @@
|
|||
m.destroy().then(resolve).fail(reject);
|
||||
});
|
||||
}));
|
||||
},
|
||||
|
||||
fetchSentAt: function(timestamp) {
|
||||
return this.fetch({
|
||||
index: {
|
||||
// 'receipt' index on sent_at
|
||||
name: 'receipt',
|
||||
only: timestamp
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})()
|
||||
|
|
Loading…
Reference in a new issue