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: () => { onArchive: () => {
this.unload('archive'); this.model.trigger('unload', 'archive');
this.model.setArchived(true); this.model.setArchived(true);
}, },
onMoveToInbox: () => { onMoveToInbox: () => {
@ -2189,9 +2189,8 @@
try { try {
await this.confirm(i18n('deleteConversationConfirmation')); await this.confirm(i18n('deleteConversationConfirmation'));
try { try {
this.unload('delete messages'); this.model.trigger('unload', 'delete messages');
await this.model.destroyMessages(); await this.model.destroyMessages();
Whisper.events.trigger('unloadConversation', this.model.id);
this.model.updateLastMessage(); this.model.updateLastMessage();
} catch (error) { } catch (error) {
window.log.error( window.log.error(

View file

@ -29,6 +29,9 @@
model: conversation, model: conversation,
window: this.model.window, window: this.model.window,
}); });
this.listenTo(conversation, 'unload', () =>
this.onUnload(conversation)
);
view.$el.appendTo(this.el); view.$el.appendTo(this.el);
if (this.lastConversation) { if (this.lastConversation) {
@ -36,6 +39,8 @@
'unload', 'unload',
'opened another conversation' 'opened another conversation'
); );
this.stopListening(this.lastConversation);
this.lastConversation = null;
} }
this.lastConversation = conversation; this.lastConversation = conversation;
@ -47,8 +52,9 @@
// Make sure poppers are positioned properly // Make sure poppers are positioned properly
window.dispatchEvent(new Event('resize')); window.dispatchEvent(new Event('resize'));
}, },
onUnload(conversationId) { onUnload(conversation) {
if (this.lastConversation.id === conversationId) { if (this.lastConversation === conversation) {
this.stopListening(this.lastConversation);
this.lastConversation = null; this.lastConversation = null;
} }
}, },
@ -80,9 +86,6 @@
el: this.$('.conversation-stack'), el: this.$('.conversation-stack'),
model: { window: options.window }, model: { window: options.window },
}); });
Whisper.events.on('unloadConversation', conversationId => {
this.conversation_stack.onUnload(conversationId);
});
if (!options.initialLoadComplete) { if (!options.initialLoadComplete) {
this.appLoadingScreen = new Whisper.AppLoadingScreen(); this.appLoadingScreen = new Whisper.AppLoadingScreen();