changed the TimeInput's reply rendering logic rely on the proper function instead of doing its own thing
This commit is contained in:
1 parent
e32df9be89
commit
684407a524
1 file changed
+3
-79
@@ -3,7 +3,6 @@ import {
|
||||
KeyboardEventHandler,
|
||||
MouseEvent,
|
||||
RefObject,
|
||||
ReactNode,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
@@ -44,13 +43,6 @@ import {
|
||||
toRem,
|
||||
} from 'folds';
|
||||
|
||||
import parse from 'html-react-parser';
|
||||
import {
|
||||
getReactCustomHtmlParser,
|
||||
LINKIFY_OPTS,
|
||||
scaleSystemEmoji,
|
||||
} from '$plugins/react-custom-html-parser';
|
||||
|
||||
import { useMatrixClient } from '$hooks/useMatrixClient';
|
||||
import {
|
||||
AutocompletePrefix,
|
||||
@@ -83,7 +75,6 @@ import {
|
||||
TUploadContent,
|
||||
encryptFile,
|
||||
getImageInfo,
|
||||
getMxIdLocalPart,
|
||||
mxcUrlToHttp,
|
||||
toggleReaction,
|
||||
} from '$utils/matrix';
|
||||
@@ -113,23 +104,16 @@ import { safeFile } from '$utils/mimeTypes';
|
||||
import { fulfilledPromiseSettledResult } from '$utils/common';
|
||||
import { useSetting } from '$state/hooks/settings';
|
||||
import { settingsAtom } from '$state/settings';
|
||||
import {
|
||||
getMemberDisplayName,
|
||||
getMentionContent,
|
||||
reactionOrEditEvent,
|
||||
trimReplyFromBody,
|
||||
trimReplyFromFormattedBody,
|
||||
} from '$utils/room';
|
||||
import { getMentionContent, reactionOrEditEvent } from '$utils/room';
|
||||
import { Command, SHRUG, TABLEFLIP, UNFLIP, useCommands } from '$hooks/useCommands';
|
||||
import { mobileOrTablet } from '$utils/user-agent';
|
||||
import { useElementSizeObserver } from '$hooks/useElementSizeObserver';
|
||||
import { ReplyLayout, ThreadIndicator } from '$components/message';
|
||||
import { Reply, ThreadIndicator } from '$components/message';
|
||||
import { roomToParentsAtom } from '$state/room/roomToParents';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import { useMediaAuthentication } from '$hooks/useMediaAuthentication';
|
||||
import { useImagePackRooms } from '$hooks/useImagePackRooms';
|
||||
import { useComposingCheck } from '$hooks/useComposingCheck';
|
||||
import { useSableCosmetics } from '$hooks/useSableCosmetics';
|
||||
import { createLogger } from '$utils/debug';
|
||||
import { createDebugLogger } from '$utils/debugLogger';
|
||||
import FocusTrap from 'focus-trap-react';
|
||||
@@ -275,12 +259,6 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
|
||||
const [msgDraft, setMsgDraft] = useAtom(roomIdToMsgDraftAtomFamily(draftKey));
|
||||
const [replyDraft, setReplyDraft] = useAtom(roomIdToReplyDraftAtomFamily(draftKey));
|
||||
const replyUserID = replyDraft?.userId;
|
||||
|
||||
const { color: replyUsernameColor, font: replyUsernameFont } = useSableCosmetics(
|
||||
replyUserID ?? '',
|
||||
room
|
||||
);
|
||||
|
||||
const [uploadBoard, setUploadBoard] = useState(true);
|
||||
const [selectedFiles, setSelectedFiles] = useAtom(roomIdToUploadItemsAtomFamily(draftKey));
|
||||
@@ -373,45 +351,6 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
);
|
||||
|
||||
const replyEvent = replyDraft ? room.findEventById(replyDraft.eventId) : undefined;
|
||||
const {
|
||||
body: replyBody,
|
||||
formatted_body: replyFormattedBody,
|
||||
format: replyFormat,
|
||||
} = replyEvent?.getContent() ?? {};
|
||||
|
||||
// Prefer the live event content; fall back to what was snapshotted in the
|
||||
// draft when the user hit Reply (the event may not be in SDK state if it
|
||||
// was redacted or evicted, but the draft always carries the original body).
|
||||
const htmlBody =
|
||||
replyFormat === 'org.matrix.custom.html' ? replyFormattedBody : replyDraft?.formattedBody;
|
||||
const plainBody = replyBody ?? replyDraft?.body;
|
||||
|
||||
let replyBodyJSX: ReactNode = replyDraft ? trimReplyFromBody(replyDraft.body) : null;
|
||||
|
||||
if (htmlBody) {
|
||||
/**
|
||||
* message with linebreaks, etc stripped
|
||||
*/
|
||||
const strippedHtml = trimReplyFromFormattedBody(htmlBody)
|
||||
.replaceAll(/<br\s*\/?>/gi, ' ')
|
||||
.replaceAll(/<\/p>\s*<p[^>]*>/gi, ' ')
|
||||
.replaceAll(/<\/?p[^>]*>/gi, '')
|
||||
.replaceAll(/(?:\r\n|\r|\n)/g, ' ')
|
||||
.trim();
|
||||
const parserOpts = getReactCustomHtmlParser(mx, roomId, {
|
||||
linkifyOpts: LINKIFY_OPTS,
|
||||
useAuthentication,
|
||||
nicknames,
|
||||
});
|
||||
replyBodyJSX = parse(strippedHtml, parserOpts);
|
||||
} else if (plainBody) {
|
||||
const strippedBody = trimReplyFromBody(plainBody).replaceAll(/(?:\r\n|\r|\n)/g, ' ');
|
||||
replyBodyJSX = scaleSystemEmoji(strippedBody);
|
||||
}
|
||||
|
||||
// Seed the reply draft with the thread relation whenever we're in thread
|
||||
// mode (e.g. on first render or when the thread root changes). We use the
|
||||
// current user's ID as userId so that the mention logic skips it.
|
||||
useEffect(() => {
|
||||
if (!threadRootId) return;
|
||||
setReplyDraft((prev) => {
|
||||
@@ -1260,22 +1199,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
{replyDraft.relation?.rel_type === RelationType.Thread && !threadRootId && (
|
||||
<ThreadIndicator />
|
||||
)}
|
||||
<ReplyLayout
|
||||
userColor={replyUsernameColor}
|
||||
username={
|
||||
<Text size="T300" truncate style={{ fontFamily: replyUsernameFont }}>
|
||||
<b>
|
||||
{getMemberDisplayName(room, replyDraft.userId, nicknames) ??
|
||||
getMxIdLocalPart(replyDraft.userId) ??
|
||||
replyDraft.userId}
|
||||
</b>
|
||||
</Text>
|
||||
}
|
||||
>
|
||||
<Text size="T300" truncate>
|
||||
{replyBodyJSX}
|
||||
</Text>
|
||||
</ReplyLayout>
|
||||
<Reply room={room} replyEventId={replyDraft.eventId} />
|
||||
</Box>
|
||||
<IconButton
|
||||
variant="SurfaceVariant"
|
||||
|
||||
Reference in new issue
Block a user