2014-11-21 00:43:51 +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-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-05-26 22:30:51 +02:00
|
|
|
this.listenTo(this.model, 'change', this.renderPending);
|
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-05-26 22:30:51 +02:00
|
|
|
renderPending: function() {
|
|
|
|
if (this.model.isOutgoing()) {
|
|
|
|
this.$el.toggleClass('pending', !!this.model.get('pending'));
|
|
|
|
}
|
|
|
|
},
|
2015-03-06 01:13:53 +01:00
|
|
|
renderDelivered: function() {
|
|
|
|
if (this.model.get('delivered')) { this.$el.addClass('delivered'); }
|
|
|
|
},
|
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-03-06 01:13:53 +01:00
|
|
|
this.renderDelivered();
|
2015-05-26 22:30:51 +02:00
|
|
|
this.renderPending();
|
2015-03-24 02:30:16 +01:00
|
|
|
this.renderControl();
|
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
|
|
|
|
|
|
|
var errors = this.model.get('errors');
|
|
|
|
if (errors && errors.length) {
|
2015-03-28 02:47:58 +01:00
|
|
|
this.$('.bubble').prepend(
|
2015-01-09 23:53:39 +01:00
|
|
|
errors.map(function(error) {
|
2015-02-18 03:03:05 +01:00
|
|
|
return new Whisper.MessageErrorView({
|
|
|
|
model: error,
|
|
|
|
message: this.model
|
|
|
|
}).render().el;
|
|
|
|
}.bind(this))
|
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
|
|
|
|
|
|
|
})();
|