211f5cdedd
* State structure * How to refactr action modules * feat: Add state and mutations for multiple conversation on widget * Adds actions to support multiple conversation * feat: Adds public API endpoints for widget * fixes lint errors * Refactors store * Update mutations to accommodate new changes in store * Refactors actions in messages * fixes broken tests
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
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,
|
|
};
|
|
},
|
|
};
|