From 3e5d255d9e0a7a6faf6437345bb92ba60e6cd10a Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Thu, 25 May 2023 11:10:52 +0800 Subject: [PATCH] fix: send msg in mobile --- src/components/Send/index.tsx | 38 +++++++++++++----------------- src/components/TextInput/index.tsx | 4 ++-- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/components/Send/index.tsx b/src/components/Send/index.tsx index 8060bba5..8644852d 100644 --- a/src/components/Send/index.tsx +++ b/src/components/Send/index.tsx @@ -48,25 +48,18 @@ const Send: FC = ({ const dispatch = useAppDispatch(); const addLocalFileMessage = useAddLocalFileMessage({ context, to: id }); // 谁发的 - const { - from_uid, - replying_mid = null, - mode, - uploadFiles, - channelsData, - usersData, - uids - } = useAppSelector((store) => { - return { - channelsData: store.channels.byId, - uids: store.users.ids, - usersData: store.users.byId, - mode: store.ui.inputMode, - from_uid: store.authData.user?.uid, - replying_mid: store.message.replying[`${context}_${id}`], - uploadFiles: store.ui.uploadFiles[`${context}_${id}`] ?? [] - }; - }); + const { from_uid, replying_mid, mode, uploadFiles, channelsData, usersData, uids } = + useAppSelector((store) => { + return { + channelsData: store.channels.byId, + uids: store.users.ids, + usersData: store.users.byId, + mode: store.ui.inputMode, + from_uid: store.authData.user?.uid, + replying_mid: store.message.replying[`${context}_${id}`], + uploadFiles: store.ui.uploadFiles[`${context}_${id}`] ?? [] + }; + }); const { sendMessage } = useSendMessage({ context, from: from_uid, to: id }); useEffect(() => { @@ -83,12 +76,13 @@ const Send: FC = ({ editor.insertText(emoji); } }; - const handleSendMessage = async () => { + const handleSendMessage = async (messages?: any[]) => { if (!id) return; + const sendingMsgs = messages ?? msgs; editor.resetInput(); - if (msgs && msgs.length) { + if (sendingMsgs && sendingMsgs.length) { // send text msgs - for await (const msg of msgs) { + for await (const msg of sendingMsgs) { const { type: content_type, content, properties = {} } = msg; if ((content as string).trim() === "") continue; // 空消息不发送 properties.local_id = properties.local_id ?? +new Date(); diff --git a/src/components/TextInput/index.tsx b/src/components/TextInput/index.tsx index f54bb925..79e49d3f 100644 --- a/src/components/TextInput/index.tsx +++ b/src/components/TextInput/index.tsx @@ -20,8 +20,8 @@ const TextInput = ({ sendMessage, placeholder }: Props) => { const handleSend = () => { if (!currMsg) return; // todo - const msg = [{ type: "text", content: currMsg }]; - sendMessage(msg); + const msgs = [{ type: "text", content: currMsg }]; + sendMessage(msgs); setCurrMsg(""); };