2015-01-19 01:16:24 +01:00
|
|
|
/* vim: ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
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',
|
|
|
|
className: 'contact',
|
|
|
|
template: $('#contact').html(),
|
|
|
|
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 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-03-06 00:38:39 +01:00
|
|
|
select: function(e) {
|
|
|
|
this.$el.addClass('selected');
|
|
|
|
this.$el.trigger('select', {modelId: this.model.id});
|
|
|
|
},
|
2014-05-17 06:48:46 +02:00
|
|
|
|
2015-03-06 00:38:39 +01:00
|
|
|
render: function() {
|
|
|
|
this.$el.html(
|
|
|
|
Mustache.render(this.template, {
|
2015-03-11 20:06:19 +01:00
|
|
|
contact_name: this.model.getTitle(),
|
|
|
|
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
|
|
|
})();
|