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
|
|
|
|
2016-01-01 14:14:25 +00:00
|
|
|
var URL_REGEX = /(^|[\s\n]|<br\/?>)((?:https?|ftp):\/\/[\-A-Z0-9\u00A0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD+\u0026\u2019@#\/%?=()~_|!:,.;]*[\-A-Z0-9+\u0026@#\/%=~()_|])/gi;
|
|
|
|
|
2016-04-14 23:42:42 +00:00
|
|
|
var ErrorIconView = Whisper.View.extend({
|
|
|
|
templateName: 'error-icon',
|
|
|
|
className: 'error-icon-container',
|
2016-05-26 17:59:43 +00:00
|
|
|
initialize: function() {
|
2016-05-26 01:57:06 +00:00
|
|
|
if (this.model.name === 'UnregisteredUserError') {
|
|
|
|
this.$el.addClass('unregistered-user-error');
|
|
|
|
}
|
2016-04-14 23:42:42 +00:00
|
|
|
}
|
|
|
|
});
|
2016-03-22 21:47:17 +00:00
|
|
|
var NetworkErrorView = Whisper.View.extend({
|
|
|
|
tagName: 'span',
|
|
|
|
className: 'hasRetry',
|
|
|
|
templateName: 'hasRetry',
|
2017-07-11 00:53:31 +00:00
|
|
|
render_attributes: function() {
|
|
|
|
var messageNotSent;
|
|
|
|
|
|
|
|
if (!this.model.someRecipientsFailed()) {
|
|
|
|
messageNotSent = i18n('messageNotSent');
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
messageNotSent: messageNotSent,
|
|
|
|
resend: i18n('resend')
|
|
|
|
};
|
2016-03-22 21:47:17 +00:00
|
|
|
}
|
|
|
|
});
|
2017-07-03 23:46:39 +00:00
|
|
|
var SomeFailedView = Whisper.View.extend({
|
|
|
|
tagName: 'span',
|
|
|
|
className: 'some-failed',
|
|
|
|
templateName: 'some-failed',
|
|
|
|
render_attributes: {
|
|
|
|
someFailed: i18n('someRecipientsFailed')
|
|
|
|
}
|
|
|
|
});
|
2016-09-23 23:50:03 +00:00
|
|
|
var TimerView = Whisper.View.extend({
|
|
|
|
templateName: 'hourglass',
|
2017-07-26 21:55:59 +00:00
|
|
|
initialize: function() {
|
|
|
|
this.listenTo(this.model, 'unload', this.remove);
|
|
|
|
},
|
2016-10-30 07:53:17 +00:00
|
|
|
update: function() {
|
|
|
|
if (this.timeout) {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
this.timeout = null;
|
|
|
|
}
|
2017-06-06 22:16:45 +00:00
|
|
|
if (this.model.isExpired()) {
|
|
|
|
return this;
|
|
|
|
}
|
2016-09-23 23:50:03 +00:00
|
|
|
if (this.model.isExpiring()) {
|
|
|
|
this.render();
|
|
|
|
var totalTime = this.model.get('expireTimer') * 1000;
|
|
|
|
var remainingTime = this.model.msTilExpire();
|
|
|
|
var elapsed = (totalTime - remainingTime) / totalTime;
|
2016-10-30 07:53:17 +00:00
|
|
|
this.$('.sand').css('transform', 'translateY(' + elapsed*100 + '%)');
|
2016-10-11 04:55:23 +00:00
|
|
|
this.$el.css('display', 'inline-block');
|
2017-06-06 22:18:03 +00:00
|
|
|
this.timeout = setTimeout(this.update.bind(this), Math.max(totalTime / 100, 500));
|
2016-09-23 23:50:03 +00:00
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
});
|
2016-03-22 21:47:17 +00:00
|
|
|
|
2016-09-27 06:15:20 +00:00
|
|
|
Whisper.ExpirationTimerUpdateView = Whisper.View.extend({
|
|
|
|
tagName: 'li',
|
|
|
|
className: 'expirationTimerUpdate advisory',
|
|
|
|
templateName: 'expirationTimerUpdate',
|
2016-10-04 07:24:00 +00:00
|
|
|
id: function() {
|
|
|
|
return this.model.id;
|
|
|
|
},
|
2016-09-27 06:15:20 +00:00
|
|
|
initialize: function() {
|
2016-10-05 13:31:27 +00:00
|
|
|
this.conversation = this.model.getExpirationTimerUpdateSource();
|
2016-09-27 06:15:20 +00:00
|
|
|
this.listenTo(this.conversation, 'change', this.render);
|
2017-07-26 21:55:59 +00:00
|
|
|
this.listenTo(this.model, 'unload', this.remove);
|
2016-09-27 06:15:20 +00:00
|
|
|
},
|
|
|
|
render_attributes: function() {
|
2016-09-28 23:47:57 +00:00
|
|
|
var seconds = this.model.get('expirationTimerUpdate').expireTimer;
|
2016-10-06 14:39:32 +00:00
|
|
|
var timerMessage;
|
2016-10-04 03:22:41 +00:00
|
|
|
if (this.conversation.id === textsecure.storage.user.getNumber()) {
|
2016-10-07 00:29:53 +00:00
|
|
|
timerMessage = i18n('youChangedTheTimer',
|
|
|
|
Whisper.ExpirationTimerOptions.getName(seconds));
|
2016-10-06 14:39:32 +00:00
|
|
|
} else {
|
2016-10-07 00:29:53 +00:00
|
|
|
timerMessage = i18n('theyChangedTheTimer', [
|
|
|
|
this.conversation.getTitle(),
|
|
|
|
Whisper.ExpirationTimerOptions.getName(seconds)]);
|
2016-10-04 03:22:41 +00:00
|
|
|
}
|
2016-10-07 00:29:53 +00:00
|
|
|
return { content: timerMessage };
|
2016-09-27 06:15:20 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-09-18 06:55:05 +00:00
|
|
|
Whisper.KeyChangeView = Whisper.View.extend({
|
|
|
|
tagName: 'li',
|
2017-06-16 21:56:38 +00:00
|
|
|
className: 'keychange advisory',
|
2016-09-18 06:55:05 +00:00
|
|
|
templateName: 'keychange',
|
2017-01-17 22:39:51 +00:00
|
|
|
id: function() {
|
|
|
|
return this.model.id;
|
|
|
|
},
|
2016-09-18 06:55:05 +00:00
|
|
|
initialize: function() {
|
|
|
|
this.conversation = this.model.getModelForKeyChange();
|
|
|
|
this.listenTo(this.conversation, 'change', this.render);
|
2017-07-26 21:55:59 +00:00
|
|
|
this.listenTo(this.model, 'unload', this.remove);
|
2016-09-18 06:55:05 +00:00
|
|
|
},
|
|
|
|
events: {
|
2017-06-09 22:22:39 +00:00
|
|
|
'click .content': 'showIdentity'
|
2016-09-18 06:55:05 +00:00
|
|
|
},
|
|
|
|
render_attributes: function() {
|
|
|
|
return {
|
2017-01-23 04:20:53 +00:00
|
|
|
content: this.model.getNotificationText()
|
2016-09-18 06:55:05 +00:00
|
|
|
};
|
|
|
|
},
|
2017-06-09 22:22:39 +00:00
|
|
|
showIdentity: function() {
|
|
|
|
this.$el.trigger('show-identity', this.conversation);
|
2016-09-18 06:55:05 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-15 19:27:41 +00:00
|
|
|
Whisper.VerifiedChangeView = Whisper.View.extend({
|
|
|
|
tagName: 'li',
|
2017-06-16 21:29:27 +00:00
|
|
|
className: 'verified-change advisory',
|
2017-06-15 19:27:41 +00:00
|
|
|
templateName: 'verified-change',
|
|
|
|
id: function() {
|
|
|
|
return this.model.id;
|
|
|
|
},
|
|
|
|
initialize: function() {
|
|
|
|
this.conversation = this.model.getModelForVerifiedChange();
|
2017-06-15 20:32:02 +00:00
|
|
|
this.listenTo(this.conversation, 'change', this.render);
|
2017-07-26 21:55:59 +00:00
|
|
|
this.listenTo(this.model, 'unload', this.remove);
|
2017-06-15 19:27:41 +00:00
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click .content': 'showIdentity'
|
|
|
|
},
|
|
|
|
render_attributes: function() {
|
2017-06-19 18:45:42 +00:00
|
|
|
var key;
|
|
|
|
|
2017-06-15 19:27:41 +00:00
|
|
|
if (this.model.get('verified')) {
|
2017-06-19 18:45:42 +00:00
|
|
|
if (this.model.get('local')) {
|
|
|
|
key = 'youMarkedAsVerified';
|
|
|
|
} else {
|
|
|
|
key = 'youMarkedAsVerifiedOtherDevice';
|
|
|
|
}
|
2017-06-15 19:27:41 +00:00
|
|
|
return {
|
|
|
|
icon: 'verified',
|
2017-06-19 18:45:42 +00:00
|
|
|
content: i18n(key, this.conversation.getTitle())
|
2017-06-15 19:27:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-06-19 18:45:42 +00:00
|
|
|
if (this.model.get('local')) {
|
|
|
|
key = 'youMarkedAsNotVerified';
|
|
|
|
} else {
|
|
|
|
key = 'youMarkedAsNotVerifiedOtherDevice';
|
|
|
|
}
|
|
|
|
|
2017-06-15 19:27:41 +00:00
|
|
|
return {
|
|
|
|
icon: 'shield',
|
2017-06-19 18:45:42 +00:00
|
|
|
content: i18n(key, this.conversation.getTitle())
|
2017-06-15 19:27:41 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
showIdentity: function() {
|
|
|
|
this.$el.trigger('show-identity', this.conversation);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-24 01:30:16 +00:00
|
|
|
Whisper.MessageView = Whisper.View.extend({
|
2015-12-26 06:17:30 +00:00
|
|
|
tagName: 'li',
|
2015-12-08 23:01:29 +00:00
|
|
|
templateName: 'message',
|
2016-10-04 07:24:00 +00:00
|
|
|
id: function() {
|
|
|
|
return this.model.id;
|
|
|
|
},
|
2015-03-06 00:13:53 +00:00
|
|
|
initialize: function() {
|
2015-11-07 01:37:12 +00:00
|
|
|
this.listenTo(this.model, 'change:errors', this.onErrorsChanged);
|
2015-11-06 04:11:28 +00:00
|
|
|
this.listenTo(this.model, 'change:body', this.render);
|
2015-03-06 00:13:53 +00:00
|
|
|
this.listenTo(this.model, 'change:delivered', this.renderDelivered);
|
2016-09-22 21:12:38 +00:00
|
|
|
this.listenTo(this.model, 'change:expirationStartTimestamp', this.renderExpiring);
|
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);
|
2016-09-21 00:19:51 +00:00
|
|
|
this.listenTo(this.model, 'destroy', this.onDestroy);
|
2017-07-26 21:55:59 +00:00
|
|
|
this.listenTo(this.model, 'unload', this.onUnload);
|
2016-09-21 00:19:51 +00:00
|
|
|
this.listenTo(this.model, 'expired', this.onExpired);
|
2015-10-28 20:57:32 +00:00
|
|
|
this.listenTo(this.model, 'pending', this.renderPending);
|
|
|
|
this.listenTo(this.model, 'done', this.renderDone);
|
2015-12-20 12:34:35 +00:00
|
|
|
this.timeStampView = new Whisper.ExtendedTimestampView();
|
2016-09-11 22:03:05 +00:00
|
|
|
|
|
|
|
this.contact = this.model.isIncoming() ? this.model.getContact() : null;
|
|
|
|
if (this.contact) {
|
|
|
|
this.listenTo(this.contact, 'change:color', this.updateColor);
|
|
|
|
}
|
2015-03-24 01:30:16 +00:00
|
|
|
},
|
|
|
|
events: {
|
2016-03-22 21:47:17 +00:00
|
|
|
'click .retry': 'retryMessage',
|
2016-04-14 23:42:42 +00:00
|
|
|
'click .error-icon': 'select',
|
2016-03-22 21:47:17 +00:00
|
|
|
'click .timestamp': 'select',
|
|
|
|
'click .status': 'select',
|
2017-07-03 23:46:39 +00:00
|
|
|
'click .some-failed': 'select',
|
2016-05-26 03:37:28 +00:00
|
|
|
'click .error-message': 'select'
|
2015-03-24 01:30:16 +00:00
|
|
|
},
|
2016-03-22 21:47:17 +00:00
|
|
|
retryMessage: function() {
|
2017-02-16 02:27:06 +00:00
|
|
|
var retrys = _.filter(this.model.get('errors'),
|
|
|
|
this.model.isReplayableError.bind(this.model));
|
2016-03-22 21:47:17 +00:00
|
|
|
_.map(retrys, 'number').forEach(function(number) {
|
|
|
|
this.model.resend(number);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
2016-09-21 00:19:51 +00:00
|
|
|
onExpired: function() {
|
|
|
|
this.$el.addClass('expired');
|
2016-09-22 21:12:38 +00:00
|
|
|
this.$el.find('.bubble').one('webkitAnimationEnd animationend', function(e) {
|
|
|
|
if (e.target === this.$('.bubble')[0]) {
|
|
|
|
this.remove();
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2017-02-21 23:32:40 +00:00
|
|
|
|
|
|
|
// Failsafe: if in the background, animation events don't fire
|
|
|
|
setTimeout(this.remove.bind(this), 1000);
|
2016-09-21 00:19:51 +00:00
|
|
|
},
|
2017-07-26 21:55:59 +00:00
|
|
|
onUnload: function() {
|
|
|
|
if (this.avatarView) {
|
|
|
|
this.avatarView.remove();
|
|
|
|
}
|
|
|
|
if (this.errorIconView) {
|
|
|
|
this.errorIconView.remove();
|
|
|
|
}
|
|
|
|
if (this.networkErrorView) {
|
|
|
|
this.networkErrorView.remove();
|
|
|
|
}
|
|
|
|
if (this.someFailedView) {
|
|
|
|
this.someFailedView.remove();
|
|
|
|
}
|
|
|
|
if (this.timeStampView) {
|
|
|
|
this.timeStampView.remove();
|
|
|
|
}
|
|
|
|
if (this.loadedAttachments && this.loadedAttachments.length) {
|
|
|
|
for (var i = 0, max = this.loadedAttachments.length; i < max; i += 1) {
|
|
|
|
var view = this.loadedAttachments[i];
|
|
|
|
view.unload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No need to handle this one, since it listens to 'unload' itself:
|
|
|
|
// this.timerView
|
|
|
|
|
|
|
|
this.remove();
|
|
|
|
},
|
2016-09-21 00:19:51 +00:00
|
|
|
onDestroy: function() {
|
|
|
|
if (this.$el.hasClass('expired')) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-26 21:55:59 +00:00
|
|
|
this.onUnload();
|
2016-09-21 00:19:51 +00:00
|
|
|
},
|
2015-10-27 00:00:21 +00:00
|
|
|
select: function(e) {
|
2015-03-24 01:30:16 +00:00
|
|
|
this.$el.trigger('select', {message: this.model});
|
2015-10-27 00:00:21 +00:00
|
|
|
e.stopPropagation();
|
2015-03-06 00:13:53 +00:00
|
|
|
},
|
2015-02-18 07:58:00 +00:00
|
|
|
className: function() {
|
2015-12-26 06:17:30 +00:00
|
|
|
return ['entry', this.model.get('type')].join(' ');
|
2015-02-18 07:58:00 +00:00
|
|
|
},
|
2015-10-28 20:57:32 +00:00
|
|
|
renderPending: function() {
|
|
|
|
this.$el.addClass('pending');
|
|
|
|
},
|
|
|
|
renderDone: function() {
|
|
|
|
this.$el.removeClass('pending');
|
|
|
|
},
|
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-11-07 01:37:12 +00:00
|
|
|
onErrorsChanged: function() {
|
|
|
|
if (this.model.isIncoming()) {
|
|
|
|
this.render();
|
|
|
|
} else {
|
|
|
|
this.renderErrors();
|
|
|
|
}
|
|
|
|
},
|
2015-09-30 21:27:18 +00:00
|
|
|
renderErrors: function() {
|
|
|
|
var errors = this.model.get('errors');
|
2017-07-26 21:55:59 +00:00
|
|
|
|
2017-08-07 19:39:44 +00:00
|
|
|
|
|
|
|
this.$('.error-icon-container').remove();
|
|
|
|
if (this.errorIconView) {
|
|
|
|
this.errorIconView.remove();
|
|
|
|
this.errorIconView = null;
|
|
|
|
}
|
2015-09-30 22:22:59 +00:00
|
|
|
if (_.size(errors) > 0) {
|
|
|
|
if (this.model.isIncoming()) {
|
|
|
|
this.$('.content').text(this.model.getDescription()).addClass('error-message');
|
|
|
|
}
|
2017-07-26 21:55:59 +00:00
|
|
|
this.errorIconView = new ErrorIconView({ model: errors[0] });
|
|
|
|
this.errorIconView.render().$el.appendTo(this.$('.bubble'));
|
2015-09-30 22:22:59 +00:00
|
|
|
}
|
2017-07-26 21:55:59 +00:00
|
|
|
|
2017-08-07 19:39:44 +00:00
|
|
|
this.$('.meta .hasRetry').remove();
|
|
|
|
if (this.networkErrorView) {
|
|
|
|
this.networkErrorView.remove();
|
|
|
|
this.networkErrorView = null;
|
|
|
|
}
|
2016-03-22 21:47:17 +00:00
|
|
|
if (this.model.hasNetworkError()) {
|
2017-07-26 21:55:59 +00:00
|
|
|
this.networkErrorView = new NetworkErrorView({model: this.model});
|
|
|
|
this.$('.meta').prepend(this.networkErrorView.render().el);
|
2016-03-22 21:47:17 +00:00
|
|
|
}
|
2017-07-26 21:55:59 +00:00
|
|
|
|
2017-08-07 19:39:44 +00:00
|
|
|
this.$('.meta .some-failed').remove();
|
|
|
|
if (this.someFailedView) {
|
|
|
|
this.someFailedView.remove();
|
|
|
|
this.someFailedView = null;
|
|
|
|
}
|
2017-07-03 23:46:39 +00:00
|
|
|
if (this.model.someRecipientsFailed()) {
|
2017-07-26 21:55:59 +00:00
|
|
|
this.someFailedView = new SomeFailedView();
|
|
|
|
this.$('.meta').prepend(this.someFailedView.render().el);
|
2017-07-03 23:46:39 +00:00
|
|
|
}
|
2015-09-30 21:27:18 +00:00
|
|
|
},
|
2015-03-24 01:30:16 +00:00
|
|
|
renderControl: function() {
|
|
|
|
if (this.model.isEndSession() || this.model.isGroupUpdate()) {
|
|
|
|
this.$el.addClass('control');
|
2016-09-01 22:59:21 +00:00
|
|
|
var content = this.$('.content');
|
|
|
|
content.text(this.model.getDescription());
|
|
|
|
emoji_util.parse(content);
|
2015-03-24 01:30:16 +00:00
|
|
|
} else {
|
|
|
|
this.$el.removeClass('control');
|
|
|
|
}
|
|
|
|
},
|
2016-09-22 21:12:38 +00:00
|
|
|
renderExpiring: function() {
|
2016-10-30 07:53:17 +00:00
|
|
|
if (!this.timerView) {
|
2017-06-06 22:18:23 +00:00
|
|
|
this.timerView = new TimerView({ model: this.model });
|
2016-10-30 07:53:17 +00:00
|
|
|
}
|
2017-06-06 22:18:23 +00:00
|
|
|
this.timerView.setElement(this.$('.timer'));
|
2016-10-30 07:53:17 +00:00
|
|
|
this.timerView.update();
|
2016-09-22 21:12:38 +00:00
|
|
|
},
|
2015-02-18 07:58:00 +00:00
|
|
|
render: function() {
|
2016-03-23 23:13:41 +00:00
|
|
|
var contact = this.model.isIncoming() ? this.model.getContact() : null;
|
2015-01-09 22:53:39 +00:00
|
|
|
this.$el.html(
|
2015-12-08 23:01:29 +00:00
|
|
|
Mustache.render(_.result(this, 'template', ''), {
|
2015-07-05 06:08:25 +00:00
|
|
|
message: this.model.get('body'),
|
2015-11-06 22:58:26 +00:00
|
|
|
timestamp: this.model.get('sent_at'),
|
2015-03-18 00:10:18 +00:00
|
|
|
sender: (contact && contact.getTitle()) || '',
|
2016-03-22 21:47:17 +00:00
|
|
|
avatar: (contact && contact.getAvatar()),
|
2017-09-11 16:50:35 +00:00
|
|
|
profileName: (contact && contact.getProfileName()),
|
2015-03-23 21:01:18 +00:00
|
|
|
}, this.render_partials())
|
2015-01-09 22:53:39 +00:00
|
|
|
);
|
2015-11-06 22:58:26 +00:00
|
|
|
this.timeStampView.setElement(this.$('.timestamp'));
|
|
|
|
this.timeStampView.update();
|
2014-12-22 05:01:21 +00:00
|
|
|
|
2015-10-23 23:03:51 +00:00
|
|
|
this.renderControl();
|
|
|
|
|
2016-08-29 08:11:13 +00:00
|
|
|
var body = this.$('.body');
|
2016-09-01 06:32:17 +00:00
|
|
|
|
|
|
|
emoji_util.parse(body);
|
|
|
|
|
2016-08-29 08:11:13 +00:00
|
|
|
if (body.length > 0) {
|
|
|
|
var escaped = body.html();
|
|
|
|
body.html(escaped.replace(/\n/g, '<br>').replace(URL_REGEX, "$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 22:22:59 +00:00
|
|
|
this.renderErrors();
|
2016-09-22 21:12:38 +00:00
|
|
|
this.renderExpiring();
|
|
|
|
|
2015-11-12 18:35:29 +00:00
|
|
|
this.loadAttachments();
|
2015-01-09 22:53:39 +00:00
|
|
|
|
2015-02-18 07:58:00 +00:00
|
|
|
return this;
|
2015-11-12 18:35:29 +00:00
|
|
|
},
|
2017-09-07 01:19:11 +00:00
|
|
|
updateColor: function() {
|
2016-09-11 22:03:05 +00:00
|
|
|
var bubble = this.$('.bubble');
|
2017-09-07 01:19:11 +00:00
|
|
|
|
|
|
|
// this.contact is known to be non-null if we're registered for color changes
|
|
|
|
var color = this.contact.getColor();
|
2016-09-11 22:03:05 +00:00
|
|
|
if (color) {
|
2017-09-07 01:19:11 +00:00
|
|
|
bubble.removeClass(Whisper.Conversation.COLORS);
|
2016-09-11 22:03:05 +00:00
|
|
|
bubble.addClass(color);
|
|
|
|
}
|
2017-07-26 21:55:59 +00:00
|
|
|
this.avatarView = new (Whisper.View.extend({
|
2016-09-11 22:03:05 +00:00
|
|
|
templateName: 'avatar',
|
2017-09-07 17:38:00 +00:00
|
|
|
render_attributes: { avatar: this.contact.getAvatar() }
|
2016-09-11 22:03:05 +00:00
|
|
|
}))();
|
2017-07-26 21:55:59 +00:00
|
|
|
this.$('.avatar').replaceWith(this.avatarView.render().$('.avatar'));
|
2016-09-11 22:03:05 +00:00
|
|
|
},
|
2017-06-07 00:28:32 +00:00
|
|
|
appendAttachmentView: function(view) {
|
|
|
|
// We check for a truthy 'updated' here to ensure that a race condition in a
|
|
|
|
// multi-fetch() scenario doesn't add an AttachmentView to the DOM before
|
|
|
|
// its 'update' event is triggered.
|
|
|
|
var parent = this.$('.attachments')[0];
|
|
|
|
if (view.updated && parent !== view.el.parentNode) {
|
|
|
|
if (view.el.parentNode) {
|
2017-06-09 02:46:02 +00:00
|
|
|
view.el.parentNode.removeChild(view.el);
|
2017-06-07 00:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.trigger('beforeChangeHeight');
|
|
|
|
this.$('.attachments').append(view.el);
|
2017-06-15 17:00:00 +00:00
|
|
|
view.setElement(view.el);
|
2017-06-07 00:28:32 +00:00
|
|
|
this.trigger('afterChangeHeight');
|
|
|
|
}
|
|
|
|
},
|
2015-11-12 18:35:29 +00:00
|
|
|
loadAttachments: function() {
|
2017-06-01 22:22:39 +00:00
|
|
|
this.loadedAttachments = this.loadedAttachments || [];
|
|
|
|
|
2017-06-07 00:28:32 +00:00
|
|
|
// If we're called a second time, render() has replaced the DOM out from under
|
|
|
|
// us with $el.html(). We'll need to reattach our AttachmentViews to the new
|
|
|
|
// parent DOM nodes if the 'update' event has already fired.
|
2017-06-01 22:22:39 +00:00
|
|
|
if (this.loadedAttachments.length) {
|
2017-06-07 00:28:32 +00:00
|
|
|
for (var i = 0, max = this.loadedAttachments.length; i < max; i += 1) {
|
|
|
|
var view = this.loadedAttachments[i];
|
|
|
|
this.appendAttachmentView(view);
|
|
|
|
}
|
2017-05-31 18:32:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-12 18:35:29 +00:00
|
|
|
this.model.get('attachments').forEach(function(attachment) {
|
2017-01-12 21:51:38 +00:00
|
|
|
var view = new Whisper.AttachmentView({
|
|
|
|
model: attachment,
|
|
|
|
timestamp: this.model.get('sent_at')
|
|
|
|
});
|
2017-05-31 18:32:17 +00:00
|
|
|
this.loadedAttachments.push(view);
|
2017-06-07 00:28:32 +00:00
|
|
|
|
|
|
|
this.listenTo(view, 'update', function() {
|
|
|
|
view.updated = true;
|
|
|
|
this.appendAttachmentView(view);
|
|
|
|
});
|
2017-06-16 17:46:55 +00:00
|
|
|
|
|
|
|
view.render();
|
2015-11-12 18:35:29 +00:00
|
|
|
}.bind(this));
|
2015-02-18 07:58:00 +00:00
|
|
|
}
|
|
|
|
});
|
2014-05-17 04:48:46 +00:00
|
|
|
|
|
|
|
})();
|