Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -7,29 +7,29 @@ import React, {
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import {
|
||||
MatrixEvent,
|
||||
RelationType,
|
||||
Room,
|
||||
RoomEvent,
|
||||
ThreadEvent,
|
||||
} from 'matrix-js-sdk';
|
||||
import { MatrixEvent, RelationType, Room, RoomEvent, ThreadEvent } from 'matrix-js-sdk';
|
||||
import { useAtomValue, useSetAtom } from 'jotai';
|
||||
import { Badge, Box, IconButton, Line, Scroll, Text, Tooltip, TooltipProvider, config } from 'folds';
|
||||
import { Icon, Icons } from '../../components/icons';
|
||||
import {
|
||||
Badge,
|
||||
Box,
|
||||
IconButton,
|
||||
Line,
|
||||
Scroll,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipProvider,
|
||||
config,
|
||||
} from 'folds';
|
||||
import { HTMLReactParserOptions } from 'html-react-parser';
|
||||
import { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
import { ReactEditor } from 'slate-react';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { Icon, Icons } from '../../components/icons';
|
||||
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { useKeyDown } from '../../hooks/useKeyDown';
|
||||
import { editableActiveElement } from '../../utils/dom';
|
||||
import {
|
||||
useEditor,
|
||||
createMentionElement,
|
||||
moveCursor,
|
||||
} from '../../components/editor';
|
||||
import { editableActiveElement, autoScrollToBottom, scrollElementIntoView } from '../../utils/dom';
|
||||
import { useEditor, createMentionElement, moveCursor } from '../../components/editor';
|
||||
import { useSetting } from '../../state/hooks/settings';
|
||||
import { MessageLayout, settingsAtom } from '../../state/settings';
|
||||
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||
@@ -44,10 +44,7 @@ import { useOpenUserRoomProfile } from '../../state/hooks/userRoomProfile';
|
||||
import { useTheme } from '../../hooks/useTheme';
|
||||
import { useRoomCreatorsTag } from '../../hooks/useRoomCreatorsTag';
|
||||
import { usePowerLevelTags } from '../../hooks/usePowerLevelTags';
|
||||
import {
|
||||
useAccessiblePowerTagColors,
|
||||
useGetMemberPowerTag,
|
||||
} from '../../hooks/useMemberPowerTag';
|
||||
import { useAccessiblePowerTagColors, useGetMemberPowerTag } from '../../hooks/useMemberPowerTag';
|
||||
import {
|
||||
combineEmbedFilters,
|
||||
useRoomEmbedFilters,
|
||||
@@ -81,14 +78,9 @@ import {
|
||||
getReactionContent,
|
||||
reactionOrEditEvent,
|
||||
} from '../../utils/room';
|
||||
import {
|
||||
eventWithShortcode,
|
||||
factoryEventSentBy,
|
||||
getMxIdLocalPart,
|
||||
} from '../../utils/matrix';
|
||||
import { eventWithShortcode, factoryEventSentBy, getMxIdLocalPart } from '../../utils/matrix';
|
||||
import { GetContentCallback, MessageEvent } from '../../../types/matrix/room';
|
||||
import { inSameDay, minuteDifference, timeDayMonthYear, today, yesterday } from '../../utils/time';
|
||||
import { autoScrollToBottom, scrollElementIntoView } from '../../utils/dom';
|
||||
|
||||
type ThreadViewProps = {
|
||||
room: Room;
|
||||
@@ -140,7 +132,7 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
console.log('[ThreadView] Component mount/render', {
|
||||
roomId: room.roomId,
|
||||
threadRootId,
|
||||
allThreadsInRoom: room.getThreads().map(t => ({
|
||||
allThreadsInRoom: room.getThreads().map((t) => ({
|
||||
id: t.id,
|
||||
rootEventId: t.rootEvent?.getId(),
|
||||
length: t.length,
|
||||
@@ -158,8 +150,11 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock');
|
||||
const [dateFormatString] = useSetting(settingsAtom, 'dateFormatString');
|
||||
const [hideActivity] = useSetting(settingsAtom, 'hideActivity');
|
||||
const { bursts: emojiConfettiBursts, removeBurst: removeEmojiConfettiBurst, handleJumboEmojiClick } =
|
||||
useJumboEmojiConfetti(room);
|
||||
const {
|
||||
bursts: emojiConfettiBursts,
|
||||
removeBurst: removeEmojiConfettiBurst,
|
||||
handleJumboEmojiClick,
|
||||
} = useJumboEmojiConfetti(room);
|
||||
|
||||
const showUrlPreview = room.hasEncryptionStateEvent() ? encUrlPreview : urlPreview;
|
||||
const direct = useIsDirectRoom();
|
||||
@@ -173,7 +168,7 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
const accessiblePowerTagColors = useAccessiblePowerTagColors(
|
||||
theme.kind,
|
||||
creatorsTag,
|
||||
powerLevelTags
|
||||
powerLevelTags,
|
||||
);
|
||||
const permissions = useRoomPermissions(creators, powerLevels);
|
||||
const canRedact = permissions.action('redact', mx.getSafeUserId());
|
||||
@@ -191,7 +186,7 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
const roomWideEmbedFilters = useRoomWideEmbedFilters(room);
|
||||
const combinedEmbedFilters = useMemo(
|
||||
() => combineEmbedFilters(personalEmbedFilters, roomWideEmbedFilters),
|
||||
[personalEmbedFilters, roomWideEmbedFilters]
|
||||
[personalEmbedFilters, roomWideEmbedFilters],
|
||||
);
|
||||
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
@@ -201,10 +196,10 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
() => ({
|
||||
...LINKIFY_OPTS,
|
||||
render: factoryRenderLinkifyWithMention((href) =>
|
||||
renderMatrixMention(mx, room.roomId, href, makeMentionCustomProps(mentionClickHandler))
|
||||
renderMatrixMention(mx, room.roomId, href, makeMentionCustomProps(mentionClickHandler)),
|
||||
),
|
||||
}),
|
||||
[mx, room, mentionClickHandler]
|
||||
[mx, room, mentionClickHandler],
|
||||
);
|
||||
|
||||
const htmlReactParserOptions = useMemo<HTMLReactParserOptions>(
|
||||
@@ -215,7 +210,7 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
handleMentionClick: mentionClickHandler,
|
||||
}),
|
||||
[mx, room, linkifyOpts, spoilerClickHandler, mentionClickHandler, useAuthentication]
|
||||
[mx, room, linkifyOpts, spoilerClickHandler, mentionClickHandler, useAuthentication],
|
||||
);
|
||||
|
||||
const thread = room.getThread(threadRootId);
|
||||
@@ -233,7 +228,11 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
rootEventFound: !!rootEvent,
|
||||
rootEventType: rootEvent?.getType(),
|
||||
rootEventThreadRootId: rootEvent?.threadRootId,
|
||||
allEventIdsInTimeline: roomTimelineSet.getLiveTimeline().getEvents().slice(0, 20).map(e => e.getId()),
|
||||
allEventIdsInTimeline: roomTimelineSet
|
||||
.getLiveTimeline()
|
||||
.getEvents()
|
||||
.slice(0, 20)
|
||||
.map((e) => e.getId()),
|
||||
});
|
||||
}
|
||||
}, [thread, room, threadRootId, roomTimelineSet]);
|
||||
@@ -245,33 +244,33 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
console.log('[ThreadView] No thread found for ID:', threadRootId);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[ThreadView] Attempting to find replies manually from room timeline');
|
||||
|
||||
|
||||
// Fallback: search the room timeline for events that are replies to this thread
|
||||
const allEvents = roomTimelineSet.getLiveTimeline().getEvents();
|
||||
const threadReplies = allEvents.filter(event => {
|
||||
const threadReplies = allEvents.filter((event) => {
|
||||
const relations = event.getRelation();
|
||||
// Check if this event is a thread reply to our root event
|
||||
return relations?.rel_type === 'm.thread' && relations?.event_id === threadRootId;
|
||||
});
|
||||
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[ThreadView] Manual search found', {
|
||||
totalEventsInTimeline: allEvents.length,
|
||||
repliesFound: threadReplies.length,
|
||||
replies: threadReplies.map(e => ({
|
||||
replies: threadReplies.map((e) => ({
|
||||
id: e.getId(),
|
||||
sender: e.getSender(),
|
||||
body: e.getContent()?.body?.substring(0, 50),
|
||||
})),
|
||||
});
|
||||
|
||||
|
||||
return threadReplies;
|
||||
}
|
||||
|
||||
|
||||
// thread.events contains only replies, not the root event
|
||||
const replies = [...t.events];
|
||||
const liveTimelineEvents = t.liveTimeline?.getEvents() || [];
|
||||
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[ThreadView] getThreadEvents', {
|
||||
threadId: threadRootId,
|
||||
@@ -282,27 +281,27 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
initialEventsFetched: (t as any).initialEventsFetched,
|
||||
liveTimelineEventsCount: liveTimelineEvents.length,
|
||||
threadEventsMatch: replies.length === liveTimelineEvents.length,
|
||||
allRepliesFromThreadEvents: replies.map(e => ({
|
||||
id: e.getId(),
|
||||
type: e.getType(),
|
||||
allRepliesFromThreadEvents: replies.map((e) => ({
|
||||
id: e.getId(),
|
||||
type: e.getType(),
|
||||
sender: e.getSender(),
|
||||
content: e.getContent()?.body?.substring(0, 50),
|
||||
})),
|
||||
allEventsFromLiveTimeline: liveTimelineEvents.map(e => ({
|
||||
allEventsFromLiveTimeline: liveTimelineEvents.map((e) => ({
|
||||
id: e.getId(),
|
||||
type: e.getType(),
|
||||
sender: e.getSender(),
|
||||
content: e.getContent()?.body?.substring(0, 50),
|
||||
})),
|
||||
});
|
||||
|
||||
|
||||
// Try using liveTimeline events if thread.events is empty but liveTimeline has events
|
||||
if (replies.length === 0 && liveTimelineEvents.length > 0) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('[ThreadView] Using liveTimeline events instead of thread.events');
|
||||
return [...liveTimelineEvents];
|
||||
}
|
||||
|
||||
|
||||
return replies;
|
||||
}, [room, threadRootId, roomTimelineSet]);
|
||||
|
||||
@@ -332,8 +331,8 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
ReactEditor.focus(editor);
|
||||
}
|
||||
},
|
||||
[editor]
|
||||
)
|
||||
[editor],
|
||||
),
|
||||
);
|
||||
|
||||
// Subscribe to thread and room timeline events.
|
||||
@@ -364,7 +363,7 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
// Fires when initial events are loaded after the SDK paginates the thread.
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(thread as any).on(RoomEvent.TimelineReset, handleUpdate);
|
||||
|
||||
|
||||
// Also listen to Timeline events which fire when events are added
|
||||
thread.on(RoomEvent.Timeline, handleUpdate);
|
||||
}
|
||||
@@ -373,9 +372,10 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
if (eventRoom?.roomId !== room.roomId) return;
|
||||
// Check if this event is related to our thread (either it's a reply to it, or it IS the root event)
|
||||
const relations = mEvent.getRelation();
|
||||
const isThreadReply = relations?.rel_type === 'm.thread' && relations?.event_id === threadRootId;
|
||||
const isThreadReply =
|
||||
relations?.rel_type === 'm.thread' && relations?.event_id === threadRootId;
|
||||
const isRootEvent = mEvent.getId() === threadRootId;
|
||||
|
||||
|
||||
if (isThreadReply || isRootEvent) {
|
||||
handleUpdate();
|
||||
}
|
||||
@@ -418,10 +418,10 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
room.roomId,
|
||||
space?.roomId,
|
||||
userId,
|
||||
evt.currentTarget.getBoundingClientRect()
|
||||
evt.currentTarget.getBoundingClientRect(),
|
||||
);
|
||||
},
|
||||
[room, space, openUserRoomProfile]
|
||||
[room, space, openUserRoomProfile],
|
||||
);
|
||||
|
||||
const handleUsernameClick: MouseEventHandler<HTMLButtonElement> = useCallback(
|
||||
@@ -434,25 +434,23 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
createMentionElement(
|
||||
userId,
|
||||
name.startsWith('@') ? name : `@${name}`,
|
||||
userId === mx.getUserId()
|
||||
)
|
||||
userId === mx.getUserId(),
|
||||
),
|
||||
);
|
||||
ReactEditor.focus(editor);
|
||||
moveCursor(editor);
|
||||
},
|
||||
[mx, room, editor]
|
||||
[mx, room, editor],
|
||||
);
|
||||
|
||||
const handleReplyClick: MouseEventHandler<HTMLButtonElement> = useCallback(
|
||||
(evt) => {
|
||||
const replyId = evt.currentTarget.getAttribute('data-event-id');
|
||||
if (!replyId) return;
|
||||
const replyEvt =
|
||||
thread?.findEventById(replyId) ?? room.findEventById(replyId);
|
||||
const replyEvt = thread?.findEventById(replyId) ?? room.findEventById(replyId);
|
||||
if (!replyEvt) return;
|
||||
const editedReply = getEditedEvent(replyId, replyEvt, roomTimelineSet);
|
||||
const content =
|
||||
editedReply?.getContent()['m.new_content'] ?? replyEvt.getContent();
|
||||
const content = editedReply?.getContent()['m.new_content'] ?? replyEvt.getContent();
|
||||
const { body, formatted_body: formattedBody } = content;
|
||||
const senderId = replyEvt.getSender();
|
||||
if (senderId && typeof body === 'string') {
|
||||
@@ -466,14 +464,14 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
setTimeout(() => ReactEditor.focus(editor), 100);
|
||||
}
|
||||
},
|
||||
[room, thread, roomTimelineSet, threadRootId, setReplyDraft, editor]
|
||||
[room, thread, roomTimelineSet, threadRootId, setReplyDraft, editor],
|
||||
);
|
||||
|
||||
const handleOpenReply: MouseEventHandler = useCallback((evt) => {
|
||||
const targetId = evt.currentTarget.getAttribute('data-event-id');
|
||||
if (!targetId) return;
|
||||
const el = scrollRef.current?.querySelector(
|
||||
`[data-message-id="${targetId}"]`
|
||||
`[data-message-id="${targetId}"]`,
|
||||
) as HTMLElement | null;
|
||||
if (el) scrollElementIntoView(el, { behavior: 'smooth', block: 'center' });
|
||||
}, []);
|
||||
@@ -498,10 +496,10 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
room.roomId,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
MessageEvent.Reaction as any,
|
||||
getReactionContent(targetEventId, key, rShortcode)
|
||||
getReactionContent(targetEventId, key, rShortcode),
|
||||
);
|
||||
},
|
||||
[mx, room, roomTimelineSet]
|
||||
[mx, room, roomTimelineSet],
|
||||
);
|
||||
|
||||
/** Renders a single thread event into JSX. Returns null for non-message events. */
|
||||
@@ -514,17 +512,12 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
if (reactionOrEditEvent(mEvent)) return null;
|
||||
|
||||
const type = mEvent.getType();
|
||||
if (
|
||||
type !== MessageEvent.RoomMessage &&
|
||||
type !== MessageEvent.RoomMessageEncrypted
|
||||
) {
|
||||
if (type !== MessageEvent.RoomMessage && type !== MessageEvent.RoomMessageEncrypted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const prevEvent = index > 0 ? all[index - 1] : undefined;
|
||||
const dayDivider = prevEvent
|
||||
? !inSameDay(prevEvent.getTs(), mEvent.getTs())
|
||||
: false;
|
||||
const dayDivider = prevEvent ? !inSameDay(prevEvent.getTs(), mEvent.getTs()) : false;
|
||||
|
||||
const collapse =
|
||||
!dayDivider &&
|
||||
@@ -534,21 +527,17 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
minuteDifference(prevEvent.getTs(), mEvent.getTs()) < 2;
|
||||
|
||||
const reactionRelations = getEventReactions(roomTimelineSet, mEventId);
|
||||
const hasReactions =
|
||||
!!reactionRelations?.getSortedAnnotationsByKey()?.length;
|
||||
const hasReactions = !!reactionRelations?.getSortedAnnotationsByKey()?.length;
|
||||
|
||||
const { replyEventId, threadRootId: evtThreadRootId } = mEvent;
|
||||
|
||||
const editedEvent = getEditedEvent(mEventId, mEvent, roomTimelineSet);
|
||||
const getContent = (() =>
|
||||
editedEvent?.getContent()['m.new_content'] ??
|
||||
mEvent.getContent()) as GetContentCallback;
|
||||
editedEvent?.getContent()['m.new_content'] ?? mEvent.getContent()) as GetContentCallback;
|
||||
|
||||
const senderId = mEvent.getSender() ?? '';
|
||||
const senderDisplayName =
|
||||
getMemberDisplayName(room, senderId) ??
|
||||
getMxIdLocalPart(senderId) ??
|
||||
senderId;
|
||||
getMemberDisplayName(room, senderId) ?? getMxIdLocalPart(senderId) ?? senderId;
|
||||
|
||||
const dayDividerJSX = dayDivider ? (
|
||||
<Box
|
||||
@@ -677,15 +666,14 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
|
||||
const rootEvent = room.findEventById(threadRootId);
|
||||
const rootBody =
|
||||
getEditedEvent(threadRootId, rootEvent ?? new MatrixEvent(), roomTimelineSet)
|
||||
?.getContent()['m.new_content']?.body ??
|
||||
getEditedEvent(threadRootId, rootEvent ?? new MatrixEvent(), roomTimelineSet)?.getContent()[
|
||||
'm.new_content'
|
||||
]?.body ??
|
||||
rootEvent?.getContent()?.body ??
|
||||
'';
|
||||
const rootSenderId = rootEvent?.getSender() ?? '';
|
||||
const rootSenderName =
|
||||
getMemberDisplayName(room, rootSenderId) ??
|
||||
getMxIdLocalPart(rootSenderId) ??
|
||||
rootSenderId;
|
||||
getMemberDisplayName(room, rootSenderId) ?? getMxIdLocalPart(rootSenderId) ?? rootSenderId;
|
||||
// Use actual events count if thread doesn't exist but we found replies manually
|
||||
const replyCount = thread?.length ?? events.length;
|
||||
|
||||
@@ -750,19 +738,16 @@ export function ThreadView({ room, threadRootId }: ThreadViewProps) {
|
||||
>
|
||||
{/* Render the thread root event */}
|
||||
{rootEvent && renderEvent(rootEvent, -1, [])}
|
||||
|
||||
|
||||
{/* Show "no replies" message if no replies exist */}
|
||||
{events.length === 0 && (
|
||||
<Box
|
||||
justifyContent="Center"
|
||||
style={{ padding: config.space.S700 }}
|
||||
>
|
||||
<Box justifyContent="Center" style={{ padding: config.space.S700 }}>
|
||||
<Text size="T300" priority="300">
|
||||
No replies yet. Be the first!
|
||||
</Text>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
|
||||
{/* Render all reply events */}
|
||||
{events.map((evt, idx, arr) => renderEvent(evt, idx, arr))}
|
||||
</Box>
|
||||
|
||||
Reference in New Issue
Block a user