2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-19 00:16:24 +00:00
|
|
|
*/
|
2014-07-22 18:55:26 +00:00
|
|
|
(function () {
|
2015-03-05 23:44:53 +00:00
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
2014-07-22 18:55:26 +00:00
|
|
|
|
2015-03-05 23:44:53 +00:00
|
|
|
Whisper.ConversationListView = Whisper.ListView.extend({
|
|
|
|
tagName: 'div',
|
|
|
|
itemView: Whisper.ConversationListItemView,
|
2017-10-13 18:47:13 +00:00
|
|
|
updateLocation: function(conversation) {
|
2015-09-14 20:30:21 +00:00
|
|
|
var $el = this.$('.' + conversation.cid);
|
2017-10-13 18:47:13 +00:00
|
|
|
|
2018-01-13 00:22:00 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2015-09-14 20:30:21 +00:00
|
|
|
}
|
2017-11-22 00:37:58 +00:00
|
|
|
},
|
|
|
|
removeItem: function(conversation) {
|
|
|
|
var $el = this.$('.' + conversation.cid);
|
|
|
|
if ($el && $el.length > 0) {
|
|
|
|
$el.remove();
|
|
|
|
}
|
2015-03-05 23:44:53 +00:00
|
|
|
}
|
|
|
|
});
|
2014-07-22 18:55:26 +00:00
|
|
|
})();
|