signal-desktop/js/views/conversation_list_view.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

/* global Whisper, getInboxCollection, $ */
// eslint-disable-next-line func-names
2018-04-27 21:25:04 +00:00
(function() {
'use strict';
2018-04-27 21:25:04 +00:00
window.Whisper = window.Whisper || {};
2018-04-27 21:25:04 +00:00
Whisper.ConversationListView = Whisper.ListView.extend({
tagName: 'div',
itemView: Whisper.ConversationListItemView,
updateLocation(conversation) {
const $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;
}
const $allConversations = this.$('.conversation-list-item');
const inboxCollection = getInboxCollection();
const index = inboxCollection.indexOf(conversation);
const elIndex = $allConversations.index($el);
2018-04-27 21:25:04 +00:00
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 {
const targetConversation = inboxCollection.at(index - 1);
const target = this.$(`.${targetConversation.cid}`);
2018-04-27 21:25:04 +00:00
$el.insertAfter(target);
}
if ($('.selected').length) {
$('.selected')[0].scrollIntoView({
block: 'nearest',
});
}
2018-04-27 21:25:04 +00:00
},
removeItem(conversation) {
const $el = this.$(`.${conversation.cid}`);
2018-04-27 21:25:04 +00:00
if ($el && $el.length > 0) {
$el.remove();
}
},
});
})();