切换会话, conversationid

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

@ -26,7 +26,7 @@ export const sentMsgTypeMapped = {
text: {
type: '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: {
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 {
...msg,
actionId: msg.id,
conversationid: msg.id.split('.')[0],
type: 'text',
title: msg.template_origin.components.header?.[0]?.text || '',
text: `${fillTemplate}`, // msg.template_origin.components.body?.[0]?.text || '',

@ -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,

Loading…
Cancel
Save