Skip to content

Commit

Permalink
Merge pull request #10299 from nextcloud/fix/10298/clear-history-for-…
Browse files Browse the repository at this point in the history
…all-participants

fix(messagesStore) - clean conversation history for participants in call
  • Loading branch information
Antreesy authored Aug 22, 2023
2 parents 177a672 + 4cc40e7 commit 394f1a1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
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') {
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

0 comments on commit 394f1a1

Please sign in to comment.