Save incoming messages and pass to frontend asynchronously

After a message is saved asynchronsly, fire an event and pass the
message attributes to frontend listeners via the chrome-runtime API.

This behavior is similar to the 'storage' event fired by localStorage.
This commit is contained in:
lilia 2014-11-16 13:19:51 -08:00
parent ced295a630
commit 470346c9c4
9 changed files with 110 additions and 85 deletions

View file

@ -25,7 +25,9 @@
if (textsecure.registration.isDone()) {
var conversations = new Whisper.ConversationCollection();
textsecure.subscribeToPush(function(message) {
conversations.addIncomingMessage(message);
conversations.addIncomingMessage(message).then(function(message) {
extension.trigger('message', message);
});
console.log("Got message from " + message.pushMessage.source + "." + message.pushMessage.sourceDevice +
': "' + getString(message.message.body) + '"');
var newUnreadCount = textsecure.storage.getUnencrypted("unreadCount", 0) + 1;