2019-01-14 21:49:58 +00:00
|
|
|
/* global
|
|
|
|
ConversationController,
|
|
|
|
extension,
|
|
|
|
getInboxCollection,
|
|
|
|
i18n,
|
|
|
|
Whisper,
|
|
|
|
Signal
|
|
|
|
*/
|
2018-03-02 20:54:15 +00:00
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
2018-03-02 20:54:15 +00:00
|
|
|
'use strict';
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
Whisper.StickerPackInstallFailedToast = Whisper.ToastView.extend({
|
|
|
|
render_attributes() {
|
|
|
|
return { toastMessage: i18n('stickers--toast--InstallFailed') };
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
Whisper.ConversationStack = Whisper.View.extend({
|
|
|
|
className: 'conversation-stack',
|
2019-06-27 20:35:21 +00:00
|
|
|
lastConversation: null,
|
2019-05-31 22:42:01 +00:00
|
|
|
open(conversation, messageId) {
|
2018-03-02 20:54:15 +00:00
|
|
|
const id = `conversation-${conversation.cid}`;
|
2019-05-31 22:42:01 +00:00
|
|
|
if (id !== this.el.lastChild.id) {
|
|
|
|
const view = new Whisper.ConversationView({
|
|
|
|
model: conversation,
|
|
|
|
window: this.model.window,
|
|
|
|
});
|
|
|
|
view.$el.appendTo(this.el);
|
|
|
|
|
|
|
|
if (this.lastConversation) {
|
|
|
|
this.lastConversation.trigger(
|
|
|
|
'unload',
|
|
|
|
'opened another conversation'
|
|
|
|
);
|
2015-12-07 20:36:30 +00:00
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
|
|
|
|
this.lastConversation = conversation;
|
|
|
|
conversation.trigger('opened', messageId);
|
|
|
|
} else if (messageId) {
|
|
|
|
conversation.trigger('scroll-to-message', messageId);
|
2019-06-27 20:35:21 +00:00
|
|
|
}
|
2019-05-31 22:42:01 +00:00
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
// Make sure poppers are positioned properly
|
|
|
|
window.dispatchEvent(new Event('resize'));
|
2018-03-02 20:54:15 +00:00
|
|
|
},
|
|
|
|
});
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
Whisper.AppLoadingScreen = Whisper.View.extend({
|
|
|
|
templateName: 'app-loading-screen',
|
|
|
|
className: 'app-loading-screen',
|
|
|
|
updateProgress(count) {
|
|
|
|
if (count > 0) {
|
|
|
|
const message = i18n('loadingMessages', count.toString());
|
|
|
|
this.$('.message').text(message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render_attributes: {
|
|
|
|
message: i18n('loading'),
|
|
|
|
},
|
|
|
|
});
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
Whisper.InboxView = Whisper.View.extend({
|
|
|
|
templateName: 'two-column',
|
|
|
|
className: 'inbox index',
|
|
|
|
initialize(options = {}) {
|
|
|
|
this.ready = false;
|
|
|
|
this.render();
|
|
|
|
this.$el.attr('tabindex', '1');
|
2017-07-25 01:43:35 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
this.conversation_stack = new Whisper.ConversationStack({
|
|
|
|
el: this.$('.conversation-stack'),
|
|
|
|
model: { window: options.window },
|
|
|
|
});
|
2017-01-04 03:37:56 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
if (!options.initialLoadComplete) {
|
|
|
|
this.appLoadingScreen = new Whisper.AppLoadingScreen();
|
|
|
|
this.appLoadingScreen.render();
|
|
|
|
this.appLoadingScreen.$el.prependTo(this.el);
|
|
|
|
this.startConnectionListener();
|
2019-08-15 21:42:43 +00:00
|
|
|
} else {
|
|
|
|
this.setupLeftPane();
|
2018-03-02 20:54:15 +00:00
|
|
|
}
|
2015-10-15 19:10:03 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
const inboxCollection = getInboxCollection();
|
2015-10-15 19:10:03 +00:00
|
|
|
|
2018-07-18 03:25:55 +00:00
|
|
|
this.listenTo(inboxCollection, 'messageError', () => {
|
2018-07-09 21:29:13 +00:00
|
|
|
if (this.networkStatusView) {
|
2019-05-17 17:24:27 +00:00
|
|
|
this.networkStatusView.update();
|
2018-07-09 21:29:13 +00:00
|
|
|
}
|
2018-03-02 20:54:15 +00:00
|
|
|
});
|
2016-03-21 03:02:38 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
this.networkStatusView = new Whisper.NetworkStatusView();
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$el
|
|
|
|
.find('.network-status-container')
|
2018-03-02 20:54:15 +00:00
|
|
|
.append(this.networkStatusView.render().el);
|
2016-03-21 06:34:56 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
if (extension.expired()) {
|
|
|
|
const banner = new Whisper.ExpiredAlertBanner().render();
|
|
|
|
banner.$el.prependTo(this.$el);
|
|
|
|
this.$el.addClass('expired');
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2019-05-16 22:32:11 +00:00
|
|
|
Whisper.events.on('pack-install-failed', () => {
|
|
|
|
const toast = new Whisper.StickerPackInstallFailedToast();
|
|
|
|
toast.$el.appendTo(this.$el);
|
|
|
|
toast.render();
|
|
|
|
});
|
2018-03-02 20:54:15 +00:00
|
|
|
},
|
|
|
|
render_attributes: {
|
|
|
|
welcomeToSignal: i18n('welcomeToSignal'),
|
|
|
|
selectAContact: i18n('selectAContact'),
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
click: 'onClick',
|
2019-01-14 21:49:58 +00:00
|
|
|
},
|
|
|
|
setupLeftPane() {
|
2019-08-15 21:42:43 +00:00
|
|
|
if (this.leftPaneView) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
this.leftPaneView = new Whisper.ReactWrapperView({
|
|
|
|
className: 'left-pane-wrapper',
|
2019-05-31 22:42:01 +00:00
|
|
|
JSX: Signal.State.Roots.createLeftPane(window.reduxStore),
|
2019-01-14 21:49:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.$('.left-pane-placeholder').append(this.leftPaneView.el);
|
2018-03-02 20:54:15 +00:00
|
|
|
},
|
|
|
|
startConnectionListener() {
|
|
|
|
this.interval = setInterval(() => {
|
|
|
|
const status = window.getSocketStatus();
|
|
|
|
switch (status) {
|
|
|
|
case WebSocket.CONNECTING:
|
|
|
|
break;
|
|
|
|
case WebSocket.OPEN:
|
|
|
|
clearInterval(this.interval);
|
|
|
|
// if we've connected, we can wait for real empty event
|
|
|
|
this.interval = null;
|
|
|
|
break;
|
|
|
|
case WebSocket.CLOSING:
|
|
|
|
case WebSocket.CLOSED:
|
|
|
|
clearInterval(this.interval);
|
|
|
|
this.interval = null;
|
|
|
|
// if we failed to connect, we pretend we got an empty event
|
|
|
|
this.onEmpty();
|
|
|
|
break;
|
|
|
|
default:
|
2019-02-26 22:14:19 +00:00
|
|
|
// We also replicate empty here
|
|
|
|
this.onEmpty();
|
2018-03-02 20:54:15 +00:00
|
|
|
break;
|
2015-12-07 20:36:30 +00:00
|
|
|
}
|
2018-03-02 20:54:15 +00:00
|
|
|
}, 1000);
|
|
|
|
},
|
|
|
|
onEmpty() {
|
2019-08-15 21:42:43 +00:00
|
|
|
this.setupLeftPane();
|
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
const view = this.appLoadingScreen;
|
|
|
|
if (view) {
|
|
|
|
this.appLoadingScreen = null;
|
|
|
|
view.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onProgress(count) {
|
|
|
|
const view = this.appLoadingScreen;
|
|
|
|
if (view) {
|
|
|
|
view.updateProgress(count);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
focusConversation(e) {
|
|
|
|
if (e && this.$(e.target).closest('.placeholder').length) {
|
|
|
|
return;
|
|
|
|
}
|
2014-11-16 23:30:40 +00:00
|
|
|
|
2018-03-02 20:54:15 +00:00
|
|
|
this.$('#header, .gutter').addClass('inactive');
|
|
|
|
this.$('.conversation-stack').removeClass('inactive');
|
|
|
|
},
|
|
|
|
focusHeader() {
|
|
|
|
this.$('.conversation-stack').addClass('inactive');
|
|
|
|
this.$('#header, .gutter').removeClass('inactive');
|
|
|
|
this.$('.conversation:first .menu').trigger('close');
|
|
|
|
},
|
|
|
|
reloadBackgroundPage() {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
2019-01-14 21:49:58 +00:00
|
|
|
async openConversation(id, messageId) {
|
2019-03-12 00:20:16 +00:00
|
|
|
const conversation = await ConversationController.getOrCreateAndWait(
|
2019-01-14 21:49:58 +00:00
|
|
|
id,
|
|
|
|
'private'
|
|
|
|
);
|
|
|
|
|
2019-04-18 00:50:36 +00:00
|
|
|
const { openConversationExternal } = window.reduxActions.conversations;
|
|
|
|
if (openConversationExternal) {
|
|
|
|
openConversationExternal(id, messageId);
|
2018-03-02 20:54:15 +00:00
|
|
|
}
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2019-05-31 22:42:01 +00:00
|
|
|
this.conversation_stack.open(conversation, messageId);
|
2019-01-14 21:49:58 +00:00
|
|
|
this.focusConversation();
|
2018-03-02 20:54:15 +00:00
|
|
|
},
|
|
|
|
closeRecording(e) {
|
|
|
|
if (e && this.$(e.target).closest('.capture-audio').length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.$('.conversation:first .recorder').trigger('close');
|
|
|
|
},
|
|
|
|
onClick(e) {
|
|
|
|
this.closeRecording(e);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Whisper.ExpiredAlertBanner = Whisper.View.extend({
|
|
|
|
templateName: 'expired_alert',
|
|
|
|
className: 'expiredAlert clearfix',
|
|
|
|
render_attributes() {
|
|
|
|
return {
|
|
|
|
expiredWarning: i18n('expiredWarning'),
|
|
|
|
upgrade: i18n('upgrade'),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
})();
|