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
pull/749/head
Scott Nonnenberg 8 years ago committed by GitHub
parent fb7701576e
commit 151d1797db

@ -35,7 +35,7 @@
} }
var title1 = m1.getTitle().toLowerCase(); var title1 = m1.getTitle().toLowerCase();
var title2 = m2.getTitle().toLowerCase(); var title2 = m2.getTitle().toLowerCase();
if (title1 === title2) { if (title1 === title2) {
return 0; return 0;
} }
if (title1 < title2) { if (title1 < title2) {

@ -8,11 +8,14 @@
Whisper.ConversationListView = Whisper.ListView.extend({ Whisper.ConversationListView = Whisper.ListView.extend({
tagName: 'div', tagName: 'div',
itemView: Whisper.ConversationListItemView, itemView: Whisper.ConversationListItemView,
sort: function(conversation) { updateLocation: function(conversation) {
var $el = this.$('.' + conversation.cid); var $el = this.$('.' + conversation.cid);
if ($el && $el.length > 0) { if ($el && $el.length > 0) {
var index = getInboxCollection().indexOf(conversation); var inboxCollection = getInboxCollection();
if (index === this.$el.index($el)) { var index = inboxCollection.indexOf(conversation);
var elIndex = this.$el.index($el);
if (index === elIndex) {
return; return;
} }
if (index === 0) { if (index === 0) {
@ -20,7 +23,9 @@
} else if (index === this.collection.length - 1) { } else if (index === this.collection.length - 1) {
this.$el.append($el); this.$el.append($el);
} else { } else {
$el.insertBefore(this.$('.conversation-list-item')[index+1]); var targetConversation = inboxCollection.at(index + 1);
var target = this.$('.' + targetConversation.cid);
$el.insertBefore(target);
} }
} }
} }

@ -110,7 +110,7 @@
this.inboxListView.listenTo(inboxCollection, this.inboxListView.listenTo(inboxCollection,
'add change:timestamp change:name change:number', 'add change:timestamp change:name change:number',
this.inboxListView.sort); this.inboxListView.updateLocation);
this.searchView = new Whisper.ConversationSearchView({ this.searchView = new Whisper.ConversationSearchView({
el : this.$('.search-results'), el : this.$('.search-results'),

Loading…
Cancel
Save