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

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

@ -285,7 +285,8 @@ const whatsappMsgMapped = {
'whatsapp.inbound_message.received': { 'whatsapp.inbound_message.received': {
getMsg: (result) => { getMsg: (result) => {
// console.log('whatsapp.inbound_message.received', 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) => { contentToRender: (contentObj) => {
// console.log('whatsapp.inbound_message.received to render', contentObj); // console.log('whatsapp.inbound_message.received to render', contentObj);
@ -445,7 +446,7 @@ export const whatsappMsgTypeMapped = {
text: { text: {
type: 'text', type: 'text',
data: (msg) => ({ id: msg.wamid, text: autoLinkText(msg?.text?.body), originText: msg?.text?.body, title: msg?.customerProfile?.name || '', }), // msg?.from || 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: { image: {
type: 'photo', type: 'photo',
@ -638,6 +639,7 @@ export const parseRenderMessageItem = (msg) => {
// console.log('parseRenderMessageItem', msg); // console.log('parseRenderMessageItem', msg);
const thisMsgType = Object.keys(whatsappMsgTypeMapped).includes(msg.type) ? msg.type : 'unsupported'; const thisMsgType = Object.keys(whatsappMsgTypeMapped).includes(msg.type) ? msg.type : 'unsupported';
return { return {
opi_sn: msg.opi_sn || '',
msgOrigin: msg, msgOrigin: msg,
date: msg?.sendTime || msg?.createTime || '', date: msg?.sendTime || msg?.createTime || '',
...(whatsappMsgTypeMapped?.[thisMsgType]?.data(msg) || {}), ...(whatsappMsgTypeMapped?.[thisMsgType]?.data(msg) || {}),

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

@ -136,8 +136,9 @@ const ChatListItem = (({item, refreshConversationList,setListUpdateFlag,onSwitch
}, [contextMenuOpen]) }, [contextMenuOpen])
const RenderLastMsg = (msg) => { 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) ? '' : 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 ( return (
<>{_text}</> <>{_text}</>
); );

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

Loading…
Cancel
Save