|
|
|
@ -2,7 +2,7 @@ import { create } from 'zustand';
|
|
|
|
|
import { RealTimeAPI } from '@/lib/realTimeAPI';
|
|
|
|
|
import { olog, isEmpty } from '@/utils/utils';
|
|
|
|
|
import { receivedMsgTypeMapped, handleNotification } from '@/lib/msgUtils';
|
|
|
|
|
import { fetchConversationsList, fetchTemplates } from '@/actions/ConversationActions';
|
|
|
|
|
import { fetchConversationsList, fetchTemplates, fetchMessages } from '@/actions/ConversationActions';
|
|
|
|
|
import { devtools } from 'zustand/middleware';
|
|
|
|
|
import { WS_URL } from '@/config';
|
|
|
|
|
|
|
|
|
@ -189,7 +189,7 @@ const messageSlice = (set, get) => ({
|
|
|
|
|
setMsgLoading: (msgListLoading) => set({ msgListLoading }),
|
|
|
|
|
receivedMessageList: (conversationid, msgList) =>
|
|
|
|
|
set((state) => ({
|
|
|
|
|
msgListLoading: false,
|
|
|
|
|
// msgListLoading: false,
|
|
|
|
|
activeConversations: { ...state.activeConversations, [String(conversationid)]: msgList },
|
|
|
|
|
})),
|
|
|
|
|
updateMessageItem: (message) => {
|
|
|
|
@ -280,7 +280,7 @@ export const useConversationStore = create(
|
|
|
|
|
|
|
|
|
|
// side effects
|
|
|
|
|
fetchInitialData: async (userId) => {
|
|
|
|
|
const { addToConversationList, setTemplates, setInitial } = get();
|
|
|
|
|
const { addToConversationList, setTemplates, setInitial, receivedMessageList } = get();
|
|
|
|
|
|
|
|
|
|
const conversationsList = await fetchConversationsList({ opisn: userId });
|
|
|
|
|
addToConversationList(conversationsList);
|
|
|
|
@ -289,6 +289,11 @@ export const useConversationStore = create(
|
|
|
|
|
setTemplates(templates);
|
|
|
|
|
|
|
|
|
|
setInitial(true);
|
|
|
|
|
|
|
|
|
|
for (const chatItem of conversationsList) {
|
|
|
|
|
const msgData = await fetchMessages({ opisn: chatItem.opi_sn, whatsappid: chatItem.whatsapp_phone_number });
|
|
|
|
|
receivedMessageList(chatItem.sn, msgData);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|