Skip to content

Commit 424ea70

Browse files
authored
Fix video review comments in threads (#1056)
1 parent 81296d9 commit 424ea70

13 files changed

Lines changed: 689 additions & 150 deletions

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
} from "@/features/messages/ui/MessageThreadPanel";
1111
import { MessageTimeline } from "@/features/messages/ui/MessageTimeline";
1212
import type { ImetaMedia } from "@/features/messages/lib/imetaMediaMarkdown";
13+
import {
14+
buildVideoReviewCommentsByRootId,
15+
buildVideoReviewContextForMessage,
16+
} from "@/features/messages/lib/videoReviewContext";
1317
import { useComposerHeightPadding } from "@/features/messages/ui/useComposerHeightPadding";
1418
import { TypingIndicatorRow } from "@/features/messages/ui/TypingIndicatorRow";
1519
import type { TypingIndicatorEntry } from "@/features/messages/useChannelTyping";
@@ -597,6 +601,38 @@ export const ChannelPane = React.memo(function ChannelPane({
597601

598602
return messages.filter((message) => !isWelcomeSetupSystemMessage(message));
599603
}, [activeChannel, messages]);
604+
const videoReviewCommentsByRootId = React.useMemo(
605+
() => buildVideoReviewCommentsByRootId(messages),
606+
[messages],
607+
);
608+
const activeVideoReviewCommentSender = activeChannel?.archivedAt
609+
? undefined
610+
: onSendVideoReviewComment;
611+
const threadHeadVideoReviewContext = React.useMemo(() => {
612+
if (!threadHeadMessage) {
613+
return undefined;
614+
}
615+
616+
return buildVideoReviewContextForMessage({
617+
channelId: activeChannel?.id ?? null,
618+
channelName: activeChannel?.name,
619+
channelType: activeChannel?.channelType ?? null,
620+
comments: videoReviewCommentsByRootId.get(threadHeadMessage.id) ?? [],
621+
isSendingVideoReviewComment: isSending,
622+
message: threadHeadMessage,
623+
onSendVideoReviewComment: activeVideoReviewCommentSender,
624+
onToggleReaction,
625+
profiles,
626+
});
627+
}, [
628+
activeChannel,
629+
activeVideoReviewCommentSender,
630+
isSending,
631+
onToggleReaction,
632+
profiles,
633+
threadHeadMessage,
634+
videoReviewCommentsByRootId,
635+
]);
600636

601637
const isOverlay = useIsThreadPanelOverlay();
602638
const useSplitAuxiliaryPane = !isSinglePanelView && !isOverlay;
@@ -825,6 +861,7 @@ export const ChannelPane = React.memo(function ChannelPane({
825861
replyTargetMessage={threadReplyTargetMessage}
826862
scrollTargetId={threadScrollTargetId}
827863
threadHead={threadHeadMessage}
864+
threadHeadVideoReviewContext={threadHeadVideoReviewContext}
828865
widthPx={threadPanelWidthPx}
829866
threadReplies={threadMessages}
830867
threadTypingPubkeys={threadTypingPubkeys}

‎desktop/src/features/channels/ui/ChannelScreen.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import {
3333
collectMessageMentionPubkeys,
3434
formatTimelineMessages,
3535
} from "@/features/messages/lib/formatTimelineMessages";
36-
import { buildThreadPanelData } from "@/features/messages/lib/threadPanel";
36+
import {
37+
buildThreadPanelDataFromIndex,
38+
buildThreadPanelIndex,
39+
} from "@/features/messages/lib/threadPanel";
3740
import { imetaMediaFromTags } from "@/features/messages/lib/imetaMediaMarkdown";
3841
import { useFetchOlderMessages } from "@/features/messages/useFetchOlderMessages";
3942
import { useLoadMissingAncestors } from "@/features/messages/useLoadMissingAncestors";
@@ -317,10 +320,14 @@ export function ChannelScreen({
317320
},
318321
[directReplyIdsByParentId],
319322
);
323+
const threadPanelIndex = React.useMemo(
324+
() => buildThreadPanelIndex(timelineMessages),
325+
[timelineMessages],
326+
);
320327
const threadPanelData = React.useMemo(
321328
() =>
322-
buildThreadPanelData(
323-
timelineMessages,
329+
buildThreadPanelDataFromIndex(
330+
threadPanelIndex,
324331
openThreadHeadId,
325332
threadReplyTargetId,
326333
expandedThreadReplyIds,
@@ -329,7 +336,7 @@ export function ChannelScreen({
329336
expandedThreadReplyIds,
330337
openThreadHeadId,
331338
threadReplyTargetId,
332-
timelineMessages,
339+
threadPanelIndex,
333340
],
334341
);
335342
const openThreadHeadMessage = threadPanelData.threadHead;

‎desktop/src/features/messages/lib/threadPanel.test.mjs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import test from "node:test";
44
import {
55
buildMainTimelineEntries,
66
buildThreadPanelData,
7+
buildThreadPanelDataFromIndex,
8+
buildThreadPanelIndex,
79
} from "./threadPanel.ts";
810

911
function message(overrides) {
@@ -100,3 +102,42 @@ test("buildThreadPanelData keeps direct comments unindented", () => {
100102
],
101103
);
102104
});
105+
106+
test("buildThreadPanelDataFromIndex matches direct panel data", () => {
107+
const root = message({ id: "root", createdAt: 1 });
108+
const directComment = message({
109+
id: "direct-comment",
110+
createdAt: 2,
111+
parentId: "root",
112+
rootId: "root",
113+
depth: 1,
114+
tags: [["e", "root", "", "reply"]],
115+
});
116+
const nestedReply = message({
117+
id: "nested-reply",
118+
createdAt: 3,
119+
parentId: "direct-comment",
120+
rootId: "root",
121+
depth: 2,
122+
tags: [
123+
["e", "root", "", "root"],
124+
["e", "direct-comment", "", "reply"],
125+
],
126+
});
127+
const messages = [root, directComment, nestedReply];
128+
129+
const direct = buildThreadPanelData(
130+
messages,
131+
"root",
132+
"direct-comment",
133+
new Set(["direct-comment"]),
134+
);
135+
const indexed = buildThreadPanelDataFromIndex(
136+
buildThreadPanelIndex(messages),
137+
"root",
138+
"direct-comment",
139+
new Set(["direct-comment"]),
140+
);
141+
142+
assert.deepEqual(indexed, direct);
143+
});

‎desktop/src/features/messages/lib/threadPanel.ts‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ type ThreadDescendantStats = {
3232
recentParticipantsNewestFirst: TimelineThreadSummaryParticipant[];
3333
};
3434

35+
export type ThreadPanelIndex = {
36+
directChildrenByParentId: Map<string, TimelineMessage[]>;
37+
descendantStatsByMessageId: Map<string, ThreadDescendantStats>;
38+
messageById: Map<string, TimelineMessage>;
39+
};
40+
3541
const MAX_SUMMARY_PARTICIPANTS = 3;
3642

3743
function normalizeHeadMessage(message: TimelineMessage): TimelineMessage {
@@ -69,8 +75,8 @@ function buildDirectChildrenByParentId(messages: TimelineMessage[]) {
6975

7076
function buildDescendantStatsByMessageId(
7177
messages: TimelineMessage[],
78+
messageById: Map<string, TimelineMessage>,
7279
): Map<string, ThreadDescendantStats> {
73-
const messageById = new Map(messages.map((message) => [message.id, message]));
7480
const descendantStatsByMessageId = new Map<string, ThreadDescendantStats>(
7581
messages.map((message) => [
7682
message.id,
@@ -135,6 +141,21 @@ function buildDescendantStatsByMessageId(
135141
return descendantStatsByMessageId;
136142
}
137143

144+
export function buildThreadPanelIndex(
145+
messages: TimelineMessage[],
146+
): ThreadPanelIndex {
147+
const messageById = new Map(messages.map((message) => [message.id, message]));
148+
149+
return {
150+
directChildrenByParentId: buildDirectChildrenByParentId(messages),
151+
descendantStatsByMessageId: buildDescendantStatsByMessageId(
152+
messages,
153+
messageById,
154+
),
155+
messageById,
156+
};
157+
}
158+
138159
function buildSummaryForDirectReplies(
139160
messageId: string,
140161
descendantStatsByMessageId: Map<string, ThreadDescendantStats>,
@@ -221,7 +242,7 @@ function buildVisibleThreadReplies(params: {
221242
export function buildMainTimelineEntries(
222243
messages: TimelineMessage[],
223244
): MainTimelineEntry[] {
224-
const descendantStatsByMessageId = buildDescendantStatsByMessageId(messages);
245+
const { descendantStatsByMessageId } = buildThreadPanelIndex(messages);
225246

226247
return messages
227248
.filter(
@@ -239,8 +260,8 @@ export function buildMainTimelineEntries(
239260
});
240261
}
241262

242-
export function buildThreadPanelData(
243-
messages: TimelineMessage[],
263+
export function buildThreadPanelDataFromIndex(
264+
index: ThreadPanelIndex,
244265
openThreadHeadId: string | null,
245266
threadReplyTargetId: string | null,
246267
expandedReplyIds: ReadonlySet<string>,
@@ -254,7 +275,8 @@ export function buildThreadPanelData(
254275
};
255276
}
256277

257-
const messageById = new Map(messages.map((message) => [message.id, message]));
278+
const { directChildrenByParentId, descendantStatsByMessageId, messageById } =
279+
index;
258280
const threadHead = messageById.get(openThreadHeadId) ?? null;
259281

260282
if (!threadHead) {
@@ -266,8 +288,6 @@ export function buildThreadPanelData(
266288
};
267289
}
268290

269-
const directChildrenByParentId = buildDirectChildrenByParentId(messages);
270-
const descendantStatsByMessageId = buildDescendantStatsByMessageId(messages);
271291
const normalizedThreadHead = normalizeHeadMessage(threadHead);
272292
const visibleReplies = buildVisibleThreadReplies({
273293
openThreadHeadId,
@@ -289,3 +309,17 @@ export function buildThreadPanelData(
289309
replyTargetMessage: replyTargetInBranch ?? normalizedThreadHead,
290310
};
291311
}
312+
313+
export function buildThreadPanelData(
314+
messages: TimelineMessage[],
315+
openThreadHeadId: string | null,
316+
threadReplyTargetId: string | null,
317+
expandedReplyIds: ReadonlySet<string>,
318+
): ThreadPanelData {
319+
return buildThreadPanelDataFromIndex(
320+
buildThreadPanelIndex(messages),
321+
openThreadHeadId,
322+
threadReplyTargetId,
323+
expandedReplyIds,
324+
);
325+
}

0 commit comments

Comments
 (0)