初始化之后, 获取最近的消息

dev/chat
Lei OT 2 years ago
parent 403194c3a0
commit 07b7493a60

@ -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);
}
},
}))
);

@ -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) => {

Loading…
Cancel
Save