ConversationStack: Unset lastConversation on model unload

This commit is contained in:
Scott Nonnenberg 2019-10-17 10:35:35 -07:00 committed by Ken Powers
parent 86864279b2
commit 05439c6cd6
2 changed files with 10 additions and 8 deletions

View file

@ -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(

View file

@ -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();