Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(messagesStore) - clean conversation history for participants in call #10299

Merged
merged 1 commit into from Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/store/messagesStore.js
Expand Up @@ -395,6 +395,31 @@ const mutations = {
}
},

/**
* Clears the messages entry from the store for the given conversation token
* starting from defined id.
*
* @param {object} state current store state
* @param {object} payload payload;
* @param {string} payload.token the token of the conversation to be cleared;
* @param {number} payload.id the id of the message to be the first one after clear;
*/
clearMessagesHistory(state, { token, id }) {
Vue.set(state.firstKnown, token, id)

if (state.visualLastReadMessageId[token] && state.visualLastReadMessageId[token] < id) {
Vue.set(state.visualLastReadMessageId, token, id)
}

if (state.messages[token]) {
for (const messageId of Object.keys(state.messages[token])) {
if (messageId < id) {
Vue.delete(state.messages[token], messageId)
}
}
}
},

// Increases reaction count for a particular reaction on a message
addReactionToMessage(state, { token, messageId, reaction }) {
if (!state.messages[token][messageId].reactions[reaction]) {
Expand Down Expand Up @@ -515,6 +540,13 @@ const actions = {
})
}

if (message.systemMessage === 'history_cleared') {
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
context.commit('clearMessagesHistory', {
token: message.token,
id: message.id,
})
}

// Filter out some system messages
if (message.systemMessage !== 'reaction'
&& message.systemMessage !== 'reaction_deleted'
Expand Down Expand Up @@ -694,6 +726,18 @@ const actions = {
context.commit('deleteMessages', token)
},

/**
* Clear all messages before defined id from the store only.
*
* @param {object} context default store context;
* @param {object} payload payload;
* @param {string} payload.token the token of the conversation to be cleared;
* @param {number} payload.id the id of the message to be the first one after clear;
*/
clearMessagesHistory(context, { token, id }) {
context.commit('clearMessagesHistory', { token, id })
},

/**
* Clears the last read message marker by moving it to the last message
* in the conversation.
Expand Down