Chatwoot/app/javascript/widget/store/modules/messageV2/mutations.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-09-16 06:52:05 +00:00
import Vue from 'vue';
export const mutations = {
addMessagesEntry($state, { messages = [] }) {
const allMessages = $state.messages;
const newMessages = messages.reduce(
(obj, message) => ({
...obj,
[message.id]: message,
}),
{}
);
const updatedMessages = { ...allMessages, ...newMessages };
Vue.set($state.messages, 'byId', updatedMessages);
},
updateMessageEntry($state, message) {
const messageId = message.id;
if (!messageId) return;
const messageById = $state.messages.byId[messageId];
if (!messageById) return;
if (messageId !== message.id) return;
Vue.set($state.messages.byId, messageId, { ...message });
},
removeMessageEntry($state, messageId) {
if (!messageId) return;
Vue.delete($state.messages.byId, messageId);
},
removeMessageId($state, messageId) {
if (!messageId) return;
$state.messages.allIds = $state.messages.allIds.filter(
id => id !== messageId
);
},
setMessageUIFlag($state, { messageId, uiFlags }) {
const flags = $state.messages.uiFlags.byId[messageId];
$state.messages.uiFlags.byId[messageId] = {
...flags,
...uiFlags,
};
},
};