|
|
|
@ -27,7 +27,6 @@ const initialConversationState = {
|
|
|
|
|
|
|
|
|
|
// referenceMsg: {},
|
|
|
|
|
|
|
|
|
|
aliOSSToken: {},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const templatesSlice = (set) => ({
|
|
|
|
@ -287,11 +286,10 @@ export const useConversationStore = create(
|
|
|
|
|
// state actions
|
|
|
|
|
addError: (error) => set((state) => ({ errors: [...state.errors, error] })),
|
|
|
|
|
setInitial: (v) => set({ initialState: v }),
|
|
|
|
|
setAliOSSToken: (v) => set({ aliOSSToken: v }),
|
|
|
|
|
|
|
|
|
|
// side effects
|
|
|
|
|
fetchInitialData: async (userId) => {
|
|
|
|
|
const { addToConversationList, setTemplates, setInitial, receivedMessageList, setAliOSSToken } = get();
|
|
|
|
|
const { addToConversationList, setTemplates, setInitial, receivedMessageList } = get();
|
|
|
|
|
|
|
|
|
|
const conversationsList = await fetchConversationsList({ opisn: userId });
|
|
|
|
|
addToConversationList(conversationsList);
|
|
|
|
@ -301,12 +299,12 @@ export const useConversationStore = create(
|
|
|
|
|
|
|
|
|
|
setInitial(true);
|
|
|
|
|
|
|
|
|
|
const autoGetMsgs = conversationsList.length > 5 ? 5 : conversationsList.length;
|
|
|
|
|
for (let index = 0; index < autoGetMsgs; index++) {
|
|
|
|
|
const chatItem = conversationsList[index];
|
|
|
|
|
const msgData = await fetchMessages({ opisn: chatItem.opi_sn, whatsappid: chatItem.whatsapp_phone_number });
|
|
|
|
|
receivedMessageList(chatItem.sn, msgData);
|
|
|
|
|
}
|
|
|
|
|
// const autoGetMsgs = conversationsList.length > 5 ? 5 : conversationsList.length;
|
|
|
|
|
// for (let index = 0; index < autoGetMsgs; index++) {
|
|
|
|
|
// const chatItem = conversationsList[index];
|
|
|
|
|
// const msgData = await fetchMessages({ opisn: chatItem.opi_sn, whatsappid: chatItem.whatsapp_phone_number });
|
|
|
|
|
// receivedMessageList(chatItem.sn, msgData);
|
|
|
|
|
// }
|
|
|
|
|
// for (const chatItem of conversationsList) {
|
|
|
|
|
// }
|
|
|
|
|
},
|
|
|
|
|