2018-07-09 21:29:13 +00:00
|
|
|
/* global Whisper, getInboxCollection, $ */
|
2018-07-07 00:48:14 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2018-07-07 00:48:14 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-07-22 18:55:26 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
Whisper.ConversationListView = Whisper.ListView.extend({
|
|
|
|
tagName: 'div',
|
|
|
|
itemView: Whisper.ConversationListItemView,
|
2018-07-07 00:48:14 +00:00
|
|
|
updateLocation(conversation) {
|
|
|
|
const $el = this.$(`.${conversation.cid}`);
|
2017-10-13 18:47:13 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
if (!$el || !$el.length) {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.warn(
|
2018-04-27 21:25:04 +00:00
|
|
|
'updateLocation: did not find element for conversation',
|
|
|
|
conversation.idForLogging()
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($el.length > 1) {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.warn(
|
2018-04-27 21:25:04 +00:00
|
|
|
'updateLocation: found more than one element for conversation',
|
|
|
|
conversation.idForLogging()
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-13 00:22:00 +00:00
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
const $allConversations = this.$('.conversation-list-item');
|
|
|
|
const inboxCollection = getInboxCollection();
|
|
|
|
const index = inboxCollection.indexOf(conversation);
|
2018-01-13 00:22:00 +00:00
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
const elIndex = $allConversations.index($el);
|
2018-04-27 21:25:04 +00:00
|
|
|
if (elIndex < 0) {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.warn(
|
2018-04-27 21:25:04 +00:00
|
|
|
'updateLocation: did not find index for conversation',
|
|
|
|
conversation.idForLogging()
|
|
|
|
);
|
|
|
|
}
|
2018-01-13 00:22:00 +00:00
|
|
|
|
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 {
|
2018-07-07 00:48:14 +00:00
|
|
|
const targetConversation = inboxCollection.at(index - 1);
|
|
|
|
const target = this.$(`.${targetConversation.cid}`);
|
2018-04-27 21:25:04 +00:00
|
|
|
$el.insertAfter(target);
|
|
|
|
}
|
2018-07-05 16:52:24 +00:00
|
|
|
|
|
|
|
if ($('.selected').length) {
|
|
|
|
$('.selected')[0].scrollIntoView({
|
|
|
|
block: 'nearest',
|
|
|
|
});
|
|
|
|
}
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
removeItem(conversation) {
|
|
|
|
const $el = this.$(`.${conversation.cid}`);
|
2018-04-27 21:25:04 +00:00
|
|
|
if ($el && $el.length > 0) {
|
|
|
|
$el.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2014-07-22 18:55:26 +00:00
|
|
|
})();
|