Mention the reply author in m.mentions

This commit is contained in:
nexy7574 2024-12-28 20:30:07 +00:00
parent 4063956d37
commit fee4065486

View file

@ -12,7 +12,7 @@ import { useAtom, useAtomValue } from 'jotai';
import { isKeyHotkey } from 'is-hotkey'; import { isKeyHotkey } from 'is-hotkey';
import { EventType, IContent, MsgType, RelationType, Room, IMentions } from 'matrix-js-sdk'; import { EventType, IContent, MsgType, RelationType, Room, IMentions } from 'matrix-js-sdk';
import { ReactEditor } from 'slate-react'; import { ReactEditor } from 'slate-react';
import {Transforms, Editor} from 'slate'; import {Transforms, Editor, Descendant} from 'slate';
import { import {
Box, Box,
Dialog, Dialog,
@ -106,8 +106,8 @@ import { ReplyLayout, ThreadIndicator } from '../../components/message';
import { roomToParentsAtom } from '../../state/room/roomToParents'; import { roomToParentsAtom } from '../../state/room/roomToParents';
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
import { import {
CustomElement, CustomElement, InlineElement,
MentionElement, MentionElement, ParagraphElement,
} from '../../components/editor/slate'; } from '../../components/editor/slate';
interface RoomInputProps { interface RoomInputProps {
@ -296,11 +296,15 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
body, body,
}; };
const userIdMentions = new Set<string>(); const userIdMentions = new Set<string>();
if (replyDraft) {
userIdMentions.add(replyDraft.userId);
}
let mentionsRoom = false; let mentionsRoom = false;
editor.children.forEach((node: CustomElement): void => { editor.children.forEach((node: Descendant): void => {
node.children?.forEach((child: MentionElement): void => { if(node.type !== "paragraph") return;
(node as ParagraphElement).children?.forEach((child: InlineElement): void => {
if (child.type === "mention") { if (child.type === "mention") {
if(child.name === "@room" && !child.id?.startsWith("@")) { if(child.name === "@room" && !child.id.startsWith("@")) {
mentionsRoom = true mentionsRoom = true
} else { } else {
userIdMentions.add(child.id) userIdMentions.add(child.id)