diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 259996fae..ccce598cc 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -286,7 +286,7 @@ }, onArchive: () => { - this.unload('archive'); + this.model.trigger('unload', 'archive'); this.model.setArchived(true); }, onMoveToInbox: () => { @@ -2189,9 +2189,8 @@ try { await this.confirm(i18n('deleteConversationConfirmation')); try { - this.unload('delete messages'); + this.model.trigger('unload', 'delete messages'); await this.model.destroyMessages(); - Whisper.events.trigger('unloadConversation', this.model.id); this.model.updateLastMessage(); } catch (error) { window.log.error( diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index e39ec5875..93b3178e7 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -29,6 +29,9 @@ model: conversation, window: this.model.window, }); + this.listenTo(conversation, 'unload', () => + this.onUnload(conversation) + ); view.$el.appendTo(this.el); if (this.lastConversation) { @@ -36,6 +39,8 @@ 'unload', 'opened another conversation' ); + this.stopListening(this.lastConversation); + this.lastConversation = null; } this.lastConversation = conversation; @@ -47,8 +52,9 @@ // Make sure poppers are positioned properly window.dispatchEvent(new Event('resize')); }, - onUnload(conversationId) { - if (this.lastConversation.id === conversationId) { + onUnload(conversation) { + if (this.lastConversation === conversation) { + this.stopListening(this.lastConversation); this.lastConversation = null; } }, @@ -80,9 +86,6 @@ el: this.$('.conversation-stack'), model: { window: options.window }, }); - Whisper.events.on('unloadConversation', conversationId => { - this.conversation_stack.onUnload(conversationId); - }); if (!options.initialLoadComplete) { this.appLoadingScreen = new Whisper.AppLoadingScreen();