Delivery receipts

This commit is contained in:
lilia 2014-12-19 17:15:57 -08:00
parent 1a4811fcef
commit 6cbde7894a
3 changed files with 38 additions and 0 deletions

View file

@ -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);
});
};
})();

View file

@ -178,6 +178,15 @@
m.destroy().then(resolve).fail(reject);
});
}));
},
fetchGroups: function(number) {
return this.fetch({
index: {
name: 'group',
only: number
}
});
}
});
})();

View file

@ -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
}
});
}
});
})()