diff --git a/src/actions/ConversationActions.js b/src/actions/ConversationActions.js index 9ae3144..2668d7b 100644 --- a/src/actions/ConversationActions.js +++ b/src/actions/ConversationActions.js @@ -24,11 +24,18 @@ export const fetchConversationsList = async (params) => { /** * - * @param {object} params { opisn, whatsappid, } + * @param {object} params { opisn, whatsappid, lasttime, pagesize } */ export const fetchMessages = async (params) => { - const { result } = await fetchJSON(`${API_HOST}/getcusmessages`, params); - return parseRenderMessageList(result || []); + const defaultParams = { + opisn: '', + whatsappid: '', + // lasttime: '', + lasttime: '2024-01-01T00:25:30', // test: + pagesize: 100, + }; + const { errcode, result } = await fetchJSON(`${API_HOST}/getcusmessages`, {...defaultParams, ...params}); + return errcode !== 0 ? [] : parseRenderMessageList(result || []); } export const fetchCustomerProfile = async (colisn) => { diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index c30e0a8..d780c9e 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -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) { // } }, diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index 8e05826..c7f4665 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -73,7 +73,7 @@ const Conversations = () => { }; const getMessages = async (item) => { setMsgLoading(true); - const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number }); + const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number, lasttime: '2024-01-01T00:25:30' }); setMsgLoading(false); receivedMessageList(item.sn, data); };