fix: 不在页面上的会话收到新消息

2.0/wai-server
Lei OT 10 months ago
parent 365343b71b
commit 70a3c83a6e

@ -285,7 +285,8 @@ const whatsappMsgMapped = {
'whatsapp.inbound_message.received': {
getMsg: (result) => {
// console.log('whatsapp.inbound_message.received', result);
return isEmpty(result?.whatsappInboundMessage) ? null : { ...result.whatsappInboundMessage, conversationid: result.conversationid, messageorigin: result.messageorigin, msg_source: 'WABA', msg_direction: 'inbound' };
const data1 = pick(result, ['conversationid', 'opi_sn', 'coli_sn', 'coli_id']);
return isEmpty(result?.whatsappInboundMessage) ? null : { ...result.whatsappInboundMessage, ...data1, messageorigin: result.messageorigin, msg_source: 'WABA', msg_direction: 'inbound' };
},
contentToRender: (contentObj) => {
// console.log('whatsapp.inbound_message.received to render', contentObj);
@ -445,7 +446,7 @@ export const whatsappMsgTypeMapped = {
text: {
type: 'text',
data: (msg) => ({ id: msg.wamid, text: autoLinkText(msg?.text?.body), originText: msg?.text?.body, title: msg?.customerProfile?.name || '', }), // msg?.from ||
renderForReply: (msg) => ({ id: msg.wamid, message: msg?.text?.body }),
renderForReply: (msg) => ({ id: msg.wamid, message: msg?.text?.body || msg?.text }),
},
image: {
type: 'photo',
@ -638,6 +639,7 @@ export const parseRenderMessageItem = (msg) => {
// console.log('parseRenderMessageItem', msg);
const thisMsgType = Object.keys(whatsappMsgTypeMapped).includes(msg.type) ? msg.type : 'unsupported';
return {
opi_sn: msg.opi_sn || '',
msgOrigin: msg,
date: msg?.sendTime || msg?.createTime || '',
...(whatsappMsgTypeMapped?.[thisMsgType]?.data(msg) || {}),

@ -420,6 +420,7 @@ const messageSlice = (set, get) => ({
},
sentOrReceivedNewMessage: (targetId, message) => {
// msgRender:
// console.log('sentOrReceivedNewMessage', targetId, message)
const { activeConversations, conversationsList, currentConversation, totalNotify, setFilter } = get();
const targetMsgs = activeConversations[String(targetId)] || [];
const targetIndex = conversationsList.findIndex((ele) => Number(ele.sn) === Number(targetId));
@ -438,8 +439,8 @@ const messageSlice = (set, get) => ({
: {
...conversationRow,
...message,
sn: targetId,
opi_sn: currentConversation.opi_sn, // todo: coli sn
sn: Number(targetId),
opi_sn: message.opi_sn || currentConversation.opi_sn, // todo: coli sn
last_received_time: dayjs(message.date).add(8, 'hours').format(DATETIME_FORMAT),
unread_msg_count: message.sender === 'me' ? 0 : 1,
whatsapp_name: message?.senderName || message?.sender || '',
@ -453,7 +454,10 @@ const messageSlice = (set, get) => ({
"whatsapp_phone_number": message.type === 'email' ? null : message.from,
},
};
if (String(targetId)!== '0') {
if (targetIndex === -1) {
conversationsList.unshift(newConversation);
} else {
// if (String(targetId)!== '0') {
conversationsList.splice(targetIndex, 1);
conversationsList.unshift(newConversation);
}

@ -136,8 +136,9 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
}, [contextMenuOpen])
const RenderLastMsg = (msg) => {
const readFromMsg = msg?.originText || msg?.text || '';
// const _text = isEmpty(msg) ? '' : msg.type === 'text' ? msg.text.body : `[${(msg?.type || '').toUpperCase()}]`;
const _text = isEmpty(msg) ? '' : (whatsappMsgTypeMapped?.[msg.type]?.renderForReply(msg) || {})?.message
const _text = isEmpty(msg) ? '' : ((whatsappMsgTypeMapped?.[msg.type]?.renderForReply(msg) || {})?.message || readFromMsg)
return (
<>{_text}</>
);

@ -89,7 +89,7 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
const loadNextPage = !(activeMessages.length === 0 || activeMessages.length < MESSAGE_PAGE_SIZE);
updateCurrentConversation({ lasttime: thisLastTime, loadNextPage, });
return () => {};
}, [activeMessages]);
}, [activeMessages, currentConversationSN]);
useEffect(() => {
if (updateRead === true && isVisible && currentConversation.opi_sn && activeMessages.length > 0) {
@ -98,7 +98,7 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
refreshTotalNotify();
}
return () => {};
}, [activeMessages.length, isVisible]);
}, [activeMessages.length, isVisible, currentConversationSN]);
let refreshing = false;
@ -108,6 +108,7 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
}
refreshing = true;
setMsgLoading(true);
setLongList([]);
const data = await fetchMessages({
conversationid: item.sn,
opisn: forceGetMessages ? item.opi_sn || '' : userId,

Loading…
Cancel
Save