Reduce unnecessary updates on conversations at startup
This commit is contained in:
parent
280f7a74b1
commit
ace59147ab
2 changed files with 10 additions and 6 deletions
|
@ -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));
|
||||
},
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue