From fee40654868b73e4ff334d3c94fc97d64038119c Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sat, 28 Dec 2024 20:30:07 +0000 Subject: [PATCH] Mention the reply author in m.mentions --- src/app/features/room/RoomInput.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/features/room/RoomInput.tsx b/src/app/features/room/RoomInput.tsx index 7ffb3e1c..02aa8ced 100644 --- a/src/app/features/room/RoomInput.tsx +++ b/src/app/features/room/RoomInput.tsx @@ -12,7 +12,7 @@ import { useAtom, useAtomValue } from 'jotai'; import { isKeyHotkey } from 'is-hotkey'; import { EventType, IContent, MsgType, RelationType, Room, IMentions } from 'matrix-js-sdk'; import { ReactEditor } from 'slate-react'; -import {Transforms, Editor} from 'slate'; +import {Transforms, Editor, Descendant} from 'slate'; import { Box, Dialog, @@ -106,8 +106,8 @@ import { ReplyLayout, ThreadIndicator } from '../../components/message'; import { roomToParentsAtom } from '../../state/room/roomToParents'; import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { - CustomElement, - MentionElement, + CustomElement, InlineElement, + MentionElement, ParagraphElement, } from '../../components/editor/slate'; interface RoomInputProps { @@ -296,11 +296,15 @@ export const RoomInput = forwardRef( body, }; const userIdMentions = new Set(); + if (replyDraft) { + userIdMentions.add(replyDraft.userId); + } let mentionsRoom = false; - editor.children.forEach((node: CustomElement): void => { - node.children?.forEach((child: MentionElement): void => { + editor.children.forEach((node: Descendant): void => { + if(node.type !== "paragraph") return; + (node as ParagraphElement).children?.forEach((child: InlineElement): void => { if (child.type === "mention") { - if(child.name === "@room" && !child.id?.startsWith("@")) { + if(child.name === "@room" && !child.id.startsWith("@")) { mentionsRoom = true } else { userIdMentions.add(child.id)