diff --git a/desktop/src/features/channels/ui/useChannelRouteTarget.test.mjs b/desktop/src/features/channels/ui/useChannelRouteTarget.test.mjs index d37a6fd1e7..54fdd0dd6f 100644 --- a/desktop/src/features/channels/ui/useChannelRouteTarget.test.mjs +++ b/desktop/src/features/channels/ui/useChannelRouteTarget.test.mjs @@ -48,7 +48,7 @@ test("top-level target with an explicit threadRootId opens its thread panel", () }); }); -test("reply target opens the thread scrolled to the reply", () => { +test("reply target without threadRootId opens the derived thread", () => { const root = makeMessage({ id: "root" }); const reply = makeMessage({ id: "reply", @@ -65,6 +65,40 @@ test("reply target opens the thread scrolled to the reply", () => { }); }); +test("reply target with its derived threadRootId opens the thread", () => { + const root = makeMessage({ id: "root" }); + const reply = makeMessage({ + id: "reply", + parentId: "root", + rootId: "root", + depth: 1, + }); + assert.deepEqual( + getRouteTargetPanelAction(reply, root.id, byId(root, reply)), + { + kind: "open-thread", + expandedReplyIds: new Set(), + replyTargetId: "root", + scrollTargetId: "reply", + threadHeadId: "root", + }, + ); +}); + +test("reply target with a mismatched threadRootId does not open the loaded derived thread", () => { + const root = makeMessage({ id: "root" }); + const reply = makeMessage({ + id: "reply", + parentId: "root", + rootId: "root", + depth: 1, + }); + assert.deepEqual( + getRouteTargetPanelAction(reply, "unrelated-root", byId(root, reply)), + { kind: "none" }, + ); +}); + test("nested reply target expands its intermediate ancestors", () => { const root = makeMessage({ id: "root" }); const mid = makeMessage({ diff --git a/desktop/src/features/channels/ui/useChannelRouteTarget.ts b/desktop/src/features/channels/ui/useChannelRouteTarget.ts index 236199b495..e099db26ee 100644 --- a/desktop/src/features/channels/ui/useChannelRouteTarget.ts +++ b/desktop/src/features/channels/ui/useChannelRouteTarget.ts @@ -84,6 +84,11 @@ export function getRouteTargetPanelAction( }; } + const derivedRootId = targetMessage.rootId ?? targetMessage.parentId; + if (targetThreadRootId !== null && targetThreadRootId !== derivedRootId) { + return { kind: "none" }; + } + if (isBroadcastReply(targetMessage.tags ?? [])) { return { kind: "none" }; }