New messages auto-update the inbox & conversation

When a new message arrives, if its conversation is not already opened,
the background page opens it. If it is alrady open the window is
focused. Finally, the 'message' event is triggered, resulting in
   1. the inbox refetches conversations
   2. all conversations fetch new messages

TODO: only send this event to the target window
pull/749/head
lilia 10 years ago
parent bffdaf9ceb
commit aca3db97da

@ -194,6 +194,7 @@
conversation.save().then(function() {
message.save().then(function() {
extension.trigger('message', message); // notify frontend listeners
openConversation(conversation.id);
});
});
});

@ -26,6 +26,7 @@
new Whisper.ConversationView({
model: conversation
}).render().$el.prependTo($('body'));
window.conversation = conversation;
});
};

@ -42,6 +42,11 @@
if (this.model.id) {
this.model.fetchMessages({reset: true});
}
extension.on('message', function() {
this.model.fetchMessages();
}.bind(this));
window.addEventListener('resize', this.view.resize.bind(this.view));
},

@ -38,12 +38,11 @@
this.$el.addClass('loading');
this.conversations.fetchActive({reset: true}).then(function() {
this.$el.removeClass('loading');
window.conversations = this.conversations;
}.bind(this));
extension.on('message', function(message) {
this.conversations.fetch({id: message.conversationId}).then(function() {
this.conversations.get(message.conversationId).fetchMessages();
}.bind(this));
extension.on('message', function() {
this.conversations.fetchActive({reset: true});
}.bind(this));
window.addEventListener('resize', this.inbox.resize.bind(this.inbox));
},

Loading…
Cancel
Save