From ac237b9e319cd98ea2d9deaaf8dcef7d3a03b0a4 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Thu, 10 Aug 2017 15:56:47 -0700 Subject: [PATCH] AppView: Store initialLoadComplete value for late openInbox FREEBIE --- js/views/app_view.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/js/views/app_view.js b/js/views/app_view.js index b5f1ad5f5..7ef047d69 100644 --- a/js/views/app_view.js +++ b/js/views/app_view.js @@ -79,14 +79,27 @@ }, openInbox: function(options) { options = options || {}; - _.defaults(options, {initialLoadComplete: false}); + // The inbox can be created before the 'empty' event fires or afterwards. If + // before, it's straightforward: the onEmpty() handler below updates the + // view directly, and we're in good shape. If we create the inbox late, we + // need to be sure that the current value of initialLoadComplete is provided + // so its loading screen doesn't stick around forever. + + // Two primary techniques at play for this situation: + // - background.js has two openInbox() calls, and passes initalLoadComplete + // directly via the options parameter. + // - in other situations openInbox() will be called with no options. So this + // view keeps track of whether onEmpty() has ever been called with + // this.initialLoadComplete. An example of this: on a phone-pairing setup. + _.defaults(options, {initialLoadComplete: this.initialLoadComplete}); 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. + // We create the inbox immediately so we don't miss an update to + // this.initialLoadComplete between the start of this method and the + // creation of inboxView. this.inboxView = new Whisper.InboxView({ model: self, window: window, @@ -105,6 +118,8 @@ }, onEmpty: function() { var view = this.inboxView; + + this.initialLoadComplete = true; if (view) { view.onEmpty(); }