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
This commit is contained in:
lilia 2015-01-30 11:20:59 -10:00
parent bffdaf9ceb
commit aca3db97da
4 changed files with 10 additions and 4 deletions

View file

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

View file

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

View file

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

View file

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