From 612f9a296adb52ca5cf3a4a20364a84e02b25a8f Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 16 Oct 2021 20:12:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=AF=B9=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=9A=84=E6=B6=88=E6=81=AF=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E3=80=82=E4=B8=8D=E5=85=81=E8=AE=B8=E5=8F=91=E9=80=81=E7=A9=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/i18n/langs/en-US/translation.json | 1 + shared/i18n/langs/zh-CN/translation.json | 1 + shared/redux/hooks/useConverseMessage.ts | 9 ++++++++- web/src/components/ChatBox/index.tsx | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/shared/i18n/langs/en-US/translation.json b/shared/i18n/langs/en-US/translation.json index fb229480..e74e20d8 100644 --- a/shared/i18n/langs/en-US/translation.json +++ b/shared/i18n/langs/en-US/translation.json @@ -33,6 +33,7 @@ "k3c502edb": "E-mail can not be empty", "k3c7c48f8": "Invite not found", "k3e514bd0": "Panel name cannot be empty", + "k3e7f3579": "Cannot send empty message", "k3f3597fc": "All", "k3fe97dcc": "System settings", "k41064134": "DM", diff --git a/shared/i18n/langs/zh-CN/translation.json b/shared/i18n/langs/zh-CN/translation.json index 40bbb44f..104c2a86 100644 --- a/shared/i18n/langs/zh-CN/translation.json +++ b/shared/i18n/langs/zh-CN/translation.json @@ -33,6 +33,7 @@ "k3c502edb": "邮箱不能为空", "k3c7c48f8": "找不到邀请信息", "k3e514bd0": "面板名不能为空", + "k3e7f3579": "无法发送空消息", "k3f3597fc": "全员", "k3fe97dcc": "系统设置", "k41064134": "私信", diff --git a/shared/redux/hooks/useConverseMessage.ts b/shared/redux/hooks/useConverseMessage.ts index f4388749..aceb9e44 100644 --- a/shared/redux/hooks/useConverseMessage.ts +++ b/shared/redux/hooks/useConverseMessage.ts @@ -10,7 +10,7 @@ import { import { chatActions } from '../slices'; import { useAppDispatch, useAppSelector } from './useAppSelector'; import _isNil from 'lodash/isNil'; -import { useChatBoxContext } from '../..'; +import { t, useChatBoxContext } from '../..'; import { MessageHelper } from '../../utils/message-helper'; import { ChatConverseType } from '../../model/converse'; @@ -24,6 +24,13 @@ function useHandleSendMessage(context: ConverseContext) { */ const handleSendMessage = useCallback( async (payload: SendMessagePayload) => { + payload.content = payload.content.trim(); + // 输入合法性检测 + if (payload.content === '') { + showErrorToasts(t('无法发送空消息')); + return; + } + try { if (hasContext === true) { // 如果有上下文, 则组装payload diff --git a/web/src/components/ChatBox/index.tsx b/web/src/components/ChatBox/index.tsx index c1383bc0..1cbfdb74 100644 --- a/web/src/components/ChatBox/index.tsx +++ b/web/src/components/ChatBox/index.tsx @@ -47,12 +47,12 @@ const ChatBoxInner: React.FC = React.memo((props) => { { - // 发送消息后滚动到底部 handleSendMessage({ converseId: props.converseId, groupId: props.groupId, content: msg, }).then(() => { + // 发送消息后滚动到底部 chatMessageListRef.current?.scrollToBottom(); }); }}