Skip to content

Commit

Permalink
Left pane: small sorting fix, logging for error cases (#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg authored Jan 13, 2018
1 parent ce01eb7 commit 743e897
Showing 1 changed file with 38 additions and 16 deletions.
54 changes: 38 additions & 16 deletions js/views/conversation_list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,45 @@
itemView: Whisper.ConversationListItemView,
updateLocation: function(conversation) {
var $el = this.$('.' + conversation.cid);
if ($el && $el.length > 0) {
var inboxCollection = getInboxCollection();
var index = inboxCollection.indexOf(conversation);
var elIndex = this.$el.index($el);

if (index === elIndex) {
return;
}
if (index === 0) {
this.$el.prepend($el);
} else if (index === this.collection.length - 1) {
this.$el.append($el);
} else {
var targetConversation = inboxCollection.at(index + 1);
var target = this.$('.' + targetConversation.cid);
$el.insertBefore(target);
}
if (!$el || !$el.length) {
console.log(
'updateLocation: did not find element for conversation',
conversation.idForLogging()
);
return;
}
if ($el.length > 1) {
console.log(
'updateLocation: found more than one element for conversation',
conversation.idForLogging()
);
return;
}

var $allConversations = this.$('.conversation-list-item');
var inboxCollection = getInboxCollection();
var index = inboxCollection.indexOf(conversation);

var elIndex = $allConversations.index($el);
if (elIndex < 0) {
console.log(
'updateLocation: did not find index for conversation',
conversation.idForLogging()
);
}

if (index === elIndex) {
return;
}
if (index === 0) {
this.$el.prepend($el);
} else if (index === this.collection.length - 1) {
this.$el.append($el);
} else {
var targetConversation = inboxCollection.at(index - 1);
var target = this.$('.' + targetConversation.cid);
$el.insertAfter(target);
}
},
removeItem: function(conversation) {
Expand Down

0 comments on commit 743e897

Please sign in to comment.