From 601081c1b800333e10bcb1bf12a3fb298da75e19 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Fri, 1 Sep 2017 11:30:41 -0700 Subject: [PATCH] More refactoring to reduce global event dependencies All Whisper.events listeners are now defined and bound in background.js, and we no longer need global methods for opening the inbox and conversation views, as those are handled by AppView or internally by InboxView. // FREEBIE --- js/background.js | 15 ++++++++------- js/notifications.js | 9 ++++----- js/panel_controller.js | 8 -------- js/views/app_view.js | 1 - js/views/network_status_view.js | 6 ------ 5 files changed, 12 insertions(+), 27 deletions(-) diff --git a/js/background.js b/js/background.js index 0d5a92f1c..1579b8f67 100644 --- a/js/background.js +++ b/js/background.js @@ -87,13 +87,14 @@ appView.inboxView.networkStatusView.setSocketReconnectInterval(60000); }); - [ - 'openInbox', - 'openInstaller', - 'openConversation', - 'openStandalone' - ].forEach(function(eventName) { - appView.listenTo(Whisper.events, eventName, appView[eventName]); + Whisper.Notifications.on('click', function(conversation) { + if (conversation) { + appView.openConversation(conversation); + } else { + appView.openInbox({ + initialLoadComplete: initialLoadComplete + }); + } }); }); diff --git a/js/notifications.js b/js/notifications.js index 64919b3f4..f7f16943c 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -20,13 +20,12 @@ this.on('remove', this.onRemove); }, onclick: function() { + var conversation; var last = this.last(); - if (!last) { - openInbox(); - return; + if (last) { + conversation = ConversationController.get(last.get('conversationId')); } - var conversation = ConversationController.get(last.get('conversationId')); - openConversation(conversation); + this.trigger('click', conversation); this.clear(); }, update: function() { diff --git a/js/panel_controller.js b/js/panel_controller.js index 8eb8bcb2a..43525bed0 100644 --- a/js/panel_controller.js +++ b/js/panel_controller.js @@ -25,10 +25,6 @@ }; var inboxWindowId = 'inbox'; - window.openInbox = function(options) { - Whisper.events.trigger('openInbox', options); - }; - window.setUnreadCount = function(count) { if (count > 0) { window.setBadgeCount(count); @@ -39,8 +35,4 @@ } }; - window.openConversation = function(conversation) { - Whisper.events.trigger('openConversation', conversation); - }; - })(); diff --git a/js/views/app_view.js b/js/views/app_view.js index 7cb194748..05b2618b0 100644 --- a/js/views/app_view.js +++ b/js/views/app_view.js @@ -11,7 +11,6 @@ events: { 'click .openInstaller': 'openInstaller', 'click .openStandalone': 'openStandalone', - 'openInstaller': 'openInstaller', 'openInbox': 'openInbox', }, openView: function(view) { diff --git a/js/views/network_status_view.js b/js/views/network_status_view.js index 1b948e6f5..a66a23da9 100644 --- a/js/views/network_status_view.js +++ b/js/views/network_status_view.js @@ -25,12 +25,6 @@ this.model = new Backbone.Model(); this.listenTo(this.model, 'change', this.onChange); }, - events: { - 'click .openInstaller': 'openInstaller' - }, - openInstaller: function() { - this.$el.trigger('openInstaller'); - }, onReconnectTimer: function() { this.setSocketReconnectInterval(60000); },