fix: send msg in mobile

This commit is contained in:
Tristan Yang
2023-05-25 11:10:52 +08:00
parent 319cbd9e42
commit 3e5d255d9e
2 changed files with 18 additions and 24 deletions
+16 -22
View File
@@ -48,25 +48,18 @@ const Send: FC<IProps> = ({
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const addLocalFileMessage = useAddLocalFileMessage({ context, to: id }); const addLocalFileMessage = useAddLocalFileMessage({ context, to: id });
// 谁发的 // 谁发的
const { const { from_uid, replying_mid, mode, uploadFiles, channelsData, usersData, uids } =
from_uid, useAppSelector((store) => {
replying_mid = null, return {
mode, channelsData: store.channels.byId,
uploadFiles, uids: store.users.ids,
channelsData, usersData: store.users.byId,
usersData, mode: store.ui.inputMode,
uids from_uid: store.authData.user?.uid,
} = useAppSelector((store) => { replying_mid: store.message.replying[`${context}_${id}`],
return { uploadFiles: store.ui.uploadFiles[`${context}_${id}`] ?? []
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 }); const { sendMessage } = useSendMessage({ context, from: from_uid, to: id });
useEffect(() => { useEffect(() => {
@@ -83,12 +76,13 @@ const Send: FC<IProps> = ({
editor.insertText(emoji); editor.insertText(emoji);
} }
}; };
const handleSendMessage = async () => { const handleSendMessage = async (messages?: any[]) => {
if (!id) return; if (!id) return;
const sendingMsgs = messages ?? msgs;
editor.resetInput(); editor.resetInput();
if (msgs && msgs.length) { if (sendingMsgs && sendingMsgs.length) {
// send text msgs // send text msgs
for await (const msg of msgs) { for await (const msg of sendingMsgs) {
const { type: content_type, content, properties = {} } = msg; const { type: content_type, content, properties = {} } = msg;
if ((content as string).trim() === "") continue; // 空消息不发送 if ((content as string).trim() === "") continue; // 空消息不发送
properties.local_id = properties.local_id ?? +new Date(); properties.local_id = properties.local_id ?? +new Date();
+2 -2
View File
@@ -20,8 +20,8 @@ const TextInput = ({ sendMessage, placeholder }: Props) => {
const handleSend = () => { const handleSend = () => {
if (!currMsg) return; if (!currMsg) return;
// todo // todo
const msg = [{ type: "text", content: currMsg }]; const msgs = [{ type: "text", content: currMsg }];
sendMessage(msg); sendMessage(msgs);
setCurrMsg(""); setCurrMsg("");
}; };