Skip to content

Commit

Permalink
Reduce unnecessary updates on conversations at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
liliakai committed Feb 22, 2017
1 parent 280f7a7 commit ace5914
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions js/models/conversations.js
Expand Up @@ -188,12 +188,15 @@
return collection.fetchConversation(this.id, 1).then(function() {
var lastMessage = collection.at(0);
if (lastMessage) {
this.save({
this.set({
lastMessage : lastMessage.getNotificationText(),
timestamp : lastMessage.get('sent_at')
});
} else {
this.save({ lastMessage: '', timestamp: null });
this.set({ lastMessage: '', timestamp: null });
}
if (this.hasChanged('lastMessage') || this.hasChanged('timestamp')) {
this.save();
}
}.bind(this));
},
Expand Down
9 changes: 5 additions & 4 deletions js/views/conversation_list_item_view.js
Expand Up @@ -20,10 +20,11 @@
this.listenTo(this.model, 'change', _.debounce(this.render.bind(this), 1000));
this.listenTo(this.model, 'destroy', this.remove); // auto update
this.listenTo(this.model, 'opened', this.markSelected); // auto update
this.listenTo(this.model.messageCollection, 'add remove',
_.debounce(this.model.updateLastMessage.bind(this.model), 1000));
this.listenTo(this.model, 'newmessage',
_.debounce(this.model.updateLastMessage.bind(this.model), 1000));

var updateLastMessage = _.debounce(this.model.updateLastMessage.bind(this.model), 1000);
this.listenTo(this.model.messageCollection, 'add remove', updateLastMessage);
this.listenTo(this.model, 'newmessage', updateLastMessage);

extension.windows.onClosed(this.stopListening.bind(this));
this.timeStampView = new Whisper.TimestampView({brief: true});
this.model.updateLastMessage();
Expand Down

0 comments on commit ace5914

Please sign in to comment.