2015-09-07 14:53:43 -07:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-18 14:16:24 -10:00
|
|
|
*/
|
2014-05-16 21:48:46 -07:00
|
|
|
(function () {
|
2015-03-05 15:38:39 -08:00
|
|
|
'use strict';
|
2015-03-05 15:44:53 -08:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-05-16 21:48:46 -07:00
|
|
|
|
2015-03-05 15:38:39 -08:00
|
|
|
// list of conversations, showing user/group and last message sent
|
|
|
|
Whisper.ConversationListItemView = Whisper.View.extend({
|
|
|
|
tagName: 'div',
|
2015-09-14 13:30:21 -07:00
|
|
|
className: function() {
|
|
|
|
return 'conversation-list-item contact ' + this.model.cid;
|
|
|
|
},
|
2015-09-04 18:44:33 -07:00
|
|
|
templateName: 'conversation-preview',
|
2015-03-05 15:38:39 -08:00
|
|
|
events: {
|
|
|
|
'click': 'select'
|
|
|
|
},
|
|
|
|
initialize: function() {
|
2016-04-11 11:24:18 -07:00
|
|
|
// auto update
|
|
|
|
this.listenTo(this.model, 'change', _.debounce(this.render.bind(this), 1000));
|
2015-03-05 15:38:39 -08:00
|
|
|
this.listenTo(this.model, 'destroy', this.remove); // auto update
|
2015-10-15 12:10:03 -07:00
|
|
|
this.listenTo(this.model, 'opened', this.markSelected); // auto update
|
2017-02-21 19:51:33 -08:00
|
|
|
|
|
|
|
var updateLastMessage = _.debounce(this.model.updateLastMessage.bind(this.model), 1000);
|
|
|
|
this.listenTo(this.model.messageCollection, 'add remove', updateLastMessage);
|
|
|
|
this.listenTo(this.model, 'newmessage', updateLastMessage);
|
|
|
|
|
2015-11-08 10:40:37 -08:00
|
|
|
extension.windows.onClosed(this.stopListening.bind(this));
|
2016-04-18 19:48:54 -07:00
|
|
|
this.timeStampView = new Whisper.TimestampView({brief: true});
|
2017-01-25 00:42:06 -08:00
|
|
|
this.model.updateLastMessage();
|
2015-03-05 15:38:39 -08:00
|
|
|
},
|
2014-05-16 21:48:46 -07:00
|
|
|
|
2015-10-15 12:10:03 -07:00
|
|
|
markSelected: function() {
|
2015-09-14 15:31:29 -07:00
|
|
|
this.$el.addClass('selected').siblings('.selected').removeClass('selected');
|
2015-10-15 12:10:03 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
select: function(e) {
|
|
|
|
this.markSelected();
|
2015-09-21 10:21:33 -07:00
|
|
|
this.$el.trigger('select', this.model);
|
2015-03-05 15:38:39 -08:00
|
|
|
},
|
2014-05-16 21:48:46 -07:00
|
|
|
|
2015-03-05 15:38:39 -08:00
|
|
|
render: function() {
|
|
|
|
this.$el.html(
|
2015-09-04 18:44:33 -07:00
|
|
|
Mustache.render(_.result(this,'template', ''), {
|
2015-09-03 13:33:17 -07:00
|
|
|
title: this.model.getTitle(),
|
2015-03-11 12:06:19 -07:00
|
|
|
last_message: this.model.get('lastMessage'),
|
2015-12-20 13:34:35 +01:00
|
|
|
last_message_timestamp: this.model.get('timestamp'),
|
2015-03-17 17:10:18 -07:00
|
|
|
number: this.model.getNumber(),
|
2015-11-09 12:07:40 -08:00
|
|
|
avatar: this.model.getAvatar(),
|
|
|
|
unreadCount: this.model.get('unreadCount')
|
2015-03-23 14:01:18 -07:00
|
|
|
}, this.render_partials())
|
2015-03-05 15:38:39 -08:00
|
|
|
);
|
2015-12-20 13:34:35 +01:00
|
|
|
this.timeStampView.setElement(this.$('.last-timestamp'));
|
|
|
|
this.timeStampView.update();
|
2015-03-10 12:11:32 -07:00
|
|
|
|
2016-08-31 23:32:17 -07:00
|
|
|
emoji_util.parse(this.$('.name'));
|
|
|
|
emoji_util.parse(this.$('.last-message'));
|
2015-03-10 12:11:32 -07:00
|
|
|
|
2015-03-11 12:06:19 -07:00
|
|
|
var unread = this.model.get('unreadCount');
|
|
|
|
if (unread > 0) {
|
|
|
|
this.$el.addClass('unread');
|
|
|
|
} else {
|
|
|
|
this.$el.removeClass('unread');
|
|
|
|
}
|
|
|
|
|
2015-03-05 15:38:39 -08:00
|
|
|
return this;
|
|
|
|
}
|
2014-07-22 08:55:26 -10:00
|
|
|
|
2015-03-05 15:38:39 -08:00
|
|
|
});
|
2014-05-16 21:48:46 -07:00
|
|
|
})();
|