mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-03-26 21:07:48 +01:00
Remove reply fallbacks & add m.mentions
(WIP) the typing on line 301 and 303 needs fixing but apart from that this is mint
This commit is contained in:
parent
35f0e400ad
commit
deba27c24d
1 changed files with 30 additions and 17 deletions
|
@ -10,9 +10,9 @@ import React, {
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { useAtom, useAtomValue } from 'jotai';
|
import { useAtom, useAtomValue } from 'jotai';
|
||||||
import { isKeyHotkey } from 'is-hotkey';
|
import { isKeyHotkey } from 'is-hotkey';
|
||||||
import { EventType, IContent, MsgType, RelationType, Room } 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,
|
||||||
|
@ -109,6 +109,7 @@ import { useElementSizeObserver } from '../../hooks/useElementSizeObserver';
|
||||||
import { ReplyLayout, ThreadIndicator } from '../../components/message';
|
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 {CustomElement, InlineElement, MentionElement, ParagraphElement} from '../../components/editor/slate';
|
||||||
|
|
||||||
interface RoomInputProps {
|
interface RoomInputProps {
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
|
@ -248,7 +249,6 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||||
uploadBoardHandlers.current?.handleSend();
|
uploadBoardHandlers.current?.handleSend();
|
||||||
|
|
||||||
const commandName = getBeginCommand(editor);
|
const commandName = getBeginCommand(editor);
|
||||||
|
|
||||||
let plainText = toPlainText(editor.children).trim();
|
let plainText = toPlainText(editor.children).trim();
|
||||||
let customHtml = trimCustomHtml(
|
let customHtml = trimCustomHtml(
|
||||||
toMatrixCustomHTML(editor.children, {
|
toMatrixCustomHTML(editor.children, {
|
||||||
|
@ -289,25 +289,38 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||||
|
|
||||||
if (plainText === '') return;
|
if (plainText === '') return;
|
||||||
|
|
||||||
let body = plainText;
|
const body = plainText;
|
||||||
let formattedBody = customHtml;
|
const formattedBody = customHtml;
|
||||||
if (replyDraft) {
|
|
||||||
body = parseReplyBody(replyDraft.userId, trimReplyFromBody(replyDraft.body)) + body;
|
|
||||||
formattedBody =
|
|
||||||
parseReplyFormattedBody(
|
|
||||||
roomId,
|
|
||||||
replyDraft.userId,
|
|
||||||
replyDraft.eventId,
|
|
||||||
replyDraft.formattedBody
|
|
||||||
? trimReplyFromFormattedBody(replyDraft.formattedBody)
|
|
||||||
: sanitizeText(replyDraft.body)
|
|
||||||
) + formattedBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
const content: IContent = {
|
const content: IContent = {
|
||||||
msgtype: msgType,
|
msgtype: msgType,
|
||||||
body,
|
body,
|
||||||
};
|
};
|
||||||
|
const userIdMentions = new Set<string>();
|
||||||
|
let mentionsRoom = false;
|
||||||
|
editor.children.forEach((node: any): void => {
|
||||||
|
if (node.type === "paragraph") {
|
||||||
|
node.children.forEach((child: any): void => {
|
||||||
|
if (child.type !== undefined && child.type === "mention") {
|
||||||
|
if(child.name === "@room" && !child.id.startswith("@")) {
|
||||||
|
// Room mention, not MXID
|
||||||
|
mentionsRoom = true
|
||||||
|
} else {
|
||||||
|
userIdMentions.add(child.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const mMentions: IMentions = {}
|
||||||
|
if (userIdMentions.size > 0) {
|
||||||
|
mMentions.user_ids = Array.from(userIdMentions)
|
||||||
|
}
|
||||||
|
if(mentionsRoom) {
|
||||||
|
mMentions.room = true
|
||||||
|
}
|
||||||
|
|
||||||
|
content["m.mentions"] = mMentions
|
||||||
if (replyDraft || !customHtmlEqualsPlainText(formattedBody, body)) {
|
if (replyDraft || !customHtmlEqualsPlainText(formattedBody, body)) {
|
||||||
content.format = 'org.matrix.custom.html';
|
content.format = 'org.matrix.custom.html';
|
||||||
content.formatted_body = formattedBody;
|
content.formatted_body = formattedBody;
|
||||||
|
|
Loading…
Reference in a new issue