diff --git a/src/components/Navigation/ConversationsList/ConversationsList.vue b/src/components/Navigation/ConversationsList/ConversationsList.vue index 1e59ff775..3fce535e7 100644 --- a/src/components/Navigation/ConversationsList/ConversationsList.vue +++ b/src/components/Navigation/ConversationsList/ConversationsList.vue @@ -65,6 +65,7 @@ export default { * to the store. */ const conversations = await fetchConversations() + this.$store.dispatch('purgeConversationsStore') conversations.data.ocs.data.forEach(conversation => { this.$store.dispatch('addConversation', conversation) }) diff --git a/src/store/conversations.js b/src/store/conversations.js index aa00450eb..813cf6965 100644 --- a/src/store/conversations.js +++ b/src/store/conversations.js @@ -21,10 +21,15 @@ */ import Vue from 'vue' +const getDefaultState = () => { + return { + conversations: { + } + } +} + const state = { conversations: { - }, - conversationsNames: { } } @@ -43,18 +48,6 @@ const mutations = { addConversation(state, conversation) { Vue.set(state.conversations, conversation.token, conversation) }, - /** - * Creates a key-value pair with conversation id and name - * respectively. - * - * @param {object} state current state object; - * @param {object} object destructuring object; - * @param {string} object.token conversation token; - * @param {string} object.displayName conversation name; - */ - indexConversationName(state, { token, displayName }) { - Vue.set(state.conversationsNames, token, displayName) - }, /** * Deletes a conversation from the store. * @param {object} state current store state; @@ -62,7 +55,13 @@ const mutations = { */ deleteConversation(state, conversation) { Vue.delete(state.conversations, conversation.token) - Vue.delete(state.conversationsNames, conversation.token) + }, + /** + * Resets the store to it's original state + * @param {object} state current store state; + */ + purgeConversationsStore(state) { + Object.assign(state, getDefaultState()) } } @@ -75,7 +74,6 @@ const actions = { */ addConversation(context, conversation) { context.commit('addConversation', conversation) - context.commit('indexConversationName', conversation) }, /** @@ -86,6 +84,13 @@ const actions = { */ deleteConversation(context, conversation) { context.commit('deleteConversation', conversation) + }, + /** + * Resets the store to it's original state. + * @param {object} context default store context; + */ + purgeConversationsStore(context) { + context.commit('purgeConversationsStore') } }