From 07a0463b65e3e2df9de99ddf894eff9e9c031002 Mon Sep 17 00:00:00 2001 From: lilia Date: Fri, 25 Mar 2016 10:39:36 -0700 Subject: [PATCH] Fix conversation list self-resorting When deleting all messages in a conversation, the entry in the left pane should be inserted into the alphabetical portion of the list. To keep it in this collection, do not nullify active_at. To ensure the list view is keeping itself correctly sorted, make sure that resorting behavior is triggered any time a relevant attribute is changed. This fixes deleted conversations jumping to the top of the list, and conversation order scrambling when getting a group or contact sync message from our master device. Fixes #734 // FREEBIE --- js/conversation_controller.js | 2 +- js/models/conversations.js | 2 +- js/views/conversation_list_view.js | 11 ++++++----- js/views/inbox_view.js | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 510d9e5cf..5ca8354f7 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -12,7 +12,7 @@ var conversations = new Whisper.ConversationCollection(); var inboxCollection = new (Backbone.Collection.extend({ initialize: function() { - this.on('change:active_at', this.sort); + this.on('change:timestamp change:name change:number', this.sort); this.on('add remove change:unreadCount', this.updateUnreadCount); this.listenTo(conversations, 'add change:active_at', this.addActive); diff --git a/js/models/conversations.js b/js/models/conversations.js index 2897aceff..1e35a65ae 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -283,7 +283,7 @@ var models = this.messageCollection.models; this.messageCollection.reset([]); _.each(models, function(message) { message.destroy(); }); - this.save({active_at: null, lastMessage: '', timestamp: null}); // archive + this.save({lastMessage: null, timestamp: null}); // archive }.bind(this)); }, diff --git a/js/views/conversation_list_view.js b/js/views/conversation_list_view.js index e594f152c..0fd3374c1 100644 --- a/js/views/conversation_list_view.js +++ b/js/views/conversation_list_view.js @@ -8,14 +8,15 @@ Whisper.ConversationListView = Whisper.ListView.extend({ tagName: 'div', itemView: Whisper.ConversationListItemView, - onChangeActiveAt: function(conversation) { + sort: function(conversation) { + console.log('sorting conversation', conversation.id); var $el = this.$('.' + conversation.cid); if ($el && $el.length > 0) { - if (conversation.get('active_at')) { - $el.prependTo(this.el); - } else { - var index = getInboxCollection().indexOf(conversation); + var index = getInboxCollection().indexOf(conversation); + if (index > 0) { $el.insertBefore(this.$('.conversation-list-item')[index+1]); + } else { + this.$el.prepend($el); } } } diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index 758111c8f..abb9e789e 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -68,8 +68,8 @@ }).render(); this.inboxListView.listenTo(inboxCollection, - 'add change:active_at', - this.inboxListView.onChangeActiveAt); + 'add change:timestamp change:name change:number', + this.inboxListView.sort); this.searchView = new Whisper.ConversationSearchView({ el : this.$('.search-results'),