diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js index 1860e34..557cccd 100644 --- a/src/lib/msgUtils.js +++ b/src/lib/msgUtils.js @@ -13,6 +13,13 @@ export const replaceTemplateString = (str, replacements) => { return result; } + +const autoLinkText = (text) => { + let regex = /(https?:\/\/[^\s]+)/g; + + let newText = text.replace(regex, '$1'); + return newText; +} /** * // +8618777396951 lyj @@ -31,12 +38,14 @@ export const sentMsgTypeMapped = { renderId: msg.id, to: msg.to, msgtype: 'text', - msgcontent: { body: msg.text, ...(msg.context ? { context: msg.context, message_origin: msg.message_origin.msgOrigin } : {}) }, + msgcontent: { body: msg.text, preview_url: true, ...(msg.context ? { context: msg.context, message_origin: msg.message_origin.msgOrigin } : {}) }, }), contentToRender: (msg) => ({ ...msg, actionId: msg.id, conversationid: msg.id.split('.')[0], + originText: (msg.text), + text: autoLinkText(msg.text), ...(msg.context ? { reply: { @@ -169,7 +178,7 @@ export const whatsappMsgTypeMapped = { }, text: { type: 'text', - data: (msg) => ({ id: msg.wamid, text: msg.text.body }), + data: (msg) => ({ id: msg.wamid, text: autoLinkText(msg.text.body), originText: msg.text.body }), renderForReply: (msg) => ({ id: msg.wamid, message: msg.text.body }), }, image: { @@ -313,12 +322,12 @@ export const parseRenderMessageList = (messages, conversationid = null) => { : { reply: { message: msg.messageorigin_AsJOSN.text?.body || msg.messageorigin_AsJOSN.text, - title: msg.messageorigin_AsJOSN?.customerProfile?.name || 'me', // msg.messageorigin_AsJOSN.senderName || '@', + title: msg.messageorigin_AsJOSN?.customerProfile?.name || msg.messageorigin_AsJOSN.senderName || 'me', ...(typeof whatsappMsgTypeMapped[msg.messageorigin_AsJOSN.type]?.renderForReply === 'function' ? whatsappMsgTypeMapped[msg.messageorigin_AsJOSN.type].renderForReply(msg.messageorigin_AsJOSN) : {}), - titleColor: msg.messageorigin_AsJOSN?.customerProfile?.name ? '#a791ff' : "#128c7e", - // titleColor: msg.messageorigin_direction === 'inbound' ? '#a791ff' : "#128c7e", + // titleColor: msg.messageorigin_AsJOSN?.customerProfile?.name ? '#a791ff' : "#128c7e", + titleColor: msg.messageorigin_direction === 'inbound' ? '#a791ff' : "#128c7e", }, origin: msg.messageorigin_AsJOSN, }), diff --git a/src/views/Conversations/Components/ConversationsList.jsx b/src/views/Conversations/Components/ConversationsList.jsx index a778263..15040e7 100644 --- a/src/views/Conversations/Components/ConversationsList.jsx +++ b/src/views/Conversations/Components/ConversationsList.jsx @@ -74,6 +74,7 @@ const Conversations = () => { return () => {}; }, [conversationsList, currentConversation]); + const [switchToC, setSwitchToC] = useState({}); const [shouldFetchCList, setShouldFetchCList] = useState(true); useEffect(() => { if (order_sn && shouldFetchCList && initialState) { @@ -116,12 +117,11 @@ const Conversations = () => { setCurrentConversation(item); }; - const [switchToC, setSwitchToC] = useState({}); const onSwitchConversation = (item) => { - if (item.coli_sn) { - navigate(`/order/chat/${item.coli_sn}`, { replace: true }); + if ( ! isEmpty(item.coli_sn)) { setSwitchToC(item); setShouldFetchCList(false); + navigate(`/order/chat/${item.coli_sn}`, { replace: true }); } else { navigate(`/order/chat`, { replace: true }); } diff --git a/src/views/Conversations/Components/InputComposer.jsx b/src/views/Conversations/Components/InputComposer.jsx index 35f73a7..d5af10c 100644 --- a/src/views/Conversations/Components/InputComposer.jsx +++ b/src/views/Conversations/Components/InputComposer.jsx @@ -72,7 +72,7 @@ const InputBox = () => { {referenceMsg.id && (
- {referenceMsg.senderName}{referenceMsg.text}
+ {referenceMsg.senderName}{referenceMsg.originText}