diff --git a/.changeset/collapse-timeline-renderer-duplication.md b/.changeset/collapse-timeline-renderer-duplication.md
new file mode 100644
index 000000000..53b09f63e
--- /dev/null
+++ b/.changeset/collapse-timeline-renderer-duplication.md
@@ -0,0 +1,5 @@
+---
+default: patch
+---
+
+Collapse the duplicated preamble, reactions bar, and thread-chip blocks in the timeline event renderer into shared helpers.
diff --git a/src/app/hooks/timeline/__snapshots__/useTimelineEventRenderer.test.tsx.snap b/src/app/hooks/timeline/__snapshots__/useTimelineEventRenderer.test.tsx.snap
new file mode 100644
index 000000000..54ad40d06
--- /dev/null
+++ b/src/app/hooks/timeline/__snapshots__/useTimelineEventRenderer.test.tsx.snap
@@ -0,0 +1,29 @@
+// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
+
+exports[`useTimelineEventRenderer > 'm.call.member (GroupCallMemberPrefix)' > renders correctly 1`] = `"
bob sent m.call.member event
"`;
+
+exports[`useTimelineEventRenderer > 'm.poll.start (M_POLL_START)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.reaction (Reaction)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.room.avatar (RoomAvatar)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.room.encrypted (RoomMessageEncrypte…' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.room.member (RoomMember)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.room.message (RoomMessage)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.room.name (RoomName)' > renders correctly 1`] = `"bob Organisms.RoomCommon.changed_room_name
"`;
+
+exports[`useTimelineEventRenderer > 'm.room.pinned_events (RoomPinnedEvent…' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.room.redaction (RoomRedaction)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.room.topic (RoomTopic)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'm.sticker (Sticker)' > renders correctly 1`] = `""`;
+
+exports[`useTimelineEventRenderer > 'non-state event fallback (unknown eve…' > renders correctly 1`] = `"bob sent io.sable.unknown.event event
"`;
+
+exports[`useTimelineEventRenderer > 'state event fallback (unknown state e…' > renders correctly 1`] = `"bob sent io.sable.unknown.state state event
"`;
diff --git a/src/app/hooks/timeline/useTimelineEventRenderer.test.tsx b/src/app/hooks/timeline/useTimelineEventRenderer.test.tsx
new file mode 100644
index 000000000..ffa17bc15
--- /dev/null
+++ b/src/app/hooks/timeline/useTimelineEventRenderer.test.tsx
@@ -0,0 +1,677 @@
+// oxlint-disable typescript/no-explicit-any
+import type { MouseEventHandler } from 'react';
+import { render, renderHook } from '@testing-library/react';
+import { describe, expect, it, vi } from 'vitest';
+import type {
+ EventTimelineSet,
+ MatrixEvent,
+ PushProcessor,
+ Room,
+ MatrixClient,
+} from '$types/matrix-sdk';
+import { EventType } from '$types/matrix-sdk';
+import type { EventStatus } from '$types/matrix-sdk';
+import type { HTMLReactParserOptions } from 'html-react-parser';
+import type { Opts as LinkifyOpts } from 'linkifyjs';
+import { MessageLayout } from '$state/settings';
+import type { ResolvedHiddenEventSettings } from '$state/hooks/settings';
+import { useTimelineEventRenderer } from './useTimelineEventRenderer';
+import { M_POLL_START } from 'matrix-js-sdk';
+
+// Applied once: no dynamic rAF or ResizeObserver.
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+}));
+
+vi.mock('jotai', async (importActual) => {
+ const actual = (await importActual()) as object;
+ return {
+ ...actual,
+ useAtomValue: () => ({}),
+ useSetAtom: () => vi.fn<(...args: unknown[]) => void>(),
+ };
+});
+
+vi.mock('$hooks/useMatrixClient', () => ({
+ useMatrixClient: () =>
+ ({
+ getUserId: () => '@me:example.com',
+ getRoom: () => undefined,
+ mxcUrlToHttp: () => null,
+ }) as any,
+}));
+
+vi.mock('$hooks/useMediaAuthentication', () => ({
+ useMediaAuthentication: () => false,
+}));
+
+vi.mock('$hooks/useSableCosmetics', () => ({
+ useSableCosmetics: () => ({ color: undefined, font: undefined }),
+}));
+
+vi.mock('$hooks/useRoomMemberHydration', () => ({
+ useRoomMemberHydration: vi.fn<(room: unknown, userId: string) => void>(),
+}));
+
+vi.mock('$state/hooks/userRoomProfile', () => ({
+ useOpenUserRoomProfile: () =>
+ vi.fn<(roomId: string, spaceId: string | undefined, userId: string, rect?: DOMRect) => void>(),
+}));
+
+vi.mock('$hooks/useMemberPowerTag', () => ({
+ useGetMemberPowerTag: () => () => undefined,
+}));
+
+vi.mock('$hooks/useMemberEventParser', () => ({
+ useMemberEventParser: () => vi.fn<(mEvent: unknown) => unknown>(),
+}));
+
+vi.mock('$hooks/useRoomEvent', () => ({
+ useRoomEvent: () => undefined,
+}));
+
+vi.mock('$hooks/useMentionClickHandler', () => ({
+ useMentionClickHandler: () => undefined,
+}));
+
+vi.mock('$features/settings/useSettingsLinkBaseUrl', () => ({
+ useSettingsLinkBaseUrl: () => 'https://app.sable.moe',
+}));
+
+vi.mock('$hooks/useIgnoredUsers', () => ({
+ useIgnoredUsers: () => [],
+}));
+
+vi.mock('@tanstack/react-query', () => ({
+ useQueryClient: () => ({ invalidateQueries: vi.fn<() => Promise>() }),
+}));
+
+vi.mock('@sentry/react', () => ({
+ default: {},
+ startSpan: vi.fn<(opts: unknown, fn: () => unknown) => unknown>(),
+ addBreadcrumb: vi.fn<() => void>(),
+ captureMessage: vi.fn<(msg: string) => void>(),
+ metrics: { distribution: vi.fn<() => void>() },
+}));
+
+// Leaf components are stubbed so the snapshot reflects renderer branching only.
+
+vi.mock('$components/message', async (importActual) => {
+ const actual = (await importActual()) as Record;
+ return {
+ ...actual,
+ EventContent: ({ content, time, icon }: any) => (
+
+ {icon}
+ {time}
+ {content}
+
+ ),
+ ImageContent: ({ content }: any) => (
+
+ ),
+ InlineTextDiff: ({ oldBody, newBody }: any) => (
+
+
+
+
+ ),
+ MessageNotDecryptedContent: () => ,
+ MSticker: ({ content }: any) => (
+
+ ),
+ RedactedContent: ({ reason }: any) => (
+ {reason ?? 'Message deleted'}
+ ),
+ RedactedReactionContent: () => ,
+ Reply: ({ replyEventId }: any) => (
+
+ ),
+ ReactionKeyInline: ({ reactionKey }: any) => (
+
+ ),
+ Time: ({ ts, compact }: any) => (
+
+ ),
+ };
+});
+
+vi.mock('$components/media', async (importActual) => {
+ const actual = (await importActual()) as Record;
+ return {
+ ...actual,
+ Image: ({ src, alt }: any) =>
,
+ };
+});
+
+vi.mock('$components/image-viewer', async (importActual) => {
+ const actual = (await importActual()) as Record;
+ return {
+ ...actual,
+ ImageViewer: ({ src, alt }: any) => (
+
+ ),
+ };
+});
+
+vi.mock('$components/RenderMessageContent', () => ({
+ RenderMessageContent: ({ msgType, displayName }: any) => (
+
+ ),
+}));
+
+vi.mock('$components/ClientSideHoverFreeze', () => ({
+ ClientSideHoverFreeze: ({ children }: any) => (
+ {children}
+ ),
+}));
+
+vi.mock('$components/user-avatar', () => ({
+ UserAvatar: ({ userId }: any) => ,
+}));
+
+vi.mock('$components/unread-badge', () => ({
+ UnreadBadge: ({ highlight }: any) => (
+
+ ),
+ UnreadBadgeCenter: ({ highlight }: any) => (
+
+ ),
+}));
+
+vi.mock('$features/room/message', async (importActual) => {
+ const actual = (await importActual()) as Record;
+ return {
+ ...actual,
+ // Stub Message to pass through props as data-attrs for snapshot
+ Message: ({
+ senderId,
+ senderDisplayName,
+ notifyHighlight,
+ content,
+ reactions,
+ reply,
+ children,
+ collapse,
+ highlight,
+ isMarked,
+ edit,
+ sendStatus,
+ canDelete,
+ canSendReaction,
+ canPinEvent,
+ hideReadReceipts,
+ showDeveloperTools,
+ hour24Clock,
+ activeReplyId,
+ }: any) => (
+
+ {content}
+ {reply}
+ {reactions}
+ {children}
+
+ ),
+ EncryptedContent: () => ,
+ Reactions: ({ mEventId: targetId, canSendReaction: canReact }: any) => (
+
+ ),
+ };
+});
+
+vi.mock('$components/icons/phosphor', () => ({
+ Code: () => [Code],
+ Hash: () => [Hash],
+ menuIcon: () => [Menu],
+ PencilSimple: () => [Pencil],
+ Phone: () => [Phone],
+ PhoneDisconnect: () => [PhoneDisconnect],
+ PushPin: () => [PushPin],
+ PushPinSlash: () => [PushPinSlash],
+ Smiley: () => [Smiley],
+ timelineIcon: (Icon: any) => Icon,
+ Trash: () => [Trash],
+}));
+
+const ROOM_ID = '!room:example.com';
+const ALICE = '@alice:example.com';
+const BOB = '@bob:example.com';
+
+const hiddenEventsDefaults: ResolvedHiddenEventSettings = {
+ showHiddenEvents: true,
+ showTombstoneEvents: true,
+ hiddenEventEdits: true,
+ hiddenEventRedactionTimeline: true,
+ hiddenEventReactions: true,
+ hiddenEventReactionTombstone: true,
+ hiddenEventReactionRedactionTimeline: true,
+ hiddenEventOther: true,
+};
+
+const htmlReactParserOptions = {} as HTMLReactParserOptions;
+const linkifyOpts = {} as LinkifyOpts;
+
+type EventFactoryOptions = {
+ id: string;
+ type: string;
+ sender?: string;
+ content?: Record;
+ prevContent?: Record;
+ wireContent?: Record;
+ originalContent?: Record;
+ ts?: number;
+ redacted?: boolean;
+ redaction?: boolean;
+ encrypted?: boolean;
+ threadRootId?: string;
+ replyEventId?: string;
+ status?: (typeof EventStatus)[keyof typeof EventStatus]; // eslint-disable-line
+};
+
+function createEvent(opts: EventFactoryOptions): MatrixEvent {
+ const {
+ id,
+ type,
+ sender = BOB,
+ content = {},
+ prevContent = {},
+ wireContent = content,
+ originalContent = content,
+ ts = 1_700_000_000_000,
+ redacted = false,
+ redaction = false,
+ encrypted = false,
+ threadRootId,
+ replyEventId,
+ status,
+ } = opts;
+ return {
+ getId: () => id,
+ getType: () => type,
+ getSender: () => sender,
+ getContent: () => content,
+ getPrevContent: () => prevContent,
+ getWireContent: () => wireContent,
+ getOriginalContent: () => originalContent,
+ getTs: () => ts,
+ isRedacted: () => redacted,
+ isRedaction: () => redaction,
+ isEncrypted: () => encrypted,
+ getUnsigned: () =>
+ ({
+ redacted_because: redacted ? { content: { reason: undefined } } : undefined,
+ }) as any,
+ getAssociatedStatus: () => status ?? null,
+ threadRootId,
+ replyEventId,
+ getRelation: () => null,
+ getServerAggregatedRelation: () => null,
+ getReplacedBy: () => null,
+ getVisibility: () => null,
+ getStatus: () => null,
+ getThread: () => threadRootId ?? null,
+ getReplyEventId: () => replyEventId ?? null,
+ } as unknown as MatrixEvent;
+}
+
+function createTimelineSet(): EventTimelineSet {
+ return {
+ relations: {
+ getChildEventsForEvent: () => null,
+ },
+ findEventById: () => null,
+ getTimelineForEvent: () => null,
+ getLiveTimeline: () => ({
+ getEvents: () => [],
+ }),
+ } as unknown as EventTimelineSet;
+}
+
+const timelineSet = createTimelineSet();
+
+function createRoom(): Room {
+ return {
+ roomId: ROOM_ID,
+ getMember: () => null,
+ getThread: () => null,
+ getThreadUnreadNotificationCount: () => 0,
+ findEventById: () => null,
+ getUnfilteredTimelineSet: () => createTimelineSet() as any,
+ getEventReadUpTo: () => null,
+ getLiveTimeline: () => ({ getEvents: () => [] }),
+ getUnreadNotificationCount: () => 0,
+ getMyMembership: () => 'join',
+ hasEncryptionStateEvent: () => false,
+ client: { getUserId: () => ALICE },
+ on: vi.fn<(event: string, listener: (...args: unknown[]) => void) => void>(),
+ off: vi.fn<(event: string, listener: (...args: unknown[]) => void) => void>(),
+ removeListener: vi.fn<(event: string, listener: (...args: unknown[]) => void) => void>(),
+ } as unknown as Room;
+}
+
+const room = createRoom();
+
+const mx = {
+ getUserId: () => ALICE,
+ getRoom: () => undefined,
+ mxcUrlToHttp: () => null,
+} as unknown as MatrixClient;
+
+const pushProcessor: PushProcessor = {
+ actionsForEvent: () => null,
+} as unknown as PushProcessor;
+
+const rendererOpts = {
+ room,
+ mx,
+ pushProcessor,
+ nicknames: {} as Record,
+ getProfile: () => undefined,
+ imagePackRooms: [] as Room[],
+ settings: {
+ messageLayout: MessageLayout.Modern,
+ messageSpacing: 0 as any,
+ hideReads: false,
+ showDeveloperTools: false,
+ hour24Clock: false,
+ dateFormatString: 'MMM dd, yyyy',
+ mediaAutoLoad: false,
+ showUrlPreview: false,
+ showBundledPreview: false,
+ showClientUrlPreview: false,
+ showMaps: false,
+ autoplayStickers: false,
+ hideMemberInReadOnly: false,
+ isReadOnly: false,
+ hideMembershipEvents: false,
+ hideNickAvatarEvents: false,
+ hiddenEvents: hiddenEventsDefaults,
+ hideThreadChip: false,
+ },
+ state: {
+ focusItem: undefined,
+ editId: undefined,
+ activeReplyId: undefined,
+ openThreadId: undefined,
+ suppressMark: undefined,
+ },
+ permissions: {
+ canRedact: false,
+ canDeleteOwn: false,
+ canSendReaction: false,
+ canPinEvent: false,
+ },
+ callbacks: {
+ onUserClick: vi.fn>(),
+ onUsernameClick: vi.fn>(),
+ onReplyClick:
+ vi.fn<(event: React.MouseEvent, startThread?: boolean) => void>(),
+ onReactionToggle: vi.fn<(targetEventId: string, key: string, shortcode?: string) => void>(),
+ onEditId: vi.fn<(editId?: string) => void>(),
+ onResend: vi.fn<(mEvent: MatrixEvent) => void>(),
+ onDeleteFailedSend: vi.fn<(mEvent: MatrixEvent) => void>(),
+ setOpenThread: vi.fn<(threadId: string | undefined) => void>(),
+ handleOpenReply: vi.fn>(),
+ },
+ utils: {
+ htmlReactParserOptions,
+ linkifyOpts,
+ getMemberPowerTag: () => ({ name: 'Admin' }),
+ parseMemberEvent:
+ vi.fn<(mEvent: MatrixEvent) => { icon: React.ReactNode; body: React.ReactNode }>(),
+ },
+};
+
+function renderEvent(event: MatrixEvent, isStateEvent: boolean) {
+ const { result } = renderHook(() => useTimelineEventRenderer(rendererOpts));
+ const renderFn = result.current;
+ const node = renderFn(
+ event.getType() ?? 'UNKNOWN',
+ isStateEvent,
+ event.getId() ?? 'null',
+ event,
+ 0,
+ timelineSet,
+ false
+ );
+ if (node === null) return { container: null as unknown as HTMLElement };
+ const { container } = render(node as any);
+ return { container };
+}
+
+type BranchEntry = {
+ name: string;
+ eventType: string;
+ isStateEvent: boolean;
+ createEvent: () => MatrixEvent;
+};
+
+const branches: BranchEntry[] = [
+ {
+ name: 'm.room.message (RoomMessage)',
+ eventType: EventType.RoomMessage,
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$msg:example.com',
+ type: EventType.RoomMessage,
+ content: { msgtype: 'm.text', body: 'Hello world!' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.room.encrypted (RoomMessageEncrypted)',
+ eventType: EventType.RoomMessageEncrypted,
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$enc:example.com',
+ type: EventType.RoomMessageEncrypted,
+ encrypted: true,
+ content: { algorithm: 'm.megolm.v1.aes-sha2', ciphertext: '...' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.sticker (Sticker)',
+ eventType: EventType.Sticker,
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$sticker:example.com',
+ type: EventType.Sticker,
+ content: { body: 'Sticker!', url: 'mxc://example.com/sticker' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.poll.start (M_POLL_START)',
+ eventType: M_POLL_START.name,
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$poll:example.com',
+ type: M_POLL_START.name,
+ content: {
+ 'm.poll.start': {
+ question: { 'm.text': [{ body: 'Yes or No?' }] },
+ max_selections: 1,
+ answers: [
+ { id: 'yes', 'm.text': [{ body: 'Yes' }] },
+ { id: 'no', 'm.text': [{ body: 'No' }] },
+ ],
+ },
+ msgtype: 'm.text',
+ body: 'Poll: Yes or No?',
+ },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.room.member (RoomMember)',
+ eventType: EventType.RoomMember,
+ isStateEvent: true,
+ createEvent: () =>
+ createEvent({
+ id: '$member:example.com',
+ type: EventType.RoomMember,
+ content: { membership: 'join', displayname: 'Bob' },
+ prevContent: { membership: 'invite' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.room.name (RoomName)',
+ eventType: EventType.RoomName,
+ isStateEvent: true,
+ createEvent: () =>
+ createEvent({
+ id: '$name:example.com',
+ type: EventType.RoomName,
+ content: { name: 'My Chat Room' },
+ prevContent: { name: 'Old Name' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.room.topic (RoomTopic)',
+ eventType: EventType.RoomTopic,
+ isStateEvent: true,
+ createEvent: () =>
+ createEvent({
+ id: '$topic:example.com',
+ type: EventType.RoomTopic,
+ content: { topic: 'A place to chat' },
+ prevContent: { topic: '' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.room.avatar (RoomAvatar)',
+ eventType: EventType.RoomAvatar,
+ isStateEvent: true,
+ createEvent: () =>
+ createEvent({
+ id: '$avatar:example.com',
+ type: EventType.RoomAvatar,
+ content: { url: 'mxc://example.com/avatar' },
+ prevContent: { url: '' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.call.member (GroupCallMemberPrefix)',
+ // GroupCallMemberPrefix is a prefix that matches m.call.member events
+ eventType: EventType.GroupCallMemberPrefix,
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$call:example.com',
+ type: 'm.call.member',
+ content: {
+ 'm.calls': [{ call_id: '!call:example.com', 'm.foci': [] }],
+ },
+ prevContent: {},
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.reaction (Reaction)',
+ eventType: EventType.Reaction,
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$reaction:example.com',
+ type: EventType.Reaction,
+ content: {
+ 'm.relates_to': { rel_type: 'm.annotation', event_id: '$msg:example.com', key: '👍' },
+ },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.room.redaction (RoomRedaction)',
+ eventType: EventType.RoomRedaction,
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$redact:example.com',
+ type: EventType.RoomRedaction,
+ redaction: true,
+ content: { reason: 'spam removal' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'm.room.pinned_events (RoomPinnedEvents)',
+ eventType: EventType.RoomPinnedEvents,
+ isStateEvent: true,
+ createEvent: () =>
+ createEvent({
+ id: '$pins:example.com',
+ type: EventType.RoomPinnedEvents,
+ content: { pinned: ['$msg:example.com'] },
+ prevContent: { pinned: [] },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'state event fallback (unknown state event)',
+ eventType: 'io.sable.unknown.state',
+ isStateEvent: true,
+ createEvent: () =>
+ createEvent({
+ id: '$unknown-state:example.com',
+ type: 'io.sable.unknown.state',
+ content: { arbitrary: 'state data' },
+ replyEventId: undefined,
+ }),
+ },
+ {
+ name: 'non-state event fallback (unknown event)',
+ eventType: 'io.sable.unknown.event',
+ isStateEvent: false,
+ createEvent: () =>
+ createEvent({
+ id: '$unknown-event:example.com',
+ type: 'io.sable.unknown.event',
+ content: { arbitrary: 'data' },
+ replyEventId: undefined,
+ }),
+ },
+];
+
+describe('useTimelineEventRenderer', () => {
+ describe.each(branches)('$name', ({ isStateEvent, createEvent: makeEvent }) => {
+ it('renders correctly', () => {
+ const evt = makeEvent();
+ // The renderer uses `timelineSet` for reactions; our mock returns null,
+ // so no reaction data. That's fine for snapshot consistency.
+ const { container } = renderEvent(evt, isStateEvent);
+ expect(container).not.toBeNull();
+ expect(container.innerHTML).toMatchSnapshot();
+ });
+ });
+});
diff --git a/src/app/hooks/timeline/useTimelineEventRenderer.tsx b/src/app/hooks/timeline/useTimelineEventRenderer.tsx
index b19bf54e0..6c5c110a7 100644
--- a/src/app/hooks/timeline/useTimelineEventRenderer.tsx
+++ b/src/app/hooks/timeline/useTimelineEventRenderer.tsx
@@ -404,6 +404,101 @@ export function useTimelineEventRenderer({
const getSenderDisplayName = (userId: string): string =>
getTimelineSenderDisplayName(room, userId, nicknames, getProfile(userId)?.displayName);
+ function deriveCommonRenderState(
+ mEventId: string,
+ mEvent: MatrixEvent,
+ item: number,
+ timelineSet: EventTimelineSet,
+ markedVariant: 'suppress' | 'plain' = 'suppress'
+ ) {
+ const highlighted = focusItem?.index === item && focusItem.highlight;
+ const marked =
+ markedVariant === 'plain'
+ ? activeReplyId === mEventId
+ : activeReplyId === mEventId && !suppressMark;
+ const senderId = mEvent.getSender() ?? '';
+ const senderName = getSenderDisplayName(senderId);
+ const timeJSX = (
+
+ );
+ const reactionRelations = getEventReactions(timelineSet, mEventId);
+ const annotations = reactionRelations?.getSortedAnnotationsByKey();
+ const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
+ const hasReactions = reactions && reactions.length > 0;
+
+ return { highlighted, marked, senderId, senderName, timeJSX, reactionRelations, hasReactions };
+ }
+
+ function deriveFallbackCommonRenderState(
+ mEventId: string,
+ mEvent: MatrixEvent,
+ item: number,
+ timelineSet: EventTimelineSet
+ ) {
+ const highlighted = focusItem?.index === item && focusItem.highlight;
+ const marked = activeReplyId === mEventId && !suppressMark;
+ const senderId = mEvent.getSender() ?? '';
+ const senderName = getSenderDisplayName(senderId);
+ const timeJSX = (
+
+ );
+ const reactionRelations = getEventReactions(timelineSet, mEventId);
+ const reactions = reactionRelations?.getSortedAnnotationsByKey();
+ const hasReactions = reactions && reactions.length > 0;
+
+ return { highlighted, marked, senderId, senderName, timeJSX, reactionRelations, hasReactions };
+ }
+
+ function renderThreadChip(mEventId: string, mEvent: MatrixEvent) {
+ if (hideThreadChip) return null;
+ if (!(room.getThread(mEventId) || mEvent.threadRootId)) return null;
+ return (
+ setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
+ />
+ );
+ }
+
+ function renderReactionsBar(
+ mEventId: string,
+ reactionRelations: ReturnType,
+ hasReactions: boolean | undefined | null,
+ threadChip: React.ReactNode,
+ useReactionsGuard: boolean
+ ) {
+ if (!reactionRelations && !threadChip) return undefined;
+ return (
+ <>
+ {reactionRelations && (useReactionsGuard ? hasReactions : true) && (
+
+ )}
+ {threadChip}
+ >
+ );
+ }
+
const renderEditTimelineEvent = (
mEventId: string,
mEvent: MatrixEvent,
@@ -475,35 +570,13 @@ export function useTimelineEventRenderer({
sendStatus={mEvent.getAssociatedStatus()}
collapse={collapse}
activeReplyId={activeReplyId}
- reactions={(() => {
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ false
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -550,12 +623,15 @@ export function useTimelineEventRenderer({
? undefined
: (threadReplyTargetId ?? rawReplyEventId);
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName: senderDisplayName,
+ reactionRelations,
+
+ hasReactions,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
const pushActions = pushProcessor.actionsForEvent(mEvent);
let notifyHighlight: 'silent' | 'loud' | undefined;
@@ -576,9 +652,6 @@ export function useTimelineEventRenderer({
const getContent = (() => editedNewContent ?? safeContent) as GetContentCallback;
- const senderId = mEvent.getSender() ?? '';
- const senderDisplayName = getSenderDisplayName(senderId);
-
const forwardContent = safeContent['moe.sable.message.forward'] as
| {
original_timestamp?: unknown;
@@ -644,35 +717,13 @@ export function useTimelineEventRenderer({
/>
)
}
- reactions={(() => {
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -720,14 +771,15 @@ export function useTimelineEventRenderer({
? undefined
: (threadReplyTargetId ?? rawReplyEventId);
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderDisplayName = getSenderDisplayName(senderId);
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName: senderDisplayName,
+ reactionRelations,
+
+ hasReactions,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
const pushActions = pushProcessor.actionsForEvent(mEvent);
let notifyHighlight: 'silent' | 'loud' | undefined;
@@ -776,35 +828,13 @@ export function useTimelineEventRenderer({
/>
)
}
- reactions={(() => {
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -899,14 +929,14 @@ export function useTimelineEventRenderer({
? undefined
: (threadReplyTargetId ?? rawReplyEventId);
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderDisplayName = getSenderDisplayName(senderId);
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName: senderDisplayName,
+ reactionRelations,
+ hasReactions,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
const content = mEvent.getContent() ?? {};
return (
@@ -948,35 +978,13 @@ export function useTimelineEventRenderer({
/>
)
}
- reactions={(() => {
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1025,12 +1033,15 @@ export function useTimelineEventRenderer({
? undefined
: (threadReplyTargetId ?? rawReplyEventId);
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName: senderDisplayName,
+ reactionRelations,
+
+ hasReactions,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
const pushActions = pushProcessor.actionsForEvent(mEvent);
let notifyHighlight: 'silent' | 'loud' | undefined;
@@ -1051,9 +1062,6 @@ export function useTimelineEventRenderer({
const getContent = (() => editedNewContent ?? safeContent) as GetContentCallback;
- const senderId = mEvent.getSender() ?? '';
- const senderDisplayName = getSenderDisplayName(senderId);
-
const forwardContent = safeContent['moe.sable.message.forward'] as
| {
original_timestamp?: unknown;
@@ -1119,35 +1127,13 @@ export function useTimelineEventRenderer({
/>
)
}
- reactions={(() => {
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1185,26 +1171,18 @@ export function useTimelineEventRenderer({
if (!membershipChanged && hideNickAvatarEvents) return null;
const isRedacted = mEvent.isRedacted();
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
const parsed = isRedacted ? null : parseMemberEvent(mEvent);
- const timeJSX = (
-
- );
-
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
-
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1285,23 +1241,15 @@ export function useTimelineEventRenderer({
},
[EventType.RoomName]: (mEventId, mEvent, item, timelineSet, collapse) => {
const isRedacted = mEvent.isRedacted();
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
- const timeJSX = (
-
- );
-
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1384,24 +1310,15 @@ export function useTimelineEventRenderer({
},
[EventType.RoomTopic]: (mEventId, mEvent, item, timelineSet, collapse) => {
const isRedacted = mEvent.isRedacted();
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
-
- const timeJSX = (
-
- );
-
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1484,24 +1379,15 @@ export function useTimelineEventRenderer({
},
[EventType.RoomAvatar]: (mEventId, mEvent, item, timelineSet, collapse) => {
const isRedacted = mEvent.isRedacted();
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
-
- const timeJSX = (
-
- );
-
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1584,10 +1448,15 @@ export function useTimelineEventRenderer({
},
[EventType.GroupCallMemberPrefix]: (mEventId, mEvent, item, timelineSet, collapse) => {
const isRedacted = mEvent.isRedacted();
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
const content = mEvent.getContent() as Record;
const prevContent = mEvent.getPrevContent();
@@ -1597,20 +1466,6 @@ export function useTimelineEventRenderer({
return null;
}
- const timeJSX = (
-
- );
-
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
-
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1699,21 +1532,17 @@ export function useTimelineEventRenderer({
[EventType.Reaction]: (mEventId, mEvent, item, timelineSet, collapse) => {
if (hideMemberInReadOnly && isReadOnly) return null;
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet, 'plain');
const targetId = getReactionAnnotationTargetId(mEvent) ?? mEvent.getRelation()?.event_id;
- const timeJSX = (
-
- );
-
const targetReply =
typeof targetId === 'string' ? (
) : null;
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
-
if (mEvent.isRedacted()) {
if (!hiddenEventReactionTombstone) return null;
const reactionKey = getReactionKey(mEvent);
@@ -1760,37 +1584,13 @@ export function useTimelineEventRenderer({
sendStatus={mEvent.getAssociatedStatus()}
collapse={collapse}
activeReplyId={activeReplyId}
- reactions={(() => {
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
-
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)
- }
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ false
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1847,35 +1647,13 @@ export function useTimelineEventRenderer({
sendStatus={mEvent.getAssociatedStatus()}
collapse={collapse}
activeReplyId={activeReplyId}
- reactions={(() => {
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -1915,21 +1693,17 @@ export function useTimelineEventRenderer({
return null;
}
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet, 'plain');
const targetId = getRedactionTargetId(mEvent);
- const timeJSX = (
-
- );
-
const targetReply = targetId ? (
) : null;
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
-
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -2024,10 +1771,15 @@ export function useTimelineEventRenderer({
[EventType.RoomPinnedEvents]: (mEventId, mEvent, item, timelineSet, collapse) => {
if (!hiddenEventOther) return null;
const isRedacted = mEvent.isRedacted();
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ reactionRelations,
+ hasReactions,
+ timeJSX,
+ } = deriveCommonRenderState(mEventId, mEvent, item, timelineSet);
const { pinned } = mEvent.getContent();
const prevPinned = mEvent.getPrevContent().pinned;
@@ -2040,20 +1792,6 @@ export function useTimelineEventRenderer({
const pinPreviewIds = (pinsAdded ?? []).concat(...(pinsRemoved ?? []));
const pinnedSet = new Set(pinned ?? []);
- const timeJSX = (
-
- );
-
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const annotations = reactionRelations?.getSortedAnnotationsByKey();
- const reactions = annotations?.filter((annotation) => annotation[1].size > 0);
- const hasReactions = reactions && reactions.length > 0;
-
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && hasReactions && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ true
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -2162,23 +1878,15 @@ export function useTimelineEventRenderer({
(mEventId, mEvent, item, timelineSet, collapse) => {
if (!hiddenEventOther) return null;
const isRedacted = mEvent.isRedacted();
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
-
- const timeJSX = (
-
- );
-
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const reactions = reactionRelations?.getSortedAnnotationsByKey();
- const hasReactions = reactions && reactions.length > 0;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ timeJSX,
+ reactionRelations,
+ hasReactions,
+ } = deriveFallbackCommonRenderState(mEventId, mEvent, item, timelineSet);
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ false
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}
@@ -2267,23 +1953,15 @@ export function useTimelineEventRenderer({
if (mEvent.getRelation()) return null;
if (mEvent.isRedaction()) return null;
- const highlighted = focusItem?.index === item && focusItem.highlight;
- const marked = activeReplyId === mEventId && !suppressMark;
- const senderId = mEvent.getSender() ?? '';
- const senderName = getSenderDisplayName(senderId);
-
- const timeJSX = (
-
- );
-
- const reactionRelations = getEventReactions(timelineSet, mEventId);
- const reactions = reactionRelations?.getSortedAnnotationsByKey();
- const hasReactions = reactions && reactions.length > 0;
+ const {
+ highlighted,
+ marked,
+ senderId,
+ senderName,
+ timeJSX,
+ reactionRelations,
+ hasReactions,
+ } = deriveFallbackCommonRenderState(mEventId, mEvent, item, timelineSet);
return (
{
- const threadChip =
- !hideThreadChip && (room.getThread(mEventId) || mEvent.threadRootId) ? (
- setOpenThread(openThreadId === mEventId ? undefined : mEventId)}
- />
- ) : null;
- if (!reactionRelations && !threadChip) return undefined;
- return (
- <>
- {reactionRelations && (
-
- )}
- {threadChip}
- >
- );
- })()}
+ reactions={renderReactionsBar(
+ mEventId,
+ reactionRelations,
+ hasReactions,
+ renderThreadChip(mEventId, mEvent),
+ false
+ )}
hideReadReceipts={hideReads}
showDeveloperTools={showDeveloperTools}
memberPowerTag={getMemberPowerTag(senderId)}