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') };
|
|
|
|
}
|
|
|
|
});
|
2017-05-12 22:16:02 +00:00
|
|
|
Whisper.LeftGroupToast = Whisper.ToastView.extend({
|
|
|
|
render_attributes: function() {
|
|
|
|
return { toastMessage: i18n('youLeftTheGroup') };
|
|
|
|
}
|
|
|
|
});
|
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();
|
|
|
|
}
|
|
|
|
});
|
2017-05-19 01:33:35 +00:00
|
|
|
|
2016-09-28 23:47:57 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-07-25 01:43:35 +00:00
|
|
|
Whisper.ConversationLoadingScreen = Whisper.View.extend({
|
|
|
|
templateName: 'conversation-loading-screen',
|
2017-07-25 23:00:06 +00:00
|
|
|
className: 'conversation-loading-screen'
|
2017-07-25 01:43:35 +00:00
|
|
|
});
|
|
|
|
|
2017-06-10 19:18:24 +00:00
|
|
|
Whisper.ConversationTitleView = Whisper.View.extend({
|
|
|
|
templateName: 'conversation-title',
|
2017-06-14 00:36:32 +00:00
|
|
|
initialize: function() {
|
|
|
|
this.listenTo(this.model, 'change', this.render);
|
|
|
|
},
|
2017-06-10 19:18:24 +00:00
|
|
|
render_attributes: function() {
|
|
|
|
return {
|
2017-06-14 19:29:32 +00:00
|
|
|
isVerified: this.model.isVerified(),
|
|
|
|
verified: i18n('verified'),
|
2017-06-10 19:18:24 +00:00
|
|
|
name: this.model.getName(),
|
|
|
|
number: this.model.getNumber(),
|
2017-09-11 16:50:35 +00:00
|
|
|
profileName: this.model.getProfileName()
|
2017-06-10 19:18:24 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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',
|
2017-06-14 17:58:05 +00:00
|
|
|
isMe: this.model.isMe(),
|
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'),
|
2017-06-10 19:18:24 +00:00
|
|
|
'show-members' : i18n('showMembers'),
|
2015-12-25 06:50:27 +00:00
|
|
|
'end-session' : i18n('resetSession'),
|
2017-06-10 19:18:24 +00:00
|
|
|
'show-identity' : i18n('showSafetyNumber'),
|
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'),
|
2017-05-26 16:50:23 +00:00
|
|
|
'android-length-warning': i18n('androidMessageLengthWarning'),
|
2016-09-28 23:47:57 +00:00
|
|
|
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);
|
2017-06-14 00:36:32 +00:00
|
|
|
this.listenTo(this.model, 'change:verified', this.onVerifiedChange);
|
2016-09-11 22:03:05 +00:00
|
|
|
this.listenTo(this.model, 'change:color', this.updateColor);
|
2017-09-11 16:50:35 +00:00
|
|
|
this.listenTo(this.model, 'change:avatar change:profileAvatar', this.updateAvatar);
|
2015-11-07 22:11:13 +00:00
|
|
|
this.listenTo(this.model, 'newmessage', this.addMessage);
|
2017-02-22 21:20:04 +00:00
|
|
|
this.listenTo(this.model, 'delivered', this.updateMessage);
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
this.listenTo(this.model, 'read', this.updateMessage);
|
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);
|
2017-07-26 21:55:59 +00:00
|
|
|
this.listenTo(this.model, 'prune', this.onPrune);
|
2016-09-21 23:26:42 +00:00
|
|
|
this.listenTo(this.model.messageCollection, 'expired', this.onExpiredCollection);
|
2015-01-16 08:22:24 +00:00
|
|
|
|
2017-06-16 21:27:43 +00:00
|
|
|
this.lazyUpdateVerified = _.debounce(
|
|
|
|
this.model.updateVerified.bind(this.model),
|
2017-07-12 23:04:10 +00:00
|
|
|
1000 // one second
|
|
|
|
);
|
|
|
|
this.throttledGetProfiles = _.throttle(
|
|
|
|
this.model.getProfiles.bind(this.model),
|
|
|
|
1000 * 60 * 5 // five minutes
|
2017-06-16 21:27:43 +00:00
|
|
|
);
|
2017-06-16 18:51:08 +00:00
|
|
|
|
2015-03-05 23:25:49 +00:00
|
|
|
this.render();
|
2017-07-25 01:43:35 +00:00
|
|
|
|
|
|
|
this.loadingScreen = new Whisper.ConversationLoadingScreen();
|
|
|
|
this.loadingScreen.render();
|
|
|
|
this.loadingScreen.$el.prependTo(this.el);
|
|
|
|
|
2017-07-26 21:55:59 +00:00
|
|
|
this.timerMenu = 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
|
|
|
|
2017-06-10 19:18:24 +00:00
|
|
|
this.titleView = new Whisper.ConversationTitleView({
|
|
|
|
el: this.$('.conversation-title'),
|
|
|
|
model: this.model
|
|
|
|
});
|
|
|
|
this.titleView.render();
|
|
|
|
|
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');
|
|
|
|
|
2017-07-26 21:55:59 +00:00
|
|
|
this.onResize = this.forceUpdateMessageFieldSize.bind(this);
|
|
|
|
this.window.addEventListener('resize', this.onResize);
|
2015-06-23 20:43:22 +00:00
|
|
|
|
2017-07-26 21:55:59 +00:00
|
|
|
this.onFocus = function() {
|
2015-08-27 21:36:32 +00:00
|
|
|
if (this.$el.css('display') !== 'none') {
|
2017-05-30 21:36:45 +00:00
|
|
|
this.markRead();
|
2015-08-27 21:36:32 +00:00
|
|
|
}
|
|
|
|
}.bind(this);
|
2017-07-26 21:55:59 +00:00
|
|
|
this.window.addEventListener('focus', this.onFocus);
|
2015-06-26 18:53:00 +00:00
|
|
|
|
2016-09-22 23:37:12 +00:00
|
|
|
extension.windows.onClosed(function () {
|
2017-07-31 17:01:20 +00:00
|
|
|
this.unload('windows closed');
|
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));
|
2017-10-30 20:54:55 +00:00
|
|
|
|
|
|
|
this.$emojiPanelContainer = this.$('.emoji-panel-container');
|
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: {
|
2017-06-14 00:36:32 +00:00
|
|
|
'submit .send': 'checkUnverifiedSendMessage',
|
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',
|
2017-06-14 00:36:32 +00:00
|
|
|
'click .show-identity': 'showSafetyNumber',
|
2017-06-10 19:18:24 +00:00
|
|
|
'click .show-members': 'showMembers',
|
2016-03-18 20:09:45 +00:00
|
|
|
'click .conversation-menu .hamburger': 'toggleMenu',
|
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',
|
2017-05-19 01:33:35 +00:00
|
|
|
'click .scroll-down-button-view': 'scrollToBottom',
|
2017-10-30 20:54:55 +00:00
|
|
|
'click button.emoji': 'toggleEmojiPanel',
|
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',
|
2017-06-01 18:30:14 +00:00
|
|
|
'loadMore .message-list': 'loadMoreMessages',
|
2017-05-19 01:33:35 +00:00
|
|
|
'newOffscreenMessage .message-list': 'addScrollDownButtonWithCount',
|
2017-06-01 18:54:57 +00:00
|
|
|
'atBottom .message-list': 'removeScrollDownButton',
|
2017-05-19 01:33:35 +00:00
|
|
|
'farFromBottom .message-list': 'addScrollDownButton',
|
2017-05-31 00:29:23 +00:00
|
|
|
'lazyScroll .message-list': 'onLazyScroll',
|
2016-03-23 22:09:04 +00:00
|
|
|
'close .menu': 'closeMenu',
|
|
|
|
'select .message-list .entry': 'messageDetail',
|
2016-09-18 06:55:05 +00:00
|
|
|
'force-resize': 'forceUpdateMessageFieldSize',
|
2017-06-19 03:45:08 +00:00
|
|
|
'show-identity': 'showSafetyNumber',
|
2017-04-25 03:58:51 +00:00
|
|
|
'dragover': 'sendToFileInput',
|
|
|
|
'drop': 'sendToFileInput',
|
|
|
|
'dragleave': 'sendToFileInput'
|
|
|
|
},
|
|
|
|
sendToFileInput: function(e) {
|
2017-09-22 16:44:09 +00:00
|
|
|
if (e.originalEvent.dataTransfer.types[0] != 'Files') {
|
|
|
|
return;
|
|
|
|
}
|
2017-04-25 03:58:51 +00:00
|
|
|
this.fileInput.$el.trigger(e);
|
2016-03-21 06:15:21 +00:00
|
|
|
},
|
2017-06-10 19:18:24 +00:00
|
|
|
|
2017-07-26 21:55:59 +00:00
|
|
|
onPrune: function() {
|
|
|
|
if (!this.model.messageCollection.length || !this.lastActivity) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var oneHourAgo = Date.now() - 60 * 60 * 1000;
|
|
|
|
if (this.isHidden() && this.lastActivity < oneHourAgo) {
|
2017-07-31 17:01:20 +00:00
|
|
|
this.unload('inactivity');
|
2017-07-26 21:55:59 +00:00
|
|
|
} else if (this.view.atBottom()) {
|
|
|
|
this.trim();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-07-31 17:01:20 +00:00
|
|
|
unload: function(reason) {
|
2017-09-25 23:41:57 +00:00
|
|
|
console.log(
|
|
|
|
'unloading conversation',
|
|
|
|
this.model.idForLogging(),
|
|
|
|
'due to:',
|
|
|
|
reason
|
|
|
|
);
|
2017-07-26 21:55:59 +00:00
|
|
|
|
|
|
|
this.timerMenu.remove();
|
|
|
|
this.fileInput.remove();
|
|
|
|
this.titleView.remove();
|
|
|
|
|
|
|
|
if (this.captureAudioView) {
|
|
|
|
this.captureAudioView.remove();
|
|
|
|
}
|
|
|
|
if (this.banner) {
|
|
|
|
this.banner.remove();
|
|
|
|
}
|
|
|
|
if (this.lastSeenIndicator) {
|
|
|
|
this.lastSeenIndicator.remove();
|
|
|
|
}
|
|
|
|
if (this.scrollDownButton) {
|
|
|
|
this.scrollDownButton.remove();
|
|
|
|
}
|
|
|
|
if (this.panels && this.panels.length) {
|
|
|
|
for (var i = 0, max = this.panels.length; i < max; i += 1) {
|
|
|
|
var panel = this.panels[i];
|
|
|
|
panel.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.window.removeEventListener('resize', this.onResize);
|
|
|
|
this.window.removeEventListener('focus', this.onFocus);
|
|
|
|
|
2017-07-28 21:51:57 +00:00
|
|
|
window.autosize.destroy(this.$messageField);
|
|
|
|
|
2017-07-26 21:55:59 +00:00
|
|
|
this.view.remove();
|
|
|
|
|
|
|
|
this.remove();
|
|
|
|
|
|
|
|
this.model.messageCollection.forEach(function(model) {
|
|
|
|
model.trigger('unload');
|
|
|
|
});
|
|
|
|
this.model.messageCollection.reset([]);
|
|
|
|
},
|
|
|
|
|
|
|
|
trim: function() {
|
|
|
|
var MAX = 100;
|
|
|
|
var toRemove = this.model.messageCollection.length - MAX;
|
|
|
|
if (toRemove <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var models = [];
|
|
|
|
for (var i = 0; i < toRemove; i += 1) {
|
|
|
|
var model = this.model.messageCollection.at(i);
|
|
|
|
models.push(model);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!models.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-25 23:41:57 +00:00
|
|
|
console.log(
|
|
|
|
'trimming conversation',
|
|
|
|
this.model.idForLogging(),
|
|
|
|
'of',
|
|
|
|
models.length,
|
|
|
|
'old messages'
|
|
|
|
);
|
2017-07-26 21:55:59 +00:00
|
|
|
|
|
|
|
this.model.messageCollection.remove(models);
|
|
|
|
_.forEach(models, function(model) {
|
|
|
|
model.trigger('unload');
|
|
|
|
});
|
|
|
|
},
|
2017-06-14 00:36:32 +00:00
|
|
|
|
|
|
|
markAllAsVerifiedDefault: function(unverified) {
|
|
|
|
return Promise.all(unverified.map(function(contact) {
|
2017-06-15 19:27:41 +00:00
|
|
|
if (contact.isUnverified()) {
|
|
|
|
return contact.setVerifiedDefault();
|
|
|
|
}
|
|
|
|
}.bind(this)));
|
2017-06-14 00:36:32 +00:00
|
|
|
},
|
|
|
|
|
2017-07-03 18:52:12 +00:00
|
|
|
|
|
|
|
markAllAsApproved: function(untrusted) {
|
|
|
|
return Promise.all(untrusted.map(function(contact) {
|
|
|
|
return contact.setApproved();
|
|
|
|
}.bind(this)));
|
|
|
|
},
|
|
|
|
|
2017-06-14 00:36:32 +00:00
|
|
|
openSafetyNumberScreens: function(unverified) {
|
|
|
|
if (unverified.length === 1) {
|
|
|
|
this.showSafetyNumber(null, unverified.at(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-16 23:48:06 +00:00
|
|
|
this.showMembers(null, unverified, {needVerify: true});
|
2017-06-10 19:18:24 +00:00
|
|
|
},
|
2017-06-14 00:36:32 +00:00
|
|
|
|
|
|
|
onVerifiedChange: function() {
|
|
|
|
if (this.model.isUnverified()) {
|
|
|
|
var unverified = this.model.getUnverified();
|
|
|
|
var message;
|
2017-06-23 23:27:34 +00:00
|
|
|
if (!unverified.length) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-14 00:36:32 +00:00
|
|
|
if (unverified.length > 1) {
|
|
|
|
message = i18n('multipleNoLongerVerified');
|
|
|
|
} else {
|
|
|
|
message = i18n('noLongerVerified', unverified.at(0).getTitle());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to re-add, since unverified set may have changed
|
|
|
|
if (this.banner) {
|
|
|
|
this.banner.remove();
|
|
|
|
this.banner = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.banner = new Whisper.BannerView({
|
|
|
|
message: message,
|
|
|
|
onDismiss: function() {
|
|
|
|
this.markAllAsVerifiedDefault(unverified);
|
|
|
|
}.bind(this),
|
|
|
|
onClick: function() {
|
|
|
|
this.openSafetyNumberScreens(unverified);
|
|
|
|
}.bind(this)
|
|
|
|
});
|
|
|
|
|
|
|
|
var container = this.$('.discussion-container');
|
|
|
|
container.append(this.banner.el);
|
|
|
|
} else if (this.banner) {
|
|
|
|
this.banner.remove();
|
|
|
|
this.banner = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
},
|
2017-05-31 11:34:03 +00:00
|
|
|
toggleLengthWarning: function() {
|
2017-06-02 23:42:23 +00:00
|
|
|
if (this.$('.send-message').val().length > 2000) {
|
2017-05-26 16:50:23 +00:00
|
|
|
this.$('.android-length-warning').show();
|
|
|
|
} else {
|
|
|
|
this.$('.android-length-warning').hide();
|
|
|
|
}
|
|
|
|
},
|
2016-08-15 22:36:29 +00:00
|
|
|
captureAudio: function(e) {
|
|
|
|
e.preventDefault();
|
2017-07-26 21:55:59 +00:00
|
|
|
|
2018-01-05 00:51:00 +00:00
|
|
|
// Note - clicking anywhere will close the audio capture panel, due to
|
|
|
|
// the onClick handler in InboxView, which calls its closeRecording method.
|
|
|
|
|
2017-07-26 21:55:59 +00:00
|
|
|
if (this.captureAudioView) {
|
|
|
|
this.captureAudioView.remove();
|
|
|
|
this.captureAudioView = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var view = this.captureAudioView = new Whisper.RecorderView();
|
|
|
|
view.render();
|
2016-08-15 22:36:29 +00:00
|
|
|
view.on('send', this.handleAudioCapture.bind(this));
|
|
|
|
view.on('closed', this.endCaptureAudio.bind(this));
|
|
|
|
view.$el.appendTo(this.$('.capture-audio'));
|
2017-07-26 21:55:59 +00:00
|
|
|
|
2018-01-05 00:51:00 +00:00
|
|
|
this.$('.send-message').attr('disabled', true);
|
2016-08-15 22:36:29 +00:00
|
|
|
this.$('.microphone').hide();
|
|
|
|
},
|
|
|
|
handleAudioCapture: function(blob) {
|
|
|
|
this.fileInput.file = blob;
|
2017-05-10 22:32:05 +00:00
|
|
|
this.fileInput.isVoiceNote = true;
|
2016-08-15 22:36:29 +00:00
|
|
|
this.fileInput.previewImages();
|
|
|
|
this.$('.bottom-bar form').submit();
|
|
|
|
},
|
|
|
|
endCaptureAudio: function() {
|
|
|
|
this.$('.send-message').removeAttr('disabled');
|
|
|
|
this.$('.microphone').show();
|
2017-07-26 21:55:59 +00:00
|
|
|
this.captureAudioView = null;
|
2016-08-15 22:36:29 +00:00
|
|
|
},
|
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
|
|
|
|
2017-05-31 00:29:23 +00:00
|
|
|
onLazyScroll: function() {
|
2017-05-31 16:48:47 +00:00
|
|
|
// The in-progress fetch check is important, because while that happens, lots
|
|
|
|
// of messages are added to the DOM, one by one, changing window size and
|
|
|
|
// generating scroll events.
|
|
|
|
if (!this.isHidden() && window.isFocused() && !this.inProgressFetch) {
|
2017-07-26 21:55:59 +00:00
|
|
|
this.lastActivity = Date.now();
|
2017-05-31 00:29:23 +00:00
|
|
|
this.markRead();
|
|
|
|
}
|
|
|
|
},
|
2017-05-30 21:36:45 +00:00
|
|
|
updateUnread: function() {
|
2017-06-01 18:54:57 +00:00
|
|
|
this.resetLastSeenIndicator();
|
2017-06-07 16:51:59 +00:00
|
|
|
// Waiting for scrolling caused by resetLastSeenIndicator to settle down
|
|
|
|
setTimeout(this.markRead.bind(this), 1);
|
2017-05-17 21:32:03 +00:00
|
|
|
},
|
|
|
|
|
2017-07-25 01:43:35 +00:00
|
|
|
onLoaded: function () {
|
|
|
|
var view = this.loadingScreen;
|
|
|
|
if (view) {
|
2017-08-16 20:53:50 +00:00
|
|
|
var openDelta = Date.now() - this.openStart;
|
2017-09-25 23:41:57 +00:00
|
|
|
console.log(
|
|
|
|
'Conversation',
|
|
|
|
this.model.idForLogging(),
|
|
|
|
'took',
|
|
|
|
openDelta,
|
|
|
|
'milliseconds to load'
|
|
|
|
);
|
2017-07-25 01:43:35 +00:00
|
|
|
this.loadingScreen = null;
|
|
|
|
view.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-11 04:39:36 +00:00
|
|
|
onOpened: function() {
|
2017-08-16 20:53:50 +00:00
|
|
|
this.openStart = Date.now();
|
2017-07-26 21:55:59 +00:00
|
|
|
this.lastActivity = Date.now();
|
|
|
|
|
2017-07-12 23:04:10 +00:00
|
|
|
this.statusFetch = this.throttledGetProfiles().then(function() {
|
2017-08-12 00:16:22 +00:00
|
|
|
return this.model.updateVerified().then(function() {
|
2017-06-16 21:27:43 +00:00
|
|
|
this.onVerifiedChange();
|
2017-06-16 01:23:29 +00:00
|
|
|
this.statusFetch = null;
|
|
|
|
console.log('done with status fetch');
|
|
|
|
}.bind(this));
|
|
|
|
}.bind(this));
|
2017-05-27 00:05:49 +00:00
|
|
|
|
2017-08-12 00:16:22 +00:00
|
|
|
// We schedule our catch-up decrypt right after any in-progress fetch of
|
|
|
|
// messages from the database, then ensure that the loading screen is only
|
|
|
|
// dismissed when that is complete.
|
|
|
|
var messagesLoaded = this.inProgressFetch || Promise.resolve();
|
|
|
|
|
2017-10-18 18:59:12 +00:00
|
|
|
messagesLoaded
|
|
|
|
.then(this.model.decryptOldIncomingKeyErrors.bind(this))
|
2017-07-25 01:43:35 +00:00
|
|
|
.then(this.onLoaded.bind(this), this.onLoaded.bind(this));
|
|
|
|
|
2015-11-11 04:39:36 +00:00
|
|
|
this.view.resetScrollPosition();
|
|
|
|
this.$el.trigger('force-resize');
|
|
|
|
this.focusMessageField();
|
2017-05-17 21:32:03 +00:00
|
|
|
|
|
|
|
if (this.inProgressFetch) {
|
|
|
|
this.inProgressFetch.then(this.updateUnread.bind(this));
|
|
|
|
} else {
|
|
|
|
this.updateUnread();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-05-19 01:33:35 +00:00
|
|
|
addScrollDownButtonWithCount: function() {
|
|
|
|
this.updateScrollDownButton(1);
|
|
|
|
},
|
|
|
|
|
|
|
|
addScrollDownButton: function() {
|
|
|
|
if (!this.scrollDownButton) {
|
|
|
|
this.updateScrollDownButton();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
updateScrollDownButton: function(count) {
|
|
|
|
if (this.scrollDownButton) {
|
|
|
|
this.scrollDownButton.increment(count);
|
|
|
|
} else {
|
|
|
|
this.scrollDownButton = new Whisper.ScrollDownButtonView({count: count});
|
|
|
|
this.scrollDownButton.render();
|
|
|
|
var container = this.$('.discussion-container');
|
|
|
|
container.append(this.scrollDownButton.el);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-06-01 18:54:57 +00:00
|
|
|
removeScrollDownButton: function() {
|
2017-05-19 01:33:35 +00:00
|
|
|
if (this.scrollDownButton) {
|
2017-07-18 20:54:57 +00:00
|
|
|
var button = this.scrollDownButton;
|
2017-05-19 01:33:35 +00:00
|
|
|
this.scrollDownButton = null;
|
2017-07-18 20:54:57 +00:00
|
|
|
button.remove();
|
2017-05-19 01:33:35 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-05-30 21:36:45 +00:00
|
|
|
removeLastSeenIndicator: function() {
|
|
|
|
if (this.lastSeenIndicator) {
|
2017-07-18 20:54:57 +00:00
|
|
|
var indicator = this.lastSeenIndicator;
|
2017-05-17 21:32:03 +00:00
|
|
|
this.lastSeenIndicator = null;
|
2017-07-18 20:54:57 +00:00
|
|
|
indicator.remove();
|
2017-05-17 21:32:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-05-19 01:33:35 +00:00
|
|
|
scrollToBottom: function() {
|
2017-05-25 17:57:40 +00:00
|
|
|
// If we're above the last seen indicator, we should scroll there instead
|
|
|
|
// Note: if we don't end up at the bottom of the conversation, button will not go away!
|
|
|
|
if (this.lastSeenIndicator) {
|
|
|
|
var location = this.lastSeenIndicator.$el.position().top;
|
|
|
|
if (location > 0) {
|
|
|
|
this.lastSeenIndicator.el.scrollIntoView();
|
|
|
|
return;
|
2017-05-31 00:29:23 +00:00
|
|
|
} else {
|
|
|
|
this.removeLastSeenIndicator();
|
2017-05-25 17:57:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-19 01:33:35 +00:00
|
|
|
this.view.scrollToBottom();
|
|
|
|
},
|
|
|
|
|
2017-06-01 18:54:57 +00:00
|
|
|
resetLastSeenIndicator: function(options) {
|
2017-05-25 17:57:40 +00:00
|
|
|
options = options || {};
|
|
|
|
_.defaults(options, {scroll: true});
|
|
|
|
|
2017-07-05 19:17:55 +00:00
|
|
|
var unreadCount = 0;
|
|
|
|
var oldestUnread = null;
|
|
|
|
|
|
|
|
// We need to iterate here because unseen non-messages do not contribute to
|
|
|
|
// the badge number, but should be reflected in the indicator's count.
|
|
|
|
this.model.messageCollection.forEach(function(model) {
|
|
|
|
if (!model.get('unread')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unreadCount += 1;
|
|
|
|
if (!oldestUnread) {
|
|
|
|
oldestUnread = model;
|
|
|
|
}
|
2017-05-17 21:32:03 +00:00
|
|
|
});
|
|
|
|
|
2017-05-30 21:36:45 +00:00
|
|
|
this.removeLastSeenIndicator();
|
2017-05-26 16:29:04 +00:00
|
|
|
|
2017-07-05 19:17:55 +00:00
|
|
|
if (oldestUnread) {
|
2017-05-17 21:32:03 +00:00
|
|
|
this.lastSeenIndicator = new Whisper.LastSeenIndicatorView({count: unreadCount});
|
2017-06-08 22:37:00 +00:00
|
|
|
var lastSeenEl = this.lastSeenIndicator.render().$el;
|
2017-05-17 21:32:03 +00:00
|
|
|
|
2017-06-08 22:37:00 +00:00
|
|
|
lastSeenEl.insertBefore(this.$('#' + oldestUnread.get('id')));
|
2017-05-25 17:57:40 +00:00
|
|
|
|
2017-05-27 00:24:51 +00:00
|
|
|
if (this.view.atBottom() || options.scroll) {
|
2017-06-08 22:37:00 +00:00
|
|
|
lastSeenEl[0].scrollIntoView();
|
2017-05-25 17:57:40 +00:00
|
|
|
}
|
2017-05-19 01:33:35 +00:00
|
|
|
|
2017-05-19 21:45:40 +00:00
|
|
|
// scrollIntoView is an async operation, but we have no way to listen for
|
2017-07-05 19:17:55 +00:00
|
|
|
// completion of the resultant scroll.
|
2017-05-19 21:45:40 +00:00
|
|
|
setTimeout(function() {
|
2017-05-27 00:24:51 +00:00
|
|
|
if (!this.view.atBottom()) {
|
2017-05-19 21:45:40 +00:00
|
|
|
this.addScrollDownButtonWithCount(unreadCount);
|
|
|
|
}
|
|
|
|
}.bind(this), 1);
|
2017-05-17 21:32:03 +00:00
|
|
|
}
|
2015-11-11 04:39:36 +00:00
|
|
|
},
|
|
|
|
|
2015-10-30 18:02:58 +00:00
|
|
|
focusMessageField: function() {
|
2018-01-05 00:51:00 +00:00
|
|
|
this.$messageField.focus();
|
|
|
|
},
|
|
|
|
|
|
|
|
focusMessageFieldAndClearDisabled: function() {
|
|
|
|
this.$messageField.removeAttr('disabled');
|
2015-10-30 18:02:58 +00:00
|
|
|
this.$messageField.focus();
|
2015-02-23 21:17:50 +00:00
|
|
|
},
|
2015-11-07 22:11:13 +00:00
|
|
|
|
2017-06-01 18:30:14 +00:00
|
|
|
loadMoreMessages: function() {
|
|
|
|
if (this.inProgressFetch) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.view.measureScrollPosition();
|
|
|
|
var startingHeight = this.view.scrollHeight;
|
|
|
|
|
|
|
|
this.fetchMessages().then(function() {
|
|
|
|
// We delay this work to let scrolling/layout settle down first
|
|
|
|
setTimeout(function() {
|
|
|
|
this.view.measureScrollPosition();
|
|
|
|
var endingHeight = this.view.scrollHeight;
|
|
|
|
var delta = endingHeight - startingHeight;
|
|
|
|
|
2017-06-02 02:15:52 +00:00
|
|
|
var newScrollPosition = this.view.scrollPosition + delta - this.view.outerHeight;
|
2017-06-01 18:30:14 +00:00
|
|
|
this.view.$el.scrollTop(newScrollPosition);
|
|
|
|
}.bind(this), 1);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
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();
|
2017-05-22 22:33:37 +00:00
|
|
|
if (this.inProgressFetch) {
|
|
|
|
console.log('Multiple fetchMessage calls!');
|
|
|
|
}
|
2017-05-17 21:32:03 +00:00
|
|
|
this.inProgressFetch = this.model.fetchContacts().then(function() {
|
2015-11-11 00:03:19 +00:00
|
|
|
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();
|
|
|
|
});
|
2017-05-17 21:32:03 +00:00
|
|
|
this.inProgressFetch = null;
|
2015-11-11 00:03:19 +00:00
|
|
|
}.bind(this));
|
2017-07-15 00:05:23 +00:00
|
|
|
}.bind(this)).catch(function(error) {
|
|
|
|
console.log('fetchMessages error:', error && error.stack ? error.stack : error);
|
|
|
|
this.inProgressFetch = null;
|
2015-11-11 00:03:19 +00:00
|
|
|
}.bind(this));
|
2017-05-17 21:32:03 +00:00
|
|
|
|
|
|
|
return this.inProgressFetch;
|
2015-11-11 00:03:19 +00:00
|
|
|
},
|
|
|
|
|
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) {
|
2018-01-23 20:27:34 +00:00
|
|
|
var removeMessage = function() {
|
|
|
|
console.log(
|
|
|
|
'removing message',
|
|
|
|
message.get('sent_at'),
|
|
|
|
'from collection'
|
|
|
|
);
|
|
|
|
this.model.messageCollection.remove(message.id);
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
// If a fetch is in progress, then we need to wait until that's complete to
|
|
|
|
// do this removal. Otherwise we could remove from messageCollection, then
|
|
|
|
// the async database fetch could include the removed message.
|
|
|
|
|
|
|
|
if (this.inProgressFetch) {
|
|
|
|
this.inProgressFetch.then(removeMessage);
|
|
|
|
} else {
|
|
|
|
removeMessage();
|
|
|
|
}
|
2016-09-21 00:19:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-07 22:11:13 +00:00
|
|
|
addMessage: function(message) {
|
2017-06-16 18:51:08 +00:00
|
|
|
// This is debounced, so it won't hit the database too often.
|
|
|
|
this.lazyUpdateVerified();
|
|
|
|
|
2015-11-07 22:11:13 +00:00
|
|
|
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
|
|
|
|
2017-11-21 22:41:05 +00:00
|
|
|
if (message.isOutgoing()) {
|
|
|
|
this.removeLastSeenIndicator();
|
|
|
|
}
|
2017-05-25 18:28:31 +00:00
|
|
|
if (this.lastSeenIndicator) {
|
|
|
|
this.lastSeenIndicator.increment(1);
|
|
|
|
}
|
|
|
|
|
2017-05-23 16:52:57 +00:00
|
|
|
if (!this.isHidden() && !window.isFocused()) {
|
2017-05-30 21:36:45 +00:00
|
|
|
// The conversation is visible, but window is not focused
|
2017-06-01 18:54:57 +00:00
|
|
|
if (!this.lastSeenIndicator) {
|
|
|
|
this.resetLastSeenIndicator({scroll: false});
|
|
|
|
} else if (this.view.atBottom() && this.model.get('unreadCount') === this.lastSeenIndicator.getCount()) {
|
2017-06-01 22:37:32 +00:00
|
|
|
// The count check ensures that the last seen indicator is still in
|
|
|
|
// sync with the real number of unread, so we can scroll to it.
|
|
|
|
// We only do this if we're at the bottom, because that signals that
|
|
|
|
// the user is okay with us changing scroll around so they see the
|
|
|
|
// right unseen message first.
|
|
|
|
this.resetLastSeenIndicator({scroll: true});
|
2017-06-01 18:54:57 +00:00
|
|
|
}
|
2017-05-23 16:52:57 +00:00
|
|
|
}
|
|
|
|
else if (!this.isHidden() && window.isFocused()) {
|
2017-05-30 21:36:45 +00:00
|
|
|
// The conversation is visible and in focus
|
2017-05-31 00:29:23 +00:00
|
|
|
this.markRead();
|
2017-05-30 21:36:45 +00:00
|
|
|
|
2017-05-31 00:29:23 +00:00
|
|
|
// When we're scrolled up and we don't already have a last seen indicator
|
|
|
|
// we add a new one.
|
|
|
|
if (!this.view.atBottom() && !this.lastSeenIndicator) {
|
2017-06-01 18:54:57 +00:00
|
|
|
this.resetLastSeenIndicator({scroll: false});
|
2017-05-30 21:36:45 +00:00
|
|
|
}
|
2015-11-14 11:47:21 +00:00
|
|
|
}
|
2015-09-14 20:47:47 +00:00
|
|
|
},
|
2017-02-22 21:20:04 +00:00
|
|
|
updateMessage: function(message) {
|
|
|
|
this.model.messageCollection.add(message, {merge: true});
|
|
|
|
},
|
2015-02-23 21:17:50 +00:00
|
|
|
|
2015-03-11 19:06:19 +00:00
|
|
|
onClick: function(e) {
|
2017-07-11 22:24:54 +00:00
|
|
|
// If there are sub-panels open, we don't want to respond to clicks
|
|
|
|
if (!this.panels || !this.panels.length) {
|
|
|
|
this.closeMenu(e);
|
|
|
|
this.markRead();
|
|
|
|
}
|
2015-03-11 19:06:19 +00:00
|
|
|
},
|
|
|
|
|
2017-05-31 00:29:23 +00:00
|
|
|
findNewestVisibleUnread: function() {
|
|
|
|
var collection = this.model.messageCollection;
|
|
|
|
var length = collection.length;
|
|
|
|
var viewportBottom = this.view.outerHeight;
|
2017-07-05 19:17:55 +00:00
|
|
|
var unreadCount = this.model.get('unreadCount') || 0;
|
2017-05-31 00:29:23 +00:00
|
|
|
|
|
|
|
// Start with the most recent message, search backwards in time
|
|
|
|
var foundUnread = 0;
|
|
|
|
for (var i = length - 1; i >= 0; i -= 1) {
|
2017-07-05 19:17:55 +00:00
|
|
|
// Search the latest 30, then stop if we believe we've covered all known
|
|
|
|
// unread messages. The unread should be relatively recent.
|
|
|
|
// Why? local notifications can be unread but won't be reflected the
|
|
|
|
// conversation's unread count.
|
|
|
|
if (i > 30 && foundUnread >= unreadCount) {
|
2017-05-31 00:29:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var message = collection.at(i);
|
|
|
|
if (!message.get('unread')) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foundUnread += 1;
|
|
|
|
|
|
|
|
var el = this.$('#' + message.id);
|
|
|
|
var position = el.position();
|
|
|
|
var top = position.top;
|
|
|
|
|
|
|
|
// We're fully below the viewport, continue searching up.
|
|
|
|
if (top > viewportBottom) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the bottom fits on screen, we'll call it visible. Even if the
|
|
|
|
// message is really tall.
|
|
|
|
var height = el.height();
|
|
|
|
var bottom = top + height;
|
|
|
|
if (bottom <= viewportBottom) {
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue searching up.
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-06-07 16:51:59 +00:00
|
|
|
markRead: function() {
|
|
|
|
var unread;
|
|
|
|
|
|
|
|
if (this.view.atBottom()) {
|
|
|
|
unread = this.model.messageCollection.last();
|
|
|
|
} else {
|
|
|
|
unread = this.findNewestVisibleUnread();
|
|
|
|
}
|
|
|
|
|
2017-05-31 00:29:23 +00:00
|
|
|
if (unread) {
|
|
|
|
this.model.markRead(unread.get('received_at'));
|
|
|
|
}
|
2015-03-11 19:06:19 +00:00
|
|
|
},
|
|
|
|
|
2017-06-16 23:48:06 +00:00
|
|
|
showMembers: function(e, members, options) {
|
|
|
|
options = options || {};
|
|
|
|
_.defaults(options, {needVerify: false});
|
|
|
|
|
2017-06-14 00:36:32 +00:00
|
|
|
members = members || this.model.contactCollection;
|
|
|
|
|
|
|
|
var view = new Whisper.GroupMemberList({
|
|
|
|
model: members,
|
2017-06-14 17:38:33 +00:00
|
|
|
// we pass this in to allow nested panels
|
2017-06-16 23:48:06 +00:00
|
|
|
listenBack: this.listenBack.bind(this),
|
|
|
|
needVerify: options.needVerify
|
2017-06-14 00:36:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.listenBack(view);
|
|
|
|
},
|
|
|
|
|
|
|
|
showSafetyNumber: function(e, model) {
|
2016-09-18 06:55:05 +00:00
|
|
|
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,
|
2017-07-03 18:52:12 +00:00
|
|
|
conversation: this.model,
|
|
|
|
// we pass these in to allow nested panels
|
|
|
|
listenBack: this.listenBack.bind(this),
|
|
|
|
resetPanel: this.resetPanel.bind(this)
|
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
|
|
|
},
|
|
|
|
|
2017-07-26 21:55:59 +00:00
|
|
|
// not currently in use
|
|
|
|
newGroupUpdate: function() {
|
|
|
|
var view = new Whisper.NewGroupUpdateView({
|
|
|
|
model: this.model,
|
|
|
|
window: this.window
|
|
|
|
});
|
|
|
|
view.render();
|
|
|
|
this.listenBack(view);
|
|
|
|
},
|
|
|
|
|
2015-03-12 18:40:55 +00:00
|
|
|
listenBack: function(view) {
|
2017-06-10 19:18:24 +00:00
|
|
|
this.panels = this.panels || [];
|
2017-07-04 00:19:47 +00:00
|
|
|
if (this.panels.length > 0) {
|
|
|
|
this.panels[0].$el.hide();
|
|
|
|
}
|
2017-06-10 19:18:24 +00:00
|
|
|
this.panels.unshift(view);
|
|
|
|
|
|
|
|
if (this.panels.length === 1) {
|
|
|
|
this.$('.main.panel, .header-buttons.right').hide();
|
|
|
|
this.$('.back').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
view.$el.insertBefore(this.$('.panel').first());
|
2016-03-21 22:37:53 +00:00
|
|
|
},
|
|
|
|
resetPanel: function() {
|
2017-06-10 19:18:24 +00:00
|
|
|
var view = this.panels.shift();
|
2017-07-04 00:19:47 +00:00
|
|
|
if (this.panels.length > 0) {
|
|
|
|
this.panels[0].$el.show();
|
|
|
|
}
|
2017-06-10 19:18:24 +00:00
|
|
|
view.remove();
|
|
|
|
|
|
|
|
if (this.panels.length === 0) {
|
|
|
|
this.$('.main.panel, .header-buttons.right').show();
|
|
|
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
|
2017-06-14 00:36:32 +00:00
|
|
|
showSendConfirmationDialog: function(e, contacts) {
|
|
|
|
var message;
|
|
|
|
var isUnverified = this.model.isUnverified();
|
|
|
|
|
|
|
|
if (contacts.length > 1) {
|
|
|
|
if (isUnverified) {
|
|
|
|
message = i18n('changedSinceVerifiedMultiple');
|
|
|
|
} else {
|
|
|
|
message = i18n('changedRecentlyMultiple');
|
|
|
|
}
|
|
|
|
} else {
|
2017-06-23 17:37:51 +00:00
|
|
|
var contactName = contacts.at(0).getTitle();
|
2017-06-14 00:36:32 +00:00
|
|
|
if (isUnverified) {
|
2017-06-23 17:37:51 +00:00
|
|
|
message = i18n('changedSinceVerified', [contactName, contactName]);
|
2017-06-14 00:36:32 +00:00
|
|
|
} else {
|
2017-06-23 17:37:51 +00:00
|
|
|
message = i18n('changedRecently', [contactName, contactName]);
|
2017-06-14 00:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var dialog = new Whisper.ConfirmationDialogView({
|
|
|
|
message: message,
|
|
|
|
okText: i18n('sendAnyway'),
|
|
|
|
resolve: function() {
|
|
|
|
this.checkUnverifiedSendMessage(e, {force: true});
|
|
|
|
}.bind(this),
|
|
|
|
reject: function() {
|
2018-01-05 00:51:00 +00:00
|
|
|
this.focusMessageFieldAndClearDisabled();
|
2017-06-14 17:37:30 +00:00
|
|
|
}.bind(this)
|
2017-06-14 00:36:32 +00:00
|
|
|
});
|
2017-06-14 17:37:30 +00:00
|
|
|
|
2017-06-14 00:36:32 +00:00
|
|
|
this.$el.prepend(dialog.el);
|
2017-06-14 17:37:30 +00:00
|
|
|
dialog.focusCancel();
|
2017-06-14 00:36:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
checkUnverifiedSendMessage: function(e, options) {
|
2017-08-12 00:36:13 +00:00
|
|
|
e.preventDefault();
|
2017-08-16 20:53:50 +00:00
|
|
|
this.sendStart = Date.now();
|
2018-01-05 00:51:00 +00:00
|
|
|
this.$messageField.attr('disabled', true);
|
2017-08-12 00:36:13 +00:00
|
|
|
|
2017-06-14 00:36:32 +00:00
|
|
|
options = options || {};
|
|
|
|
_.defaults(options, {force: false});
|
|
|
|
|
2017-06-16 18:50:02 +00:00
|
|
|
// This will go to the trust store for the latest identity key information,
|
|
|
|
// and may result in the display of a new banner for this conversation.
|
|
|
|
this.model.updateVerified().then(function() {
|
|
|
|
var contacts = this.model.getUnverified();
|
|
|
|
if (!contacts.length) {
|
|
|
|
return this.checkUntrustedSendMessage(e, options);
|
|
|
|
}
|
2017-06-14 00:36:32 +00:00
|
|
|
|
2017-06-16 18:50:02 +00:00
|
|
|
if (options.force) {
|
|
|
|
return this.markAllAsVerifiedDefault(contacts).then(function() {
|
|
|
|
this.checkUnverifiedSendMessage(e, options);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
2017-06-14 00:36:32 +00:00
|
|
|
|
2017-06-16 18:50:02 +00:00
|
|
|
this.showSendConfirmationDialog(e, contacts);
|
2017-08-10 16:30:08 +00:00
|
|
|
}.bind(this)).catch(function(error) {
|
2018-01-05 00:51:00 +00:00
|
|
|
this.focusMessageFieldAndClearDisabled();
|
2017-08-10 16:30:08 +00:00
|
|
|
console.log(
|
|
|
|
'checkUnverifiedSendMessage error:',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
2017-08-12 00:36:13 +00:00
|
|
|
}.bind(this));
|
2017-06-14 00:36:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
checkUntrustedSendMessage: function(e, options) {
|
|
|
|
options = options || {};
|
|
|
|
_.defaults(options, {force: false});
|
|
|
|
|
|
|
|
this.model.getUntrusted().then(function(contacts) {
|
2017-07-03 18:52:12 +00:00
|
|
|
if (!contacts.length) {
|
2017-06-14 00:36:32 +00:00
|
|
|
return this.sendMessage(e);
|
|
|
|
}
|
|
|
|
|
2017-07-03 18:52:12 +00:00
|
|
|
if (options.force) {
|
|
|
|
return this.markAllAsApproved(contacts).then(function() {
|
|
|
|
this.sendMessage(e);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
|
2017-06-14 00:36:32 +00:00
|
|
|
this.showSendConfirmationDialog(e, contacts);
|
2017-08-10 16:30:08 +00:00
|
|
|
}.bind(this)).catch(function(error) {
|
2018-01-05 00:51:00 +00:00
|
|
|
this.focusMessageFieldAndClearDisabled();
|
2017-08-10 16:30:08 +00:00
|
|
|
console.log(
|
|
|
|
'checkUntrustedSendMessage error:',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
2017-08-12 00:36:13 +00:00
|
|
|
}.bind(this));
|
2017-06-14 00:36:32 +00:00
|
|
|
},
|
|
|
|
|
2017-10-30 20:54:55 +00:00
|
|
|
toggleEmojiPanel: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
if (!this.emojiPanel) {
|
|
|
|
this.openEmojiPanel();
|
|
|
|
} else {
|
|
|
|
this.closeEmojiPanel();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
openEmojiPanel: function(e) {
|
|
|
|
this.$emojiPanelContainer.outerHeight(200);
|
|
|
|
this.emojiPanel = new EmojiPanel(this.$emojiPanelContainer[0], {
|
|
|
|
onClick: this.insertEmoji.bind(this)
|
|
|
|
});
|
|
|
|
this.updateMessageFieldSize({});
|
|
|
|
},
|
|
|
|
closeEmojiPanel: function() {
|
|
|
|
this.$emojiPanelContainer.empty().outerHeight(0);
|
|
|
|
this.emojiPanel = null;
|
|
|
|
this.updateMessageFieldSize({});
|
|
|
|
},
|
|
|
|
insertEmoji: function(e) {
|
2017-12-04 18:19:35 +00:00
|
|
|
var colons = ':' + emojiData[e.index].short_name + ':';
|
2017-10-30 20:54:55 +00:00
|
|
|
|
|
|
|
var textarea = this.$messageField[0];
|
|
|
|
if (textarea.selectionStart || textarea.selectionStart == '0') {
|
|
|
|
var startPos = textarea.selectionStart;
|
|
|
|
var endPos = textarea.selectionEnd;
|
|
|
|
textarea.value = textarea.value.substring(0, startPos)
|
|
|
|
+ colons
|
|
|
|
+ textarea.value.substring(endPos, textarea.value.length);
|
|
|
|
textarea.selectionStart = startPos + colons.length;
|
|
|
|
textarea.selectionEnd = startPos + colons.length;
|
|
|
|
} else {
|
|
|
|
textarea.value += colons;
|
|
|
|
}
|
|
|
|
this.focusMessageField();
|
|
|
|
},
|
2014-11-16 21:19:51 +00:00
|
|
|
sendMessage: function(e) {
|
2017-05-17 21:32:03 +00:00
|
|
|
this.removeLastSeenIndicator();
|
2017-10-30 20:54:55 +00:00
|
|
|
this.closeEmojiPanel();
|
2017-05-17 21:32:03 +00:00
|
|
|
|
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
|
|
|
}
|
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();
|
2017-05-12 22:16:02 +00:00
|
|
|
}
|
|
|
|
if (!this.model.isPrivate() && this.model.get('left')) {
|
|
|
|
toast = new Whisper.LeftGroupToast();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toast) {
|
2016-09-07 00:12:45 +00:00
|
|
|
toast.$el.insertAfter(this.$el);
|
|
|
|
toast.render();
|
2018-01-05 00:51:00 +00:00
|
|
|
this.focusMessageFieldAndClearDisabled();
|
2016-09-07 00:12:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-12 00:36:13 +00:00
|
|
|
|
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();
|
2017-06-14 17:37:30 +00:00
|
|
|
|
2014-11-16 21:19:51 +00:00
|
|
|
if (message.length > 0 || this.fileInput.hasFiles()) {
|
|
|
|
this.fileInput.getFiles().then(function(attachments) {
|
2017-08-16 20:53:50 +00:00
|
|
|
var sendDelta = Date.now() - this.sendStart;
|
|
|
|
console.log('Send pre-checks took', sendDelta, 'milliseconds');
|
2017-08-12 00:36:13 +00:00
|
|
|
this.model.sendMessage(message, attachments);
|
|
|
|
input.val("");
|
2018-01-05 00:51:00 +00:00
|
|
|
this.focusMessageFieldAndClearDisabled();
|
2017-08-12 00:36:13 +00:00
|
|
|
this.forceUpdateMessageFieldSize(e);
|
|
|
|
this.fileInput.deleteFiles();
|
|
|
|
}.bind(this)).catch(function() {
|
|
|
|
console.log('Error pulling attached files before send');
|
2018-01-05 00:51:00 +00:00
|
|
|
this.focusMessageFieldAndClearDisabled();
|
2017-08-12 00:36:13 +00:00
|
|
|
}.bind(this));
|
2017-08-16 20:58:07 +00:00
|
|
|
} else {
|
2018-01-05 00:51:00 +00:00
|
|
|
this.focusMessageFieldAndClearDisabled();
|
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
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2017-09-11 16:50:35 +00:00
|
|
|
updateAvatar: function(model) {
|
|
|
|
var header = this.$('.conversation-header');
|
|
|
|
var avatarView = new (Whisper.View.extend({
|
|
|
|
templateName: 'avatar',
|
|
|
|
render_attributes: { avatar: this.model.getAvatar() }
|
|
|
|
}))();
|
|
|
|
header.find('.avatar').replaceWith(avatarView.render().$('.avatar'));
|
|
|
|
},
|
|
|
|
|
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();
|
2017-05-31 11:34:03 +00:00
|
|
|
this.toggleLengthWarning();
|
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() +
|
2017-10-30 20:54:55 +00:00
|
|
|
this.$emojiPanelContainer.outerHeight() +
|
2016-08-31 01:27:54 +00:00
|
|
|
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
|
|
|
})();
|