2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2014-11-20 23:43:51 +00:00
|
|
|
*/
|
2014-05-17 04:48:46 +00:00
|
|
|
(function () {
|
2015-02-18 07:58:00 +00:00
|
|
|
'use strict';
|
|
|
|
window.Whisper = window.Whisper || {};
|
2015-02-17 19:54:15 +00:00
|
|
|
|
2015-03-24 01:30:16 +00:00
|
|
|
Whisper.MessageView = Whisper.View.extend({
|
|
|
|
tagName: "li",
|
2015-03-05 23:25:49 +00:00
|
|
|
template: $('#message').html(),
|
2015-03-06 00:13:53 +00:00
|
|
|
initialize: function() {
|
2015-03-18 23:26:55 +00:00
|
|
|
this.listenTo(this.model, 'change:body change:errors', this.render);
|
2015-03-06 00:13:53 +00:00
|
|
|
this.listenTo(this.model, 'change:delivered', this.renderDelivered);
|
2015-07-08 02:21:10 +00:00
|
|
|
this.listenTo(this.model, 'change', this.renderSent);
|
2015-03-24 01:30:16 +00:00
|
|
|
this.listenTo(this.model, 'change:flags change:group_update', this.renderControl);
|
|
|
|
this.listenTo(this.model, 'destroy', this.remove);
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click .timestamp': 'select'
|
|
|
|
},
|
|
|
|
select: function() {
|
|
|
|
this.$el.trigger('select', {message: this.model});
|
2015-03-06 00:13:53 +00:00
|
|
|
},
|
2015-02-18 07:58:00 +00:00
|
|
|
className: function() {
|
2015-03-24 01:30:16 +00:00
|
|
|
return ["entry", this.model.get('type')].join(' ');
|
2015-02-18 07:58:00 +00:00
|
|
|
},
|
2015-07-08 02:21:10 +00:00
|
|
|
renderSent: function() {
|
2015-05-26 20:30:51 +00:00
|
|
|
if (this.model.isOutgoing()) {
|
2015-07-08 02:21:10 +00:00
|
|
|
this.$el.toggleClass('sent', !!this.model.get('sent'));
|
2015-05-26 20:30:51 +00:00
|
|
|
}
|
|
|
|
},
|
2015-03-06 00:13:53 +00:00
|
|
|
renderDelivered: function() {
|
|
|
|
if (this.model.get('delivered')) { this.$el.addClass('delivered'); }
|
|
|
|
},
|
2015-09-30 21:27:18 +00:00
|
|
|
renderErrors: function() {
|
|
|
|
var errors = this.model.get('errors');
|
|
|
|
if (_.size(errors) > 0) { this.$el.addClass('error'); }
|
|
|
|
},
|
2015-03-24 01:30:16 +00:00
|
|
|
renderControl: function() {
|
|
|
|
if (this.model.isEndSession() || this.model.isGroupUpdate()) {
|
|
|
|
this.$el.addClass('control');
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.content').text(this.model.getDescription());
|
2015-03-24 01:30:16 +00:00
|
|
|
} else {
|
|
|
|
this.$el.removeClass('control');
|
|
|
|
}
|
|
|
|
},
|
2015-02-18 07:58:00 +00:00
|
|
|
render: function() {
|
2015-03-12 00:49:01 +00:00
|
|
|
var contact = this.model.getContact();
|
2015-01-09 22:53:39 +00:00
|
|
|
this.$el.html(
|
|
|
|
Mustache.render(this.template, {
|
2015-07-05 06:08:25 +00:00
|
|
|
message: this.model.get('body'),
|
2015-05-26 20:31:17 +00:00
|
|
|
timestamp: moment(this.model.get('sent_at')).fromNow(),
|
2015-03-18 00:10:18 +00:00
|
|
|
sender: (contact && contact.getTitle()) || '',
|
2015-06-19 00:05:00 +00:00
|
|
|
avatar: (contact && contact.getAvatar())
|
2015-03-23 21:01:18 +00:00
|
|
|
}, this.render_partials())
|
2015-01-09 22:53:39 +00:00
|
|
|
);
|
2014-12-22 05:01:21 +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-28 01:47:58 +00:00
|
|
|
var content = this.$('.content');
|
2015-07-05 06:08:25 +00:00
|
|
|
var escaped = content.html();
|
|
|
|
content.html(escaped.replace(/\n/g, '<br>').replace(/(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi, "$1<a href='$2' target='_blank'>$2</a>"));
|
2015-03-07 01:01:04 +00:00
|
|
|
|
2015-07-08 02:21:10 +00:00
|
|
|
this.renderSent();
|
2015-03-06 00:13:53 +00:00
|
|
|
this.renderDelivered();
|
2015-09-30 21:27:18 +00:00
|
|
|
this.renderErrors();
|
2015-03-24 01:30:16 +00:00
|
|
|
this.renderControl();
|
2015-02-19 07:57:13 +00:00
|
|
|
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.attachments').append(
|
2015-01-09 22:53:39 +00:00
|
|
|
this.model.get('attachments').map(function(attachment) {
|
2015-02-18 07:58:00 +00:00
|
|
|
return new Whisper.AttachmentView({
|
|
|
|
model: attachment
|
|
|
|
}).render().el;
|
2014-12-19 04:06:45 +00:00
|
|
|
})
|
|
|
|
);
|
2015-01-09 22:53:39 +00:00
|
|
|
|
2015-02-18 07:58:00 +00:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
2014-05-17 04:48:46 +00:00
|
|
|
|
|
|
|
})();
|