From 56aee5e8ef641717ab8a2da488233e505e968a0d Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 29 Sep 2016 15:26:11 -0700 Subject: [PATCH] Update conversation snippets automatically Fixes stale snippets after the message has expired --- js/models/conversations.js | 12 ++++++++++++ js/views/conversation_list_item_view.js | 2 ++ 2 files changed, 14 insertions(+) diff --git a/js/models/conversations.js b/js/models/conversations.js index 86178625c0..1a34c87e5d 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -167,6 +167,18 @@ }.bind(this)); }, + updateLastMessage: function() { + var lastMessage = this.messageCollection.at(this.messageCollection.length - 1); + if (lastMessage) { + this.save({ + lastMessage : lastMessage.getNotificationText(), + timestamp : lastMessage.get('sent_at') + }); + } else { + this.save({ lastMessage: '', timestamp: null }); + } + }, + addExpirationTimerUpdate: function(time, source) { var now = Date.now(); this.save({ expireTimer: time }); diff --git a/js/views/conversation_list_item_view.js b/js/views/conversation_list_item_view.js index 8e72b4fc75..aad25bfca1 100644 --- a/js/views/conversation_list_item_view.js +++ b/js/views/conversation_list_item_view.js @@ -20,6 +20,8 @@ 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)); extension.windows.onClosed(this.stopListening.bind(this)); this.timeStampView = new Whisper.TimestampView({brief: true}); },