Skip to content
Merged
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
44 changes: 44 additions & 0 deletions src/store/messagesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,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 @@ -486,6 +511,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 @@ -673,6 +705,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