mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-12 18:20:28 +03:00
Remove fallback replies & implement intentional mentions (#2138)
* Remove reply fallbacks & add m.mentions (WIP) the typing on line 301 and 303 needs fixing but apart from that this is mint * Less jank typing * Mention the reply author in m.mentions * Improve typing * Fix typing in m.mentions finder * Correctly iterate through editor children, properly handle @room, ... ..., don't mention the reply author when the reply author is ourself, don't add own user IDs when mentioning intentionally * Formatting * Add intentional mentions to edited messages * refactor reusable code and fix todo * parse mentions from all nodes --------- Co-authored-by: Ajay Bura <32841439+ajbura@users.noreply.github.com>
This commit is contained in:
parent
dd4c1a94e6
commit
8d95758ed7
5 changed files with 83 additions and 28 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { Descendant, Text } from 'slate';
|
||||
|
||||
import { Descendant, Editor, Text } from 'slate';
|
||||
import { MatrixClient } from 'matrix-js-sdk';
|
||||
import { sanitizeText } from '../../utils/sanitize';
|
||||
import { BlockType } from './types';
|
||||
import { CustomElement } from './slate';
|
||||
|
|
@ -11,6 +11,7 @@ import {
|
|||
} from '../../plugins/markdown';
|
||||
import { findAndReplace } from '../../utils/findAndReplace';
|
||||
import { sanitizeForRegex } from '../../utils/regex';
|
||||
import { getCanonicalAliasOrRoomId, isUserId } from '../../utils/matrix';
|
||||
|
||||
export type OutputOptions = {
|
||||
allowTextFormatting?: boolean;
|
||||
|
|
@ -195,3 +196,36 @@ export const trimCommand = (cmdName: string, str: string) => {
|
|||
if (!match) return str;
|
||||
return str.slice(match[0].length);
|
||||
};
|
||||
|
||||
export type MentionsData = {
|
||||
room: boolean;
|
||||
users: Set<string>;
|
||||
};
|
||||
export const getMentions = (mx: MatrixClient, roomId: string, editor: Editor): MentionsData => {
|
||||
const mentionData: MentionsData = {
|
||||
room: false,
|
||||
users: new Set(),
|
||||
};
|
||||
|
||||
const parseMentions = (node: Descendant): void => {
|
||||
if (Text.isText(node)) return;
|
||||
if (node.type === BlockType.CodeBlock) return;
|
||||
|
||||
if (node.type === BlockType.Mention) {
|
||||
if (node.id === getCanonicalAliasOrRoomId(mx, roomId)) {
|
||||
mentionData.room = true;
|
||||
}
|
||||
if (isUserId(node.id) && node.id !== mx.getUserId()) {
|
||||
mentionData.users.add(node.id);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
node.children.forEach(parseMentions);
|
||||
};
|
||||
|
||||
editor.children.forEach(parseMentions);
|
||||
|
||||
return mentionData;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue