diff --git a/shared/index.tsx b/shared/index.tsx index 5f2250d6..767f5a66 100644 --- a/shared/index.tsx +++ b/shared/index.tsx @@ -129,7 +129,11 @@ export { addReaction, removeReaction, } from './model/message'; -export type { ChatMessageReaction, ChatMessage } from './model/message'; +export type { + ChatMessageReaction, + ChatMessage, + SendMessagePayloadMeta, +} from './model/message'; export type { PluginManifest } from './model/plugin'; export type { UserBaseInfo, UserLoginInfo } from './model/user'; export { diff --git a/shared/model/message.ts b/shared/model/message.ts index e958e9dc..81bb50a1 100644 --- a/shared/model/message.ts +++ b/shared/model/message.ts @@ -33,8 +33,12 @@ export interface SimpleMessagePayload { content: string; } +export interface SendMessagePayloadMeta { + mentions?: string[]; +} + export interface SendMessagePayload extends SimpleMessagePayload { - meta?: Record; + meta?: SendMessagePayloadMeta; } /** diff --git a/web/src/components/ChatBox/ChatInputBox/index.tsx b/web/src/components/ChatBox/ChatInputBox/index.tsx index c3860d39..0fc58d5d 100644 --- a/web/src/components/ChatBox/ChatInputBox/index.tsx +++ b/web/src/components/ChatBox/ChatInputBox/index.tsx @@ -6,18 +6,22 @@ import { ClipboardHelper } from './clipboard-helper'; import { ChatInputActionContext } from './context'; import { uploadMessageImage } from './utils'; import { ChatInputBoxInput } from './input'; +import type { SendMessagePayloadMeta } from 'tailchat-shared'; interface ChatInputBoxProps { - onSendMsg: (msg: string) => void; + onSendMsg: (msg: string, meta?: SendMessagePayloadMeta) => void; } export const ChatInputBox: React.FC = React.memo((props) => { const inputRef = useRef(null); const [message, setMessage] = useState(''); + const [mentions, setMentions] = useState([]); const handleSendMsg = useCallback(() => { - props.onSendMsg(message); + props.onSendMsg(message, { + mentions, + }); setMessage(''); inputRef.current?.focus(); - }, [message]); + }, [message, mentions]); const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { @@ -53,7 +57,10 @@ export const ChatInputBox: React.FC = React.memo((props) => { { + setMessage(message); + setMentions(mentions); + }} onKeyDown={handleKeyDown} onPaste={handlePaste} /> diff --git a/web/src/components/ChatBox/ChatInputBox/input.tsx b/web/src/components/ChatBox/ChatInputBox/input.tsx index 6e9f8ceb..b0d1e3f9 100644 --- a/web/src/components/ChatBox/ChatInputBox/input.tsx +++ b/web/src/components/ChatBox/ChatInputBox/input.tsx @@ -14,11 +14,11 @@ interface ChatInputBoxInputProps > { inputRef?: React.Ref; value: string; - onChange: (message: string) => void; + onChange: (message: string, mentions: string[]) => void; } export const ChatInputBoxInput: React.FC = React.memo( (props) => { - const mentions = useChatInputMentionsContext(); + const allMentions = useChatInputMentionsContext(); return ( = React.memo( placeholder={t('输入一些什么')} singleLine={true} value={props.value} - onChange={(e) => props.onChange(e.target.value)} + onChange={(e, newValue, _, mentions) => + props.onChange( + newValue, + mentions.map((m) => m.id) + ) + } onKeyDown={props.onKeyDown} onPaste={props.onPaste} allowSuggestionsAboveCursor={true} @@ -35,7 +40,7 @@ export const ChatInputBoxInput: React.FC = React.memo( > `@${display}`} appendSpaceOnAdd={true} renderSuggestion={(suggestion) => ( diff --git a/web/src/components/ChatBox/index.tsx b/web/src/components/ChatBox/index.tsx index 8cb880f1..5155ddda 100644 --- a/web/src/components/ChatBox/index.tsx +++ b/web/src/components/ChatBox/index.tsx @@ -55,11 +55,12 @@ const ChatBoxInner: React.FC = React.memo((props) => { { + onSendMsg={(msg, meta) => { handleSendMessage({ converseId: props.converseId, groupId: props.groupId, content: msg, + meta, }); }} />