From 07b7493a60bb266301517b818eb750d384cefa55 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Mon, 4 Mar 2024 22:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B9=8B=E5=90=8E,?= =?UTF-8?q?=20=E8=8E=B7=E5=8F=96=E6=9C=80=E8=BF=91=E7=9A=84=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/ConversationStore.js | 11 ++++++++--- .../Conversations/Components/ConversationsList.jsx | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index 52e668d..0d87c92 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -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); + } }, })) ); diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index 8b23b8b..689fedf 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -59,6 +59,7 @@ const Conversations = () => { const getMessages = async (item) => { setMsgLoading(true); const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number }); + setMsgLoading(false); receivedMessageList(item.sn, data); }; const switchConversation = async (item) => {