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