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() {
|
|
|
|
this.listenTo(this.model, 'change', this.render); // auto update
|
|
|
|
this.listenTo(this.model, 'destroy', this.remove); // auto update
|
2015-05-13 18:23:59 +00:00
|
|
|
extension.windows.beforeUnload(function() {
|
2015-03-15 03:46:00 +00:00
|
|
|
this.stopListening();
|
|
|
|
}.bind(this));
|
2015-03-05 23:38:39 +00:00
|
|
|
},
|
2014-05-17 04:48:46 +00:00
|
|
|
|
2015-03-05 23:38:39 +00:00
|
|
|
select: function(e) {
|
2015-09-14 22:31:29 +00:00
|
|
|
this.$el.addClass('selected').siblings('.selected').removeClass('selected');
|
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'),
|
|
|
|
last_message_timestamp: moment(this.model.get('timestamp')).format('MMM D'),
|
2015-03-18 00:10:18 +00:00
|
|
|
number: this.model.getNumber(),
|
2015-06-19 00:05:00 +00:00
|
|
|
avatar: this.model.getAvatar()
|
2015-03-23 21:01:18 +00:00
|
|
|
}, this.render_partials())
|
2015-03-05 23:38:39 +00:00
|
|
|
);
|
2015-03-10 19:11:32 +00:00
|
|
|
|
2015-03-19 23:46:58 +00:00
|
|
|
twemoji.parse(this.el, { base: '/images/twemoji/', size: 16 });
|
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
|
|
|
})();
|