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