refactor: 对发送的消息增加校验。不允许发送空信息

pull/13/head
moonrailgun 4 years ago
parent 3adbcca86f
commit 612f9a296a

@ -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",

@ -33,6 +33,7 @@
"k3c502edb": "邮箱不能为空",
"k3c7c48f8": "找不到邀请信息",
"k3e514bd0": "面板名不能为空",
"k3e7f3579": "无法发送空消息",
"k3f3597fc": "全员",
"k3fe97dcc": "系统设置",
"k41064134": "私信",

@ -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

@ -47,12 +47,12 @@ const ChatBoxInner: React.FC<ChatBoxProps> = React.memo((props) => {
<ChatInputBox
onSendMsg={(msg) => {
// 发送消息后滚动到底部
handleSendMessage({
converseId: props.converseId,
groupId: props.groupId,
content: msg,
}).then(() => {
// 发送消息后滚动到底部
chatMessageListRef.current?.scrollToBottom();
});
}}

Loading…
Cancel
Save