2015-09-07 21:53:43 +00:00
|
|
|
/*
|
|
|
|
* vim: ts=4:sw=4:expandtab
|
2014-11-13 22:36:09 +00:00
|
|
|
*/
|
2014-07-23 07:24:17 +00:00
|
|
|
(function () {
|
2014-12-02 23:47:28 +00:00
|
|
|
'use strict';
|
2014-11-16 23:30:40 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-07-23 07:24:17 +00:00
|
|
|
|
2016-04-04 03:06:27 +00:00
|
|
|
Whisper.ExpiredToast = Whisper.ToastView.extend({
|
|
|
|
render_attributes: function() {
|
2016-09-07 00:11:44 +00:00
|
|
|
return { toastMessage: i18n('expiredWarning') };
|
2016-04-04 03:06:27 +00:00
|
|
|
}
|
|
|
|
});
|
2016-09-07 00:12:45 +00:00
|
|
|
Whisper.BlockedToast = Whisper.ToastView.extend({
|
|
|
|
render_attributes: function() {
|
|
|
|
return { toastMessage: i18n('unblockToSend') };
|
|
|
|
}
|
|
|
|
});
|
2016-04-04 03:06:27 +00:00
|
|
|
|
2016-09-28 23:47:57 +00:00
|
|
|
var MenuView = Whisper.View.extend({
|
|
|
|
toggleMenu: function() {
|
|
|
|
this.$('.menu-list').toggle();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var TimerMenuView = MenuView.extend({
|
|
|
|
initialize: function() {
|
|
|
|
this.render();
|
|
|
|
this.listenTo(this.model, 'change:expireTimer', this.render);
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click button': 'toggleMenu',
|
|
|
|
'click li': 'setTimer'
|
|
|
|
},
|
|
|
|
setTimer: function(e) {
|
|
|
|
var seconds = this.$(e.target).data().seconds;
|
2017-02-21 03:12:53 +00:00
|
|
|
if (seconds > 0) {
|
2017-01-03 12:52:29 +00:00
|
|
|
this.model.updateExpirationTimer(seconds);
|
2017-02-21 03:12:53 +00:00
|
|
|
} else {
|
|
|
|
this.model.updateExpirationTimer(null);
|
2016-09-28 23:47:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var seconds = this.model.get('expireTimer');
|
|
|
|
if (seconds) {
|
|
|
|
var s = Whisper.ExpirationTimerOptions.getAbbreviated(seconds);
|
|
|
|
this.$el.attr('data-time', s);
|
|
|
|
this.$el.show();
|
|
|
|
} else {
|
|
|
|
this.$el.attr('data-time', null);
|
|
|
|
this.$el.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-05 23:25:49 +00:00
|
|
|
Whisper.ConversationView = Whisper.View.extend({
|
2015-01-16 08:22:24 +00:00
|
|
|
className: function() {
|
|
|
|
return [ 'conversation', this.model.get('type') ].join(' ');
|
|
|
|
},
|
2015-08-25 23:47:15 +00:00
|
|
|
id: function() {
|
|
|
|
return 'conversation-' + this.model.cid;
|
|
|
|
},
|
2015-03-05 23:25:49 +00:00
|
|
|
template: $('#conversation').html(),
|
2015-03-07 01:05:36 +00:00
|
|
|
render_attributes: function() {
|
2015-05-22 22:41:30 +00:00
|
|
|
return {
|
|
|
|
group: this.model.get('type') === 'group',
|
2016-03-18 20:09:45 +00:00
|
|
|
name: this.model.getName(),
|
2015-12-04 02:21:19 +00:00
|
|
|
number: this.model.getNumber(),
|
2015-12-25 06:50:27 +00:00
|
|
|
avatar: this.model.getAvatar(),
|
2016-09-28 23:47:57 +00:00
|
|
|
expireTimer: this.model.get('expireTimer'),
|
2015-12-25 06:50:27 +00:00
|
|
|
'view-members' : i18n('members'),
|
|
|
|
'end-session' : i18n('resetSession'),
|
2016-10-08 02:05:59 +00:00
|
|
|
'verify-identity' : i18n('verifySafetyNumbers'),
|
2015-12-25 06:50:27 +00:00
|
|
|
'destroy' : i18n('deleteMessages'),
|
2016-09-28 23:47:57 +00:00
|
|
|
'send-message' : i18n('sendMessage'),
|
|
|
|
'disappearing-messages': i18n('disappearingMessages'),
|
|
|
|
timer_options : Whisper.ExpirationTimerOptions.models
|
2015-05-22 22:41:30 +00:00
|
|
|
};
|
2015-03-05 23:25:49 +00:00
|
|
|
},
|
2015-05-21 21:35:44 +00:00
|
|
|
initialize: function(options) {
|
2015-03-05 23:25:49 +00:00
|
|
|
this.listenTo(this.model, 'destroy', this.stopListening);
|
2016-09-11 22:03:05 +00:00
|
|
|
this.listenTo(this.model, 'change:color', this.updateColor);
|
2015-06-04 00:23:55 +00:00
|
|
|
this.listenTo(this.model, 'change:name', this.updateTitle);
|
2015-11-07 22:11:13 +00:00
|
|
|
this.listenTo(this.model, 'newmessage', this.addMessage);
|
2015-11-11 04:39:36 +00:00
|
|
|
this.listenTo(this.model, 'opened', this.onOpened);
|
2016-09-21 23:26:42 +00:00
|
|
|
this.listenTo(this.model, 'expired', this.onExpired);
|
|
|
|
this.listenTo(this.model.messageCollection, 'expired', this.onExpiredCollection);
|
2015-01-16 08:22:24 +00:00
|
|
|
|
2015-03-05 23:25:49 +00:00
|
|
|
this.render();
|
2016-09-28 23:47:57 +00:00
|
|
|
new TimerMenuView({ el: this.$('.timer-menu'), model: this.model });
|
2015-12-25 06:50:27 +00:00
|
|
|
|
2016-09-01 06:32:17 +00:00
|
|
|
emoji_util.parse(this.$('.conversation-name'));
|
2014-07-23 08:52:59 +00:00
|
|
|
|
2016-10-07 01:43:02 +00:00
|
|
|
this.window = options.window;
|
2014-11-16 21:19:51 +00:00
|
|
|
this.fileInput = new Whisper.FileInputView({
|
2015-10-30 01:19:51 +00:00
|
|
|
el: this.$('form.send'),
|
2016-10-07 01:43:02 +00:00
|
|
|
window: this.window
|
2014-11-16 21:19:51 +00:00
|
|
|
});
|
2014-10-24 21:03:34 +00:00
|
|
|
|
2014-11-16 21:19:51 +00:00
|
|
|
this.view = new Whisper.MessageListView({
|
2015-05-28 18:50:31 +00:00
|
|
|
collection: this.model.messageCollection,
|
2016-10-07 01:43:02 +00:00
|
|
|
window: this.window
|
2014-11-16 21:19:51 +00:00
|
|
|
});
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.discussion-container').append(this.view.el);
|
2015-02-12 07:39:57 +00:00
|
|
|
this.view.render();
|
2015-01-22 04:27:42 +00:00
|
|
|
|
2015-06-23 20:43:22 +00:00
|
|
|
this.$messageField = this.$('.send-message');
|
|
|
|
|
|
|
|
var onResize = this.forceUpdateMessageFieldSize.bind(this);
|
2016-10-07 01:43:02 +00:00
|
|
|
this.window.addEventListener('resize', onResize);
|
2015-06-23 20:43:22 +00:00
|
|
|
|
2015-08-27 21:36:32 +00:00
|
|
|
var onFocus = function() {
|
|
|
|
if (this.$el.css('display') !== 'none') {
|
|
|
|
this.markRead();
|
|
|
|
}
|
|
|
|
}.bind(this);
|
2016-10-07 01:43:02 +00:00
|
|
|
this.window.addEventListener('focus', onFocus);
|
2015-06-26 18:53:00 +00:00
|
|
|
|
2016-09-22 23:37:12 +00:00
|
|
|
extension.windows.onClosed(function () {
|
2016-10-07 01:43:02 +00:00
|
|
|
this.window.removeEventListener('resize', onResize);
|
|
|
|
this.window.removeEventListener('focus', onFocus);
|
2015-06-23 20:43:22 +00:00
|
|
|
window.autosize.destroy(this.$messageField);
|
|
|
|
this.remove();
|
2015-11-11 04:40:36 +00:00
|
|
|
this.model.messageCollection.reset([]);
|
2015-06-23 20:43:22 +00:00
|
|
|
}.bind(this));
|
2015-06-19 20:43:24 +00:00
|
|
|
|
2015-11-11 00:03:19 +00:00
|
|
|
this.fetchMessages();
|
2016-03-21 06:15:21 +00:00
|
|
|
|
|
|
|
this.$('.send-message').focus(this.focusBottomBar.bind(this));
|
|
|
|
this.$('.send-message').blur(this.unfocusBottomBar.bind(this));
|
2014-11-16 21:19:51 +00:00
|
|
|
},
|
2014-07-23 07:24:17 +00:00
|
|
|
|
2014-11-16 21:19:51 +00:00
|
|
|
events: {
|
|
|
|
'submit .send': 'sendMessage',
|
2015-06-16 20:43:40 +00:00
|
|
|
'input .send-message': 'updateMessageFieldSize',
|
|
|
|
'keydown .send-message': 'updateMessageFieldSize',
|
2015-01-13 23:27:18 +00:00
|
|
|
'click .destroy': 'destroyMessages',
|
2015-02-13 04:36:44 +00:00
|
|
|
'click .end-session': 'endSession',
|
|
|
|
'click .leave-group': 'leaveGroup',
|
2015-09-04 20:11:21 +00:00
|
|
|
'click .update-group': 'newGroupUpdate',
|
2015-02-27 02:10:04 +00:00
|
|
|
'click .verify-identity': 'verifyIdentity',
|
2015-08-04 19:15:37 +00:00
|
|
|
'click .view-members': 'viewMembers',
|
2016-03-18 20:09:45 +00:00
|
|
|
'click .conversation-menu .hamburger': 'toggleMenu',
|
2015-06-02 21:56:58 +00:00
|
|
|
'click .openInbox' : 'openInbox',
|
2015-03-11 19:06:19 +00:00
|
|
|
'click' : 'onClick',
|
2016-03-22 00:17:39 +00:00
|
|
|
'click .bottom-bar': 'focusMessageField',
|
2016-03-23 22:09:04 +00:00
|
|
|
'click .back': 'resetPanel',
|
2016-08-15 22:36:29 +00:00
|
|
|
'click .microphone': 'captureAudio',
|
2016-09-28 23:47:57 +00:00
|
|
|
'click .disappearing-messages': 'enableDisappearingMessages',
|
2016-03-21 06:15:21 +00:00
|
|
|
'focus .send-message': 'focusBottomBar',
|
2016-08-15 22:36:29 +00:00
|
|
|
'change .file-input': 'toggleMicrophone',
|
2016-03-21 22:37:53 +00:00
|
|
|
'blur .send-message': 'unfocusBottomBar',
|
2016-03-23 22:09:04 +00:00
|
|
|
'loadMore .message-list': 'fetchMessages',
|
|
|
|
'close .menu': 'closeMenu',
|
|
|
|
'select .message-list .entry': 'messageDetail',
|
2016-09-18 06:55:05 +00:00
|
|
|
'force-resize': 'forceUpdateMessageFieldSize',
|
|
|
|
'verify-identity': 'verifyIdentity'
|
2016-03-21 06:15:21 +00:00
|
|
|
},
|
2016-09-28 23:47:57 +00:00
|
|
|
enableDisappearingMessages: function() {
|
|
|
|
if (!this.model.get('expireTimer')) {
|
2017-01-03 12:52:29 +00:00
|
|
|
this.model.updateExpirationTimer(
|
2016-09-28 23:47:57 +00:00
|
|
|
moment.duration(1, 'day').asSeconds()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2016-08-15 22:36:29 +00:00
|
|
|
toggleMicrophone: function() {
|
|
|
|
if (this.$('.send-message').val().length > 0 || this.fileInput.hasFiles()) {
|
|
|
|
this.$('.capture-audio').hide();
|
|
|
|
} else {
|
|
|
|
this.$('.capture-audio').show();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
captureAudio: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var view = new Whisper.RecorderView().render();
|
|
|
|
view.on('send', this.handleAudioCapture.bind(this));
|
|
|
|
view.on('closed', this.endCaptureAudio.bind(this));
|
|
|
|
view.$el.appendTo(this.$('.capture-audio'));
|
|
|
|
this.$('.send-message').attr('disabled','disabled');
|
|
|
|
this.$('.microphone').hide();
|
|
|
|
},
|
|
|
|
handleAudioCapture: function(blob) {
|
|
|
|
this.fileInput.file = blob;
|
|
|
|
this.fileInput.previewImages();
|
|
|
|
this.$('.bottom-bar form').submit();
|
|
|
|
},
|
|
|
|
endCaptureAudio: function() {
|
|
|
|
this.$('.send-message').removeAttr('disabled');
|
|
|
|
this.$('.microphone').show();
|
|
|
|
},
|
2016-03-21 06:15:21 +00:00
|
|
|
|
|
|
|
unfocusBottomBar: function() {
|
|
|
|
this.$('.bottom-bar form').removeClass('active');
|
|
|
|
},
|
|
|
|
focusBottomBar: function() {
|
|
|
|
this.$('.bottom-bar form').addClass('active');
|
2015-10-30 18:02:58 +00:00
|
|
|
},
|
2015-11-11 04:39:36 +00:00
|
|
|
|
|
|
|
onOpened: function() {
|
|
|
|
this.view.resetScrollPosition();
|
|
|
|
this.$el.trigger('force-resize');
|
|
|
|
this.focusMessageField();
|
|
|
|
this.model.markRead();
|
|
|
|
},
|
|
|
|
|
2015-10-30 18:02:58 +00:00
|
|
|
focusMessageField: function() {
|
|
|
|
this.$messageField.focus();
|
2015-02-23 21:17:50 +00:00
|
|
|
},
|
2015-11-07 22:11:13 +00:00
|
|
|
|
2015-11-11 00:03:19 +00:00
|
|
|
fetchMessages: function() {
|
2016-04-08 22:41:46 +00:00
|
|
|
console.log('fetchMessages');
|
2016-03-19 00:59:54 +00:00
|
|
|
this.$('.bar-container').show();
|
2015-11-11 00:03:19 +00:00
|
|
|
return this.model.fetchContacts().then(function() {
|
|
|
|
return this.model.fetchMessages().then(function() {
|
2016-03-19 00:59:54 +00:00
|
|
|
this.$('.bar-container').hide();
|
2016-10-12 01:32:11 +00:00
|
|
|
this.model.messageCollection.where({unread: 1}).forEach(function(m) {
|
|
|
|
m.fetch();
|
|
|
|
});
|
2015-11-11 00:03:19 +00:00
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
|
|
|
// TODO catch?
|
|
|
|
},
|
|
|
|
|
2016-09-21 00:19:51 +00:00
|
|
|
onExpired: function(message) {
|
2016-09-21 23:26:42 +00:00
|
|
|
var mine = this.model.messageCollection.get(message.id);
|
|
|
|
if (mine && mine.cid !== message.cid) {
|
|
|
|
mine.trigger('expired', mine);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onExpiredCollection: function(message) {
|
2016-09-21 00:19:51 +00:00
|
|
|
this.model.messageCollection.remove(message.id);
|
|
|
|
},
|
|
|
|
|
2015-11-07 22:11:13 +00:00
|
|
|
addMessage: function(message) {
|
|
|
|
this.model.messageCollection.add(message, {merge: true});
|
2016-09-21 00:19:51 +00:00
|
|
|
message.setToExpire();
|
2015-11-14 11:47:21 +00:00
|
|
|
|
|
|
|
if (!this.isHidden() && window.isFocused()) {
|
|
|
|
this.markRead();
|
|
|
|
}
|
2015-09-14 20:47:47 +00:00
|
|
|
},
|
2015-02-23 21:17:50 +00:00
|
|
|
|
2015-08-04 19:15:37 +00:00
|
|
|
viewMembers: function() {
|
2016-01-12 19:06:14 +00:00
|
|
|
return this.model.fetchContacts().then(function() {
|
|
|
|
var view = new Whisper.GroupMemberList({ model: this.model });
|
|
|
|
this.listenBack(view);
|
|
|
|
}.bind(this));
|
2015-08-04 19:15:37 +00:00
|
|
|
},
|
|
|
|
|
2015-06-02 21:56:58 +00:00
|
|
|
openInbox: function() {
|
|
|
|
openInbox();
|
|
|
|
},
|
|
|
|
|
2015-03-11 19:06:19 +00:00
|
|
|
onClick: function(e) {
|
|
|
|
this.closeMenu(e);
|
|
|
|
this.markRead(e);
|
|
|
|
},
|
|
|
|
|
|
|
|
markRead: function(e) {
|
|
|
|
this.model.markRead();
|
|
|
|
},
|
|
|
|
|
2016-09-18 06:55:05 +00:00
|
|
|
verifyIdentity: function(ev, model) {
|
|
|
|
if (!model && this.model.isPrivate()) {
|
|
|
|
model = this.model;
|
|
|
|
}
|
|
|
|
if (model) {
|
2016-09-18 01:59:22 +00:00
|
|
|
var view = new Whisper.KeyVerificationPanelView({
|
2016-09-18 22:16:39 +00:00
|
|
|
model: model
|
2016-09-18 01:59:22 +00:00
|
|
|
});
|
|
|
|
this.listenBack(view);
|
2015-02-27 02:10:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-02-23 21:17:50 +00:00
|
|
|
messageDetail: function(e, data) {
|
2016-11-16 21:25:36 +00:00
|
|
|
var view = new Whisper.MessageDetailView({
|
|
|
|
model: data.message,
|
|
|
|
conversation: this.model
|
2015-03-06 00:30:59 +00:00
|
|
|
});
|
2016-11-16 21:25:36 +00:00
|
|
|
this.listenBack(view);
|
|
|
|
view.render();
|
2015-03-12 18:40:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
listenBack: function(view) {
|
2016-03-21 22:37:53 +00:00
|
|
|
this.panel = view;
|
2016-10-05 17:56:30 +00:00
|
|
|
this.$('.main.panel, .header-buttons.right').hide();
|
2016-03-21 22:37:53 +00:00
|
|
|
this.$('.back').show();
|
|
|
|
view.$el.insertBefore(this.$('.panel'));
|
|
|
|
},
|
|
|
|
resetPanel: function() {
|
|
|
|
this.panel.remove();
|
2016-10-05 17:56:30 +00:00
|
|
|
this.$('.main.panel, .header-buttons.right').show();
|
2016-03-21 22:37:53 +00:00
|
|
|
this.$('.back').hide();
|
|
|
|
this.$el.trigger('force-resize');
|
2015-02-19 19:48:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
closeMenu: function(e) {
|
2016-03-18 20:09:45 +00:00
|
|
|
if (e && !$(e.target).hasClass('hamburger')) {
|
2016-09-28 23:47:57 +00:00
|
|
|
this.$('.conversation-menu .menu-list').hide();
|
|
|
|
}
|
|
|
|
if (e && !$(e.target).hasClass('clock')) {
|
|
|
|
this.$('.timer-menu .menu-list').hide();
|
2015-02-19 19:48:56 +00:00
|
|
|
}
|
2015-01-26 20:37:13 +00:00
|
|
|
},
|
|
|
|
|
2015-02-13 04:36:44 +00:00
|
|
|
endSession: function() {
|
|
|
|
this.model.endSession();
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.menu-list').hide();
|
2015-02-13 04:36:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
leaveGroup: function() {
|
|
|
|
this.model.leaveGroup();
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.menu-list').hide();
|
2015-02-13 04:36:44 +00:00
|
|
|
},
|
|
|
|
|
2015-01-26 20:37:13 +00:00
|
|
|
toggleMenu: function() {
|
2016-09-28 23:47:57 +00:00
|
|
|
this.$('.conversation-menu .menu-list').toggle();
|
2015-01-13 23:27:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
newGroupUpdate: function() {
|
2015-03-12 18:40:55 +00:00
|
|
|
this.newGroupUpdateView = new Whisper.NewGroupUpdateView({
|
2015-06-04 20:29:01 +00:00
|
|
|
model: this.model,
|
2016-10-07 01:43:02 +00:00
|
|
|
window: this.window
|
2015-03-12 18:40:55 +00:00
|
|
|
});
|
|
|
|
this.listenBack(this.newGroupUpdateView);
|
2014-12-02 23:47:28 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
destroyMessages: function(e) {
|
2016-04-23 18:35:04 +00:00
|
|
|
this.confirm(i18n('deleteConversationConfirmation')).then(function() {
|
2014-12-02 23:47:28 +00:00
|
|
|
this.model.destroyMessages();
|
2015-08-31 22:50:32 +00:00
|
|
|
this.remove();
|
2015-11-03 01:03:55 +00:00
|
|
|
}.bind(this)).catch(function() {
|
|
|
|
// clicked cancel, nothing to do.
|
|
|
|
});
|
2015-03-28 01:47:58 +00:00
|
|
|
this.$('.menu-list').hide();
|
2014-11-16 21:19:51 +00:00
|
|
|
},
|
2014-10-25 01:44:30 +00:00
|
|
|
|
2014-11-16 21:19:51 +00:00
|
|
|
sendMessage: function(e) {
|
2016-09-07 20:48:49 +00:00
|
|
|
var toast;
|
2016-04-04 03:06:27 +00:00
|
|
|
if (extension.expired()) {
|
2016-09-07 20:48:49 +00:00
|
|
|
toast = new Whisper.ExpiredToast();
|
2016-04-04 03:06:27 +00:00
|
|
|
toast.$el.insertAfter(this.$el);
|
|
|
|
toast.render();
|
|
|
|
return;
|
|
|
|
}
|
2016-09-07 00:12:45 +00:00
|
|
|
if (this.model.isPrivate() && storage.isBlocked(this.model.id)) {
|
2016-09-07 20:48:49 +00:00
|
|
|
toast = new Whisper.BlockedToast();
|
2016-09-07 00:12:45 +00:00
|
|
|
toast.$el.insertAfter(this.$el);
|
|
|
|
toast.render();
|
|
|
|
return;
|
|
|
|
}
|
2014-11-16 21:19:51 +00:00
|
|
|
e.preventDefault();
|
2015-06-23 20:43:22 +00:00
|
|
|
var input = this.$messageField;
|
2015-07-03 19:53:45 +00:00
|
|
|
var message = this.replace_colons(input.val()).trim();
|
2014-11-16 21:19:51 +00:00
|
|
|
var convo = this.model;
|
2014-07-23 20:06:37 +00:00
|
|
|
|
2014-11-16 21:19:51 +00:00
|
|
|
if (message.length > 0 || this.fileInput.hasFiles()) {
|
|
|
|
this.fileInput.getFiles().then(function(attachments) {
|
|
|
|
convo.sendMessage(message, attachments);
|
|
|
|
});
|
|
|
|
input.val("");
|
2015-06-19 20:43:24 +00:00
|
|
|
this.forceUpdateMessageFieldSize(e);
|
2015-02-10 09:20:21 +00:00
|
|
|
this.fileInput.deleteFiles();
|
2014-11-16 21:19:51 +00:00
|
|
|
}
|
2015-03-11 01:12:40 +00:00
|
|
|
},
|
2015-06-16 20:43:40 +00:00
|
|
|
|
2015-03-11 01:12:40 +00:00
|
|
|
replace_colons: function(str) {
|
2016-02-18 01:08:50 +00:00
|
|
|
return str.replace(emoji.rx_colons, function(m) {
|
2015-03-11 01:12:40 +00:00
|
|
|
var idx = m.substr(1, m.length-2);
|
|
|
|
var val = emoji.map.colons[idx];
|
2015-03-12 18:03:11 +00:00
|
|
|
if (val) {
|
|
|
|
return emoji.data[val][0][0];
|
|
|
|
} else {
|
|
|
|
return m;
|
|
|
|
}
|
2015-03-11 01:12:40 +00:00
|
|
|
});
|
2015-06-04 00:23:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
updateTitle: function() {
|
|
|
|
this.$('.conversation-title').text(this.model.getTitle());
|
2015-06-16 20:43:40 +00:00
|
|
|
},
|
|
|
|
|
2016-09-11 22:03:05 +00:00
|
|
|
updateColor: function(model, color) {
|
|
|
|
var header = this.$('.conversation-header');
|
|
|
|
header.removeClass(Whisper.Conversation.COLORS);
|
|
|
|
if (color) {
|
|
|
|
header.addClass(color);
|
|
|
|
}
|
2015-11-12 20:08:29 +00:00
|
|
|
var avatarView = new (Whisper.View.extend({
|
|
|
|
templateName: 'avatar',
|
|
|
|
render_attributes: { avatar: this.model.getAvatar() }
|
|
|
|
}))();
|
2016-09-11 22:03:05 +00:00
|
|
|
header.find('.avatar').replaceWith(avatarView.render().$('.avatar'));
|
2015-11-12 20:08:29 +00:00
|
|
|
},
|
|
|
|
|
2015-06-16 20:43:40 +00:00
|
|
|
updateMessageFieldSize: function (event) {
|
|
|
|
var keyCode = event.which || event.keyCode;
|
|
|
|
|
2015-07-03 11:49:01 +00:00
|
|
|
if (keyCode === 13 && !event.altKey && !event.shiftKey && !event.ctrlKey) {
|
2015-06-16 20:43:40 +00:00
|
|
|
// enter pressed - submit the form now
|
2015-06-17 21:06:19 +00:00
|
|
|
event.preventDefault();
|
2015-06-16 20:43:40 +00:00
|
|
|
return this.$('.bottom-bar form').submit();
|
|
|
|
}
|
2016-08-15 22:36:29 +00:00
|
|
|
this.toggleMicrophone();
|
2015-06-16 20:43:40 +00:00
|
|
|
|
2015-07-14 21:11:11 +00:00
|
|
|
this.view.measureScrollPosition();
|
|
|
|
window.autosize(this.$messageField);
|
2015-07-08 19:45:40 +00:00
|
|
|
|
2016-04-16 02:17:16 +00:00
|
|
|
var $attachmentPreviews = this.$('.attachment-previews'),
|
|
|
|
$bottomBar = this.$('.bottom-bar');
|
|
|
|
|
|
|
|
$bottomBar.outerHeight(
|
|
|
|
this.$messageField.outerHeight() +
|
2016-08-31 01:27:54 +00:00
|
|
|
$attachmentPreviews.outerHeight() +
|
|
|
|
parseInt($bottomBar.css('min-height')));
|
2016-04-16 02:17:16 +00:00
|
|
|
|
2015-07-14 21:11:11 +00:00
|
|
|
this.view.scrollToBottomIfNeeded();
|
2015-06-19 20:43:24 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
forceUpdateMessageFieldSize: function (event) {
|
2015-09-16 03:50:00 +00:00
|
|
|
if (this.isHidden()) {
|
2015-08-25 23:47:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-07-14 21:11:11 +00:00
|
|
|
this.view.scrollToBottomIfNeeded();
|
2015-06-23 20:43:22 +00:00
|
|
|
window.autosize.update(this.$messageField);
|
2015-06-19 20:43:24 +00:00
|
|
|
this.updateMessageFieldSize(event);
|
2015-09-16 03:50:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isHidden: function() {
|
2015-10-02 18:21:10 +00:00
|
|
|
return (this.$el.css('display') === 'none') || this.$('.panel').css('display') === 'none';
|
2014-11-16 21:19:51 +00:00
|
|
|
}
|
|
|
|
});
|
2014-07-23 07:24:17 +00:00
|
|
|
})();
|