2018-07-18 03:25:55 +00:00
|
|
|
/* global Whisper, Signal, Backbone */
|
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-05-17 04:48:46 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
// list of conversations, showing user/group and last message sent
|
|
|
|
Whisper.ConversationListItemView = Whisper.View.extend({
|
|
|
|
tagName: 'div',
|
2018-07-07 00:48:14 +00:00
|
|
|
className() {
|
|
|
|
return `conversation-list-item contact ${this.model.cid}`;
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
|
|
|
templateName: 'conversation-preview',
|
2018-07-07 00:48:14 +00:00
|
|
|
initialize() {
|
2018-07-18 03:25:55 +00:00
|
|
|
this.listenTo(this.model, 'destroy', this.remove);
|
2018-04-27 21:25:04 +00:00
|
|
|
this.model.updateLastMessage();
|
|
|
|
},
|
2014-05-17 04:48:46 +00:00
|
|
|
|
2018-05-18 23:57:26 +00:00
|
|
|
remove() {
|
2018-07-18 03:25:55 +00:00
|
|
|
if (this.childView) {
|
|
|
|
this.childView.remove();
|
|
|
|
this.childView = null;
|
2018-05-18 23:57:26 +00:00
|
|
|
}
|
|
|
|
Backbone.View.prototype.remove.call(this);
|
|
|
|
},
|
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
render() {
|
2018-07-18 03:25:55 +00:00
|
|
|
if (this.childView) {
|
|
|
|
this.childView.remove();
|
|
|
|
this.childView = null;
|
2018-05-18 23:57:26 +00:00
|
|
|
}
|
2018-07-18 03:25:55 +00:00
|
|
|
|
|
|
|
const props = this.model.getPropsForListItem();
|
|
|
|
this.childView = new Whisper.ReactWrapperView({
|
|
|
|
className: 'list-item-wrapper',
|
|
|
|
Component: Signal.Components.ConversationListItem,
|
|
|
|
props,
|
2018-05-18 23:57:26 +00:00
|
|
|
});
|
2018-05-14 20:52:10 +00:00
|
|
|
|
2018-07-18 03:25:55 +00:00
|
|
|
const update = () =>
|
|
|
|
this.childView.update(this.model.getPropsForListItem());
|
2015-03-10 19:11:32 +00:00
|
|
|
|
2018-07-18 03:25:55 +00:00
|
|
|
this.listenTo(this.model, 'change', update);
|
|
|
|
|
|
|
|
this.$el.append(this.childView.el);
|
2015-03-11 19:06:19 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
});
|
2014-05-17 04:48:46 +00:00
|
|
|
})();
|