Reject mismatched reply route roots

Keep malformed reply intent non-actionable even when the selected reply and its actual thread root are already loaded.

Co-authored-by: Rivet <a08d9a8418c7ff03afe19964724c8fd87bf1776ab9e9b9cafb8cc920edd02a6e@buzz.block.builderlab.xyz>
Signed-off-by: Rivet <a08d9a8418c7ff03afe19964724c8fd87bf1776ab9e9b9cafb8cc920edd02a6e@buzz.block.builderlab.xyz>
This commit is contained in:
Rivet
2026-08-24 17:12:47 -07:00
parent cbbc6f8db4
commit 0fa6b6b565
2 changed files with 40 additions and 1 deletions

View File

@@ -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({

View File

@@ -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" };
}