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-06 00:25:49 +01:00
|
|
|
var ContentMessageView = Whisper.View.extend({
|
2015-02-18 08:58:00 +01:00
|
|
|
tagName: 'div',
|
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-02-18 08:58:00 +01:00
|
|
|
className: function() {
|
|
|
|
if (this.model.get('delivered')) { return 'delivered'; }
|
|
|
|
},
|
2015-03-06 01:13:53 +01:00
|
|
|
renderDelivered: function() {
|
|
|
|
if (this.model.get('delivered')) { this.$el.addClass('delivered'); }
|
|
|
|
},
|
2015-03-07 02:01:04 +01:00
|
|
|
autoLink: function(text) {
|
|
|
|
return text.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-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-03-23 23:44:47 +01:00
|
|
|
message: this.model.getDescription(),
|
2015-01-09 23:53:39 +01:00
|
|
|
timestamp: moment(this.model.get('received_at')).fromNow(),
|
2015-03-18 01:10:18 +01:00
|
|
|
sender: (contact && contact.getTitle()) || '',
|
|
|
|
avatar_url: (contact && contact.getAvatarUrl())
|
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-07 02:01:04 +01:00
|
|
|
var content = this.$el.find('.content');
|
|
|
|
content.html(this.autoLink(content.html()));
|
|
|
|
|
2015-03-06 01:13:53 +01:00
|
|
|
this.renderDelivered();
|
2015-02-19 08:57:13 +01:00
|
|
|
|
2015-01-09 23:53:39 +01:00
|
|
|
this.$el.find('.attachments').append(
|
|
|
|
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-02-18 03:03:05 +01:00
|
|
|
this.$el.find('.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
|
|
|
);
|
|
|
|
}
|
2014-12-19 05:06:45 +01:00
|
|
|
}
|
2015-02-18 08:58:00 +01:00
|
|
|
});
|
2015-02-17 20:54:15 +01:00
|
|
|
|
2015-02-18 08:58:00 +01:00
|
|
|
Whisper.MessageView = Backbone.View.extend({
|
|
|
|
tagName: "li",
|
|
|
|
className: function() {
|
|
|
|
return ["entry", this.model.get('type')].join(' ');
|
|
|
|
},
|
|
|
|
initialize: function() {
|
2015-03-23 23:44:47 +01:00
|
|
|
this.view = new ContentMessageView({model: this.model});
|
2015-02-18 08:58:00 +01:00
|
|
|
this.$el.append(this.view.el);
|
2015-02-17 20:54:15 +01:00
|
|
|
|
2015-02-18 08:58:00 +01:00
|
|
|
this.listenTo(this.model, 'destroy', this.remove); // auto update
|
2015-03-24 00:41:03 +01:00
|
|
|
this.listenTo(this.model, 'change:flags change:group_update', this.render); // auto update
|
2015-02-18 08:58:00 +01:00
|
|
|
},
|
2015-02-23 22:17:50 +01:00
|
|
|
events: {
|
|
|
|
'click .timestamp': 'select'
|
|
|
|
},
|
|
|
|
select: function() {
|
|
|
|
this.$el.trigger('select', {message: this.model});
|
|
|
|
},
|
2015-02-18 08:58:00 +01:00
|
|
|
render: function() {
|
2015-03-23 23:44:47 +01:00
|
|
|
if (this.model.isEndSession() || this.model.isGroupUpdate()) {
|
|
|
|
this.$el.addClass('control');
|
|
|
|
} else {
|
|
|
|
this.$el.removeClass('control');
|
|
|
|
}
|
2015-02-18 08:58:00 +01:00
|
|
|
this.view.render();
|
|
|
|
return this;
|
|
|
|
}
|
2014-11-11 09:35:18 +01:00
|
|
|
|
2015-02-18 08:58:00 +01:00
|
|
|
});
|
2014-05-17 06:48:46 +02:00
|
|
|
|
|
|
|
})();
|