diff --git a/src/FilesSidebarTabApp.vue b/src/FilesSidebarTabApp.vue index 4e2d381b9db..ed2cdb2b054 100644 --- a/src/FilesSidebarTabApp.vue +++ b/src/FilesSidebarTabApp.vue @@ -216,7 +216,7 @@ export default { // Remove the conversation to ensure that the old data is not used // before fetching it again if this conversation is joined again. - this.$store.dispatch('deleteConversationByToken', this.token) + this.$store.dispatch('deleteConversation', this.token) // Remove the participant to ensure that it will be set again fresh // if this conversation is joined again. this.$store.dispatch('purgeParticipantsStore', this.token) diff --git a/src/PublicShareAuthSidebar.vue b/src/PublicShareAuthSidebar.vue index c773bd6a8a5..f51d0882cdd 100644 --- a/src/PublicShareAuthSidebar.vue +++ b/src/PublicShareAuthSidebar.vue @@ -179,7 +179,7 @@ export default { } catch (exception) { window.clearInterval(this.fetchCurrentConversationIntervalId) - this.$store.dispatch('deleteConversationByToken', this.token) + this.$store.dispatch('deleteConversation', this.token) this.$store.dispatch('updateToken', '') } }, diff --git a/src/PublicShareSidebar.vue b/src/PublicShareSidebar.vue index 2ac74f62d8c..0b8a99e3f04 100644 --- a/src/PublicShareSidebar.vue +++ b/src/PublicShareSidebar.vue @@ -215,7 +215,7 @@ export default { } catch (exception) { window.clearInterval(this.fetchCurrentConversationIntervalId) - this.$store.dispatch('deleteConversationByToken', this.token) + this.$store.dispatch('deleteConversation', this.token) this.$store.dispatch('updateToken', '') } diff --git a/src/components/LeftSidebar/ConversationsList/Conversation.vue b/src/components/LeftSidebar/ConversationsList/Conversation.vue index 71264994014..d671116460b 100644 --- a/src/components/LeftSidebar/ConversationsList/Conversation.vue +++ b/src/components/LeftSidebar/ConversationsList/Conversation.vue @@ -331,7 +331,7 @@ export default { try { await deleteConversation(this.item.token) // If successful, deletes the conversation from the store - this.$store.dispatch('deleteConversation', this.item) + this.$store.dispatch('deleteConversation', this.item.token) } catch (error) { console.debug(`error while deleting conversation ${error}`) } @@ -346,7 +346,7 @@ export default { try { await removeCurrentUserFromConversation(this.item.token) // If successful, deletes the conversation from the store - this.$store.dispatch('deleteConversation', this.item) + this.$store.dispatch('deleteConversation', this.item.token) } catch (error) { if (error.response && error.response.status === 400) { showError(t('spreed', 'You need to promote a new moderator before you can leave the conversation.')) diff --git a/src/store/conversationsStore.js b/src/store/conversationsStore.js index 8369787f6d2..3c0e07adfa2 100644 --- a/src/store/conversationsStore.js +++ b/src/store/conversationsStore.js @@ -146,22 +146,13 @@ const actions = { }, /** - * Delete a object - * - * @param {object} context default store context; - * @param {object} conversation the conversation to be deleted; - */ - deleteConversation(context, conversation) { - context.commit('deleteConversation', conversation.token) - }, - - /** - * Delete a object + * Delete a conversation from the store. * * @param {object} context default store context; * @param {object} token the token of the conversation to be deleted; */ - deleteConversationByToken(context, token) { + deleteConversation(context, token) { + context.dispatch('deleteMessages', token) context.commit('deleteConversation', token) }, diff --git a/src/store/messagesStore.js b/src/store/messagesStore.js index 5ce1f119cbb..16ca0f6264d 100644 --- a/src/store/messagesStore.js +++ b/src/store/messagesStore.js @@ -22,12 +22,18 @@ import Vue from 'vue' const state = { - messages: { - }, - firstKnown: { - }, - lastKnown: { - }, + /** + * Map of conversation token to message list + */ + messages: {}, + /** + * Map of conversation token to first known message id + */ + firstKnown: {}, + /** + * Map of conversation token to last known message id + */ + lastKnown: {}, } const getters = { @@ -146,6 +152,24 @@ const mutations = { setLastKnownMessageId(state, { token, id }) { Vue.set(state.lastKnown, token, id) }, + + /** + * Deletes the messages entry from the store for the given conversation token. + * + * @param {object} state current store state + * @param {string} token Token of the conversation + */ + deleteMessages(state, token) { + if (state.firstKnown[token]) { + Vue.delete(state.firstKnown, token) + } + if (state.lastKnown[token]) { + Vue.delete(state.lastKnown, token) + } + if (state.messages[token]) { + Vue.delete(state.messages, token) + } + }, } const actions = { @@ -216,6 +240,16 @@ const actions = { setLastKnownMessageId(context, { token, id }) { context.commit('setLastKnownMessageId', { token, id }) }, + + /** + * Deletes the messages of a conversation + * + * @param {object} context default store context; + * @param {object} token the token of the conversation to be deleted; + */ + deleteMessages(context, token) { + context.commit('deleteMessages', token) + }, } export default { state, mutations, getters, actions }