切换会话, conversationid

dev/chat
Lei OT 2 years ago
parent 404105fc40
commit 5f4c8863b5

@ -26,7 +26,7 @@ export const sentMsgTypeMapped = {
text: { text: {
type: 'text', type: 'text',
contentToSend: (msg) => ({ action: 'message', actionId: msg.id, renderId: msg.id, to: msg.to, msgtype: 'text', msgcontent: { body: msg.text } }), contentToSend: (msg) => ({ action: 'message', actionId: msg.id, renderId: msg.id, to: msg.to, msgtype: 'text', msgcontent: { body: msg.text } }),
contentToRender: (msg) => ({ ...msg, actionId: msg.id, }), contentToRender: (msg) => ({ ...msg, actionId: msg.id, conversationid: msg.id.split('.')[0], }),
}, },
whatsappTemplate: { whatsappTemplate: {
contentToSend: (msg) => ({ action: 'message', actionId: msg.id, renderId: msg.id, to: msg.to, msgtype: 'template', msgcontent: msg.template }), contentToSend: (msg) => ({ action: 'message', actionId: msg.id, renderId: msg.id, to: msg.to, msgtype: 'template', msgcontent: msg.template }),
@ -39,6 +39,7 @@ export const sentMsgTypeMapped = {
return { return {
...msg, ...msg,
actionId: msg.id, actionId: msg.id,
conversationid: msg.id.split('.')[0],
type: 'text', type: 'text',
title: msg.template_origin.components.header?.[0]?.text || '', title: msg.template_origin.components.header?.[0]?.text || '',
text: `${fillTemplate}`, // msg.template_origin.components.body?.[0]?.text || '', text: `${fillTemplate}`, // msg.template_origin.components.body?.[0]?.text || '',

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

Loading…
Cancel
Save