Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/FilesSidebarTabApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/PublicShareAuthSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/PublicShareSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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', '')
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/LeftSidebar/ConversationsList/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand All @@ -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.'))
Expand Down
15 changes: 3 additions & 12 deletions src/store/conversationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},

Expand Down
46 changes: 40 additions & 6 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 }