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