signal-desktop/js/views/conversation_list_view.js

65 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-04-27 21:25:04 +00:00
(function() {
'use strict';
window.Whisper = window.Whisper || {};
2018-04-27 21:25:04 +00:00
Whisper.ConversationListView = Whisper.ListView.extend({
tagName: 'div',
itemView: Whisper.ConversationListItemView,
updateLocation: function(conversation) {
var $el = this.$('.' + conversation.cid);
2018-04-27 21:25:04 +00:00
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;
}
2018-04-27 21:25:04 +00:00
var $allConversations = this.$('.conversation-list-item');
var inboxCollection = getInboxCollection();
var index = inboxCollection.indexOf(conversation);
2018-04-27 21:25:04 +00:00
var elIndex = $allConversations.index($el);
if (elIndex < 0) {
console.log(
'updateLocation: did not find index for conversation',
conversation.idForLogging()
);
}
2018-04-27 21:25:04 +00:00
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);
}
if ($('.selected').length) {
$('.selected')[0].scrollIntoView({
block: 'nearest',
});
}
2018-04-27 21:25:04 +00:00
},
removeItem: function(conversation) {
var $el = this.$('.' + conversation.cid);
if ($el && $el.length > 0) {
$el.remove();
}
},
});
})();