Files
Signal-Desktop/js/views/app_view.js
Scott Nonnenberg f37af04818 AppView.createInbox() - set this.inboxView immediately to be ready
If the 'empty' event is fired between the updateInbox() call and the
new InboxView() call afterwards, then the loading screen will never go
away. We fix that by immediately creating the InboxView but only adding
it to the DOM when the backing data is ready.

FREEBIE
2017-09-14 16:53:53 -07:00

101 lines
3.2 KiB
JavaScript

(function () {
'use strict';
window.Whisper = window.Whisper || {};
Whisper.AppView = Backbone.View.extend({
initialize: function(options) {
this.inboxView = null;
this.installView = null;
},
events: {
'click .openInstaller': 'openInstaller',
'click .openStandalone': 'openStandalone',
'openInbox': 'openInbox',
},
openView: function(view) {
this.el.innerHTML = "";
this.el.append(view.el);
this.delegateEvents();
},
openDebugLog: function() {
this.closeDebugLog();
this.debugLogView = new Whisper.DebugLogView();
this.debugLogView.$el.appendTo(this.el);
},
closeDebugLog: function() {
if (this.debugLogView) {
this.debugLogView.remove();
this.debugLogView = null;
}
},
openInstaller: function() {
this.closeInstaller();
this.installView = new Whisper.InstallView();
if (Whisper.Registration.everDone()) {
this.installView.selectStep(3);
this.installView.hideDots();
}
this.openView(this.installView);
},
openStandalone: function() {
if (window.config.environment !== 'production') {
this.closeInstaller();
this.installView = new Whisper.StandaloneRegistrationView();
this.openView(this.installView);
}
},
closeInstaller: function() {
if (this.installView) {
this.installView.remove();
this.installView = null;
}
},
openInbox: function(options) {
options = options || {};
_.defaults(options, {initialLoadComplete: false});
console.log('open inbox');
this.closeInstaller();
if (!this.inboxView) {
// We create the inbox immediately to make sure we're ready to receive the
// empty event after getting down to zero messages in the queue.
this.inboxView = new Whisper.InboxView({
model: self,
window: window,
initialLoadComplete: options.initialLoadComplete
});
return ConversationController.loadPromise().then(function() {
this.openView(this.inboxView);
}.bind(this));
} else {
if (!$.contains(this.el, this.inboxView.el)) {
this.openView(this.inboxView);
}
window.focus(); // FIXME
return Promise.resolve();
}
},
onEmpty: function() {
var view = this.inboxView;
if (view) {
view.onEmpty();
}
},
onProgress: function(count) {
var view = this.inboxView;
if (view) {
view.onProgress(count);
}
},
openConversation: function(conversation) {
if (conversation) {
this.openInbox().then(function() {
this.inboxView.openConversation(null, conversation);
}.bind(this));
}
},
});
})();