|
|
|
@ -72,7 +72,7 @@ export const useConversations = ({loginUser, realtimeAPI}) => {
|
|
|
|
|
// const _data = [];
|
|
|
|
|
const _data = testConversations;
|
|
|
|
|
const list = [..._data, ...data];
|
|
|
|
|
const dataMapped = list.reduce((r, v) => ({ ...r, [v.sn]: [] }), {});
|
|
|
|
|
const dataMapped = list.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {});
|
|
|
|
|
setConversationsList(list);
|
|
|
|
|
setActiveConversations({...dataMapped, ...activeConversations});
|
|
|
|
|
console.log(list, dataMapped);
|
|
|
|
@ -99,7 +99,7 @@ export const useConversations = ({loginUser, realtimeAPI}) => {
|
|
|
|
|
if (!isEmpty(data.conversation)) {
|
|
|
|
|
setConversationsList((pre) => [...data.conversations, ...pre]);
|
|
|
|
|
setCurrentConversation(data.conversation[0]);
|
|
|
|
|
const thisCMapped = data.conversation.reduce((r, v) => ({ ...r, [v.sn]: [] }), {});
|
|
|
|
|
const thisCMapped = data.conversation.reduce((r, v) => ({ ...r, [`${v.sn}`]: [] }), {});
|
|
|
|
|
setActiveConversations((pre) => ({ ...pre, ...thisCMapped }));
|
|
|
|
|
setMessages([]); // todo: 获取当前会话的历史消息
|
|
|
|
|
} else {
|
|
|
|
@ -111,7 +111,7 @@ export const useConversations = ({loginUser, realtimeAPI}) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const switchConversation = (cc) => {
|
|
|
|
|
setCurrentID(cc.sn);
|
|
|
|
|
setCurrentID(`${cc.sn}`);
|
|
|
|
|
setCurrentConversation({...cc, id: cc.sn, customer_name: cc.whatsapp_name});
|
|
|
|
|
// Get customer profile when switching conversation
|
|
|
|
|
// getCustomerProfile(??);
|
|
|
|
@ -183,7 +183,7 @@ export const useConversations = ({loginUser, realtimeAPI}) => {
|
|
|
|
|
return targetMsgs;
|
|
|
|
|
});
|
|
|
|
|
// 更新会话中的消息
|
|
|
|
|
const targetId = currentConversationRef.current.sn;
|
|
|
|
|
const targetId = message.conversationid; // currentConversationRef.current.sn;
|
|
|
|
|
setActiveConversations((prevList) => ({
|
|
|
|
|
...prevList,
|
|
|
|
|
[targetId]: targetMsgs,
|
|
|
|
|