2015-09-07 23:53:43 +02:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2015-01-19 01:16:24 +01:00
|
|
|
*/
|
2014-05-17 06:48:46 +02:00
|
|
|
(function () {
|
2015-03-06 00:38:39 +01:00
|
|
|
'use strict';
|
2015-03-06 00:44:53 +01:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-05-17 06:48:46 +02:00
|
|
|
|
2015-03-06 00:38:39 +01:00
|
|
|
// list of conversations, showing user/group and last message sent
|
|
|
|
Whisper.ConversationListItemView = Whisper.View.extend({
|
|
|
|
tagName: 'div',
|
2015-09-14 22:30:21 +02:00
|
|
|
className: function() {
|
|
|
|
return 'conversation-list-item contact ' + this.model.cid;
|
|
|
|
},
|
2015-09-05 03:44:33 +02:00
|
|
|
templateName: 'conversation-preview',
|
2015-03-06 00:38:39 +01:00
|
|
|
events: {
|
|
|
|
'click': 'select'
|
|
|
|
},
|
|
|
|
initialize: function() {
|
|
|
|
this.listenTo(this.model, 'change', this.render); // auto update
|
|
|
|
this.listenTo(this.model, 'destroy', this.remove); // auto update
|
2015-10-15 21:10:03 +02:00
|
|
|
this.listenTo(this.model, 'opened', this.markSelected); // auto update
|
2015-05-13 20:23:59 +02:00
|
|
|
extension.windows.beforeUnload(function() {
|
2015-03-15 04:46:00 +01:00
|
|
|
this.stopListening();
|
|
|
|
}.bind(this));
|
2015-03-06 00:38:39 +01:00
|
|
|
},
|
2014-05-17 06:48:46 +02:00
|
|
|
|
2015-10-15 21:10:03 +02:00
|
|
|
markSelected: function() {
|
2015-09-15 00:31:29 +02:00
|
|
|
this.$el.addClass('selected').siblings('.selected').removeClass('selected');
|
2015-10-15 21:10:03 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
select: function(e) {
|
|
|
|
this.markSelected();
|
2015-09-21 19:21:33 +02:00
|
|
|
this.$el.trigger('select', this.model);
|
2015-03-06 00:38:39 +01:00
|
|
|
},
|
2014-05-17 06:48:46 +02:00
|
|
|
|
2015-03-06 00:38:39 +01:00
|
|
|
render: function() {
|
|
|
|
this.$el.html(
|
2015-09-05 03:44:33 +02:00
|
|
|
Mustache.render(_.result(this,'template', ''), {
|
2015-09-03 22:33:17 +02:00
|
|
|
title: this.model.getTitle(),
|
2015-03-11 20:06:19 +01:00
|
|
|
last_message: this.model.get('lastMessage'),
|
|
|
|
last_message_timestamp: moment(this.model.get('timestamp')).format('MMM D'),
|
2015-03-18 01:10:18 +01:00
|
|
|
number: this.model.getNumber(),
|
2015-06-19 02:05:00 +02:00
|
|
|
avatar: this.model.getAvatar()
|
2015-03-23 22:01:18 +01:00
|
|
|
}, this.render_partials())
|
2015-03-06 00:38:39 +01:00
|
|
|
);
|
2015-03-10 20:11:32 +01:00
|
|
|
|
2015-03-20 00:46:58 +01:00
|
|
|
twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 });
|
2015-03-10 20:11:32 +01:00
|
|
|
|
2015-03-11 20:06:19 +01:00
|
|
|
var unread = this.model.get('unreadCount');
|
|
|
|
if (unread > 0) {
|
|
|
|
this.$el.addClass('unread');
|
|
|
|
} else {
|
|
|
|
this.$el.removeClass('unread');
|
|
|
|
}
|
|
|
|
|
2015-03-06 00:38:39 +01:00
|
|
|
return this;
|
|
|
|
}
|
2014-07-22 20:55:26 +02:00
|
|
|
|
2015-03-06 00:38:39 +01:00
|
|
|
});
|
2014-05-17 06:48:46 +02:00
|
|
|
})();
|