From f22e32ebcdf6ff213ac2d601d269f374d466e8db Mon Sep 17 00:00:00 2001 From: Lei OT Date: Fri, 13 Dec 2024 14:41:34 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=9A=E8=AF=9D=E7=BC=BA=E5=B0=91Wha?= =?UTF-8?q?tsApp=E5=8F=B7=E7=A0=81=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Online/Input/InputComposer.jsx | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/views/Conversations/Online/Input/InputComposer.jsx b/src/views/Conversations/Online/Input/InputComposer.jsx index 1bf75ba..f276de8 100644 --- a/src/views/Conversations/Online/Input/InputComposer.jsx +++ b/src/views/Conversations/Online/Input/InputComposer.jsx @@ -13,6 +13,7 @@ import { postUploadFileItem } from '@/actions/CommonActions'; import dayjs from 'dayjs'; import useStyleStore from '@/stores/StyleStore'; import ComposerTools from './ComposerTools'; +import { useOrderStore, OrderLabelDefaultOptions, OrderStatusDefaultOptions } from "@/stores/OrderStore"; const ButtonStyleClsMapped = { @@ -22,9 +23,11 @@ const ButtonStyleClsMapped = }; const InputComposer = ({ channel, currentActive }) => { + const { message: appMessage, notification: appNotification } = App.useApp(); const [mobile] = useStyleStore((state) => [state.mobile]); const {userId, whatsAppBusiness} = useAuthStore((state) => state.loginUser); + const [customerDetail] = useOrderStore((s) => [s.customerDetail]) const websocket = useConversationStore((state) => state.websocket); const websocketOpened = useConversationStore((state) => state.websocketOpened); @@ -55,6 +58,7 @@ const InputComposer = ({ channel, currentActive }) => { ? 'Enter 发送, Shift+Enter 换行' : 'Enter 换行'; + const [toIM, setToIM] = useState(''); const [fromIM, setFromIM] = useState(DEFAULT_WABA); useEffect(() => { switch (channel) { @@ -73,15 +77,25 @@ const InputComposer = ({ channel, currentActive }) => { return () => {} }, [channel, whatsAppBusiness]) + useEffect(() => { + const _to = currentConversation.whatsapp_phone_number || currentConversation.channel?.whatsapp_phone_number || currentConversation.channel?.phone_number // || customerDetail.whatsapp_phone_number + setToIM(_to); + + return () => {} + }, [currentConversation, customerDetail]) const textInputRef = useRef(null); const [textContent, setTextContent] = useState(''); const invokeSendMessage = (msgObj) => { + if (isEmpty(toIM)) { + appNotification.warning({ message: '缺少WhatsApp号码, 请先在会话列表右键菜单编辑联系人', placement: 'top' }); + return false + } const msgObjMerge = { sender: 'me', senderName: 'me', - to: currentConversation.whatsapp_phone_number, + to: toIM, from: fromIM, date: new Date(), status: 'waiting', @@ -110,7 +124,7 @@ const InputComposer = ({ channel, currentActive }) => { const msgObjMerge = { sender: 'me', senderName: 'me', - to: currentConversation.whatsapp_phone_number, + to: toIM, date: new Date(), status: 'waiting', ...(referenceMsg.id ? { context: { message_id: referenceMsg.id }, message_origin: referenceMsg } : {}), @@ -125,10 +139,14 @@ const InputComposer = ({ channel, currentActive }) => { }; const invokeSendUploadMessage = (msgObj) => { + if (isEmpty(toIM)) { + appNotification.warning({ message: '缺少WhatsApp号码, 请先在会话列表右键菜单编辑联系人', placement: 'top' }); + return false + } const msgObjMerge = { sender: 'me', senderName: 'me', - to: currentConversation.whatsapp_phone_number, + to: toIM, from: fromIM, date: new Date(), status: 'waiting', @@ -142,7 +160,6 @@ const InputComposer = ({ channel, currentActive }) => { websocket.sendMessage({ ...contentToSend, opi_sn: userId, coli_sn: currentConversation.coli_sn, conversationid: currentConversation.sn, }); }; - const { message: appMessage } = App.useApp(); const [pastedUploading, setPastedUploading] = useState(false); const readPasted = async (file) => { const fileTypeSupport = Object.keys(whatsappSupportFileTypes).find((msgType) => whatsappSupportFileTypes[msgType].types.includes(file.type)); @@ -260,6 +277,7 @@ const InputComposer = ({ channel, currentActive }) => { return (
{wabaWarning && } + {isEmpty(toIM) && } {referenceMsg.id && (