diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js
index c9710dc..563266c 100644
--- a/src/lib/msgUtils.js
+++ b/src/lib/msgUtils.js
@@ -79,7 +79,14 @@ const whatsappMsgMapped = {
// * 仅更新消息状态, 没有输出
return null;
},
- contentToUpdate: (msgcontent) => ({ ...msgcontent, id: msgcontent.wamid, status: msgStatusRenderMapped[(msgcontent?.status || 'failed')], dateString: msgcontent.status==='failed' ? '发送失败 ❌' : '', }),
+ contentToUpdate: (msgcontent) => ({
+ ...msgcontent,
+ ...parseRenderMessageItem(msgcontent),
+ id: msgcontent.wamid,
+ status: msgStatusRenderMapped[(msgcontent?.status || 'failed')],
+ sender: 'me',
+ dateString: msgcontent.status==='failed' ? '发送失败 ❌' : '',
+ }),
},
};
export const msgStatusRenderMapped = {
@@ -175,7 +182,7 @@ export const whatsappMsgTypeMapped = {
type: 'text',
data: (msg) => {
const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({...r, [v.type]: v}), {}) : null;
- return { id: msg.wamid, text: templateDataMapped?.body?.parameters?.[0]?.text || '', title: msg.template.name }
+ return { id: msg.wamid, text: templateDataMapped?.body?.text || templateDataMapped?.body?.parameters?.[0]?.text || '', title: msg.template.name }
},
},
};
@@ -202,6 +209,7 @@ export const parseRenderMessageItem = (msg) => {
export const parseRenderMessageList = (messages, conversationid = null) => {
return messages.map((msg) => {
const msgContent = msg.msgtext_AsJOSN;
+ msgContent.template = msg.msgtype === 'template' ? { ...msgContent.template, ...msg.template_AsJOSN } : {};
const msgType = msgContent.type;
// const parseMethod = msgContent.bizType === 'whatsapp' ? cloneDeep(whatsappMsgTypeMapped) : {};
return {
diff --git a/src/reducers/ConversationReducer.js b/src/reducers/ConversationReducer.js
index 5e12877..2125fc7 100644
--- a/src/reducers/ConversationReducer.js
+++ b/src/reducers/ConversationReducer.js
@@ -65,6 +65,11 @@ const ConversationReducer = (state = initialState, action) => {
}
return ele;
});
+ // 显示会话中其他客户端发送的消息
+ const targetMsgsIds = targetMsgs.map((ele) => ele.id);
+ if ( ! targetMsgsIds.includes(message.id)) {
+ targetMsgs.push(message);
+ }
// 更新列表的时间
const newConversationList = conversationsList.map((ele) => {
@@ -107,6 +112,10 @@ const ConversationReducer = (state = initialState, action) => {
...state,
activeConversations: { ...activeConversations, [String(targetId)]: [...targetMsgs, message] },
conversationsList: newConversationList,
+ currentConversation: {
+ ...state.currentConversation,
+ last_received_time: String(targetId) === String(currentConversation.sn) ? message.date : currentConversation.last_received_time,
+ },
};
}
case NAME_SPACE + 'ADD_ERROR': {
diff --git a/src/utils/utils.js b/src/utils/utils.js
index fd3c567..801f22b 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -116,6 +116,7 @@ export function omit(object, keysToOmit) {
* 深拷贝
*/
export function cloneDeep(value) {
+ // return structuredClone(value);
if (typeof value !== 'object' || value === null) {
return value;
}
diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx
index 87f361a..79744f4 100644
--- a/src/views/Conversations/Components/ConversationsList.jsx
+++ b/src/views/Conversations/Components/ConversationsList.jsx
@@ -90,18 +90,15 @@ const Conversations = () => {
}
};
const switchConversation = async (item) => {
- if (currentConversation.sn === item.sn) {
- return false;
- }
dispatch(setCurrentConversation(item));
- if (isEmpty(item.coli_sn) || item.coli_sn === '0') {
- dispatch(receivedCustomerProfile({}));
- }
const messagesList = activeConversations[`${item.sn}`] || [];
if (isEmpty(messagesList)) {
const data = await fetchMessages({ opisn: userId, whatsappid: item.whatsapp_phone_number });
dispatch(receivedMessageList(item.sn, data));
}
+ if (isEmpty(item.coli_sn) || item.coli_sn === '0') {
+ dispatch(receivedCustomerProfile({}));
+ }
};
const onSwitchConversation = (item) => {
diff --git a/src/views/Conversations/Components/InputComposer.jsx b/src/views/Conversations/Components/InputComposer.jsx
index 03623fa..4aa8f89 100644
--- a/src/views/Conversations/Components/InputComposer.jsx
+++ b/src/views/Conversations/Components/InputComposer.jsx
@@ -67,7 +67,7 @@ const InputBox = () => {
- } disabled={!talkabled}>
+ } disabled={!talkabled}>
Send
diff --git a/src/views/Conversations/Components/Messages.jsx b/src/views/Conversations/Components/Messages.jsx
index 8ce01ff..b363213 100644
--- a/src/views/Conversations/Components/Messages.jsx
+++ b/src/views/Conversations/Components/Messages.jsx
@@ -1,17 +1,18 @@
-import { useEffect, useState, useRef } from 'react';
+import { useEffect, useState, useRef, useMemo } from 'react';
import { Image, Alert } from 'antd';
import { MessageBox } from 'react-chat-elements';
import { useConversationState } from '@/stores/ConversationContext';
const Messages = () => {
const { activeConversations, currentConversation } = useConversationState();
- const messagesList = activeConversations[currentConversation.sn] || [];
+
+ const messagesList = useMemo(() => activeConversations[currentConversation.sn] || [], [activeConversations, currentConversation.sn]);
console.log('messagesList----------------------------------------------------', messagesList);
const messagesEndRef = useRef(null);
useEffect(() => {
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
- }, [messagesList.length]);
+ }, [messagesList, currentConversation.last_received_time]);
const [previewVisible, setPreviewVisible] = useState(false);
const [previewSrc, setPreviewSrc] = useState();
diff --git a/src/views/Conversations/Components/MessagesHeader.jsx b/src/views/Conversations/Components/MessagesHeader.jsx
index 0bd6462..f61f24b 100644
--- a/src/views/Conversations/Components/MessagesHeader.jsx
+++ b/src/views/Conversations/Components/MessagesHeader.jsx
@@ -9,7 +9,7 @@ const MessagesHeader = () => {
const { websocketOpened, websocketRetrying, websocketRetrytimes, currentConversation } = useConversationState();
return (
<>
- {!websocketOpened && }
+ {websocketOpened===false && }
{websocketRetrying && websocketRetrytimes > 0 && } />}
{currentConversation.customer_name && }