From 151d1797dba54d96b9c1393afe267db8b1ed6a22 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 13 Oct 2017 11:47:13 -0700 Subject: [PATCH] Fix intermittent conversation sort order problem (#1558) We were inserting based on what was already in the DOM, instead of using the index from our conversation collection. FREEBIE --- js/conversation_controller.js | 2 +- js/views/conversation_list_view.js | 13 +++++++++---- js/views/inbox_view.js | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/js/conversation_controller.js b/js/conversation_controller.js index bb72755c3..171122ed2 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -35,7 +35,7 @@ } var title1 = m1.getTitle().toLowerCase(); var title2 = m2.getTitle().toLowerCase(); - if (title1 === title2) { + if (title1 === title2) { return 0; } if (title1 < title2) { diff --git a/js/views/conversation_list_view.js b/js/views/conversation_list_view.js index 42f11a79a..07e01c8e7 100644 --- a/js/views/conversation_list_view.js +++ b/js/views/conversation_list_view.js @@ -8,11 +8,14 @@ Whisper.ConversationListView = Whisper.ListView.extend({ tagName: 'div', itemView: Whisper.ConversationListItemView, - sort: function(conversation) { + updateLocation: function(conversation) { var $el = this.$('.' + conversation.cid); if ($el && $el.length > 0) { - var index = getInboxCollection().indexOf(conversation); - if (index === this.$el.index($el)) { + var inboxCollection = getInboxCollection(); + var index = inboxCollection.indexOf(conversation); + var elIndex = this.$el.index($el); + + if (index === elIndex) { return; } if (index === 0) { @@ -20,7 +23,9 @@ } else if (index === this.collection.length - 1) { this.$el.append($el); } else { - $el.insertBefore(this.$('.conversation-list-item')[index+1]); + var targetConversation = inboxCollection.at(index + 1); + var target = this.$('.' + targetConversation.cid); + $el.insertBefore(target); } } } diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index e9287f575..e677d0562 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -110,7 +110,7 @@ this.inboxListView.listenTo(inboxCollection, 'add change:timestamp change:name change:number', - this.inboxListView.sort); + this.inboxListView.updateLocation); this.searchView = new Whisper.ConversationSearchView({ el : this.$('.search-results'),