diff --git a/desktop/src/features/messages/lib/independentThreadPanel.test.mjs b/desktop/src/features/messages/lib/independentThreadPanel.test.mjs index 8dbc3e2840..2dbb524322 100644 --- a/desktop/src/features/messages/lib/independentThreadPanel.test.mjs +++ b/desktop/src/features/messages/lib/independentThreadPanel.test.mjs @@ -7,6 +7,8 @@ const ROOT_ID = "6".repeat(64); const EDIT_ID = "9".repeat(64); const REPLY_ID = "a".repeat(64); const DELETION_ID = "d".repeat(64); +const AUX_DELETION_ID = "e".repeat(64); +const REACTION_ID = "b".repeat(64); const AUTHOR = "f".repeat(64); const CHANNEL = "chan-uuid"; @@ -52,6 +54,21 @@ function deletionEvent(id, targetId) { }; } +function reactionEvent(id, targetId, emoji) { + return { + id, + pubkey: AUTHOR, + kind: 7, + created_at: 2500, + content: emoji, + tags: [ + ["h", CHANNEL], + ["e", targetId], + ], + sig: "s", + }; +} + function head(channelEvents, replyEvents) { return buildIndependentThreadPanel( channelEvents, @@ -143,3 +160,27 @@ test("applies a head deletion carried in the channel window", () => { const result = head([root, deletion], []); assert.equal(result, null); }); + +// Deletion closure: the channel window holds an edit on the head PLUS a deletion +// of that edit (the deletion `#e`-references the EDIT id, not the head). The +// thread head must keep the original, un-edited body — the main timeline does, +// because it has the deletion. Before the closure fix the deletion was dropped +// and the panel resurrected the deleted edit. +test("does not resurrect a deleted head edit carried in the channel window", () => { + const root = contentEvent(ROOT_ID, "two PRs"); + const edit = editEvent(EDIT_ID, ROOT_ID, "these PRs (3)", 2000); + const deletion = deletionEvent(AUX_DELETION_ID, EDIT_ID); + const result = head([root, edit, deletion], []); + assert.equal(result?.body, "two PRs"); + assert.equal(result?.edited, false); +}); + +// Same closure for reactions: a deleted reaction on the head must not reappear +// in the thread panel. +test("does not resurrect a deleted head reaction carried in the channel window", () => { + const root = contentEvent(ROOT_ID, "two PRs"); + const reaction = reactionEvent(REACTION_ID, ROOT_ID, "👍"); + const deletion = deletionEvent(AUX_DELETION_ID, REACTION_ID); + const result = head([root, reaction, deletion], []); + assert.equal(result?.reactions, undefined); +}); diff --git a/desktop/src/features/messages/lib/independentThreadPanel.ts b/desktop/src/features/messages/lib/independentThreadPanel.ts index 6156c6bb8f..30e5bec51f 100644 --- a/desktop/src/features/messages/lib/independentThreadPanel.ts +++ b/desktop/src/features/messages/lib/independentThreadPanel.ts @@ -4,6 +4,10 @@ import { } from "@/features/messages/lib/formatTimelineMessages"; import { buildThreadPanelData } from "@/features/messages/lib/threadPanel"; import type { RelayEvent } from "@/shared/api/types"; +import { + KIND_DELETION, + KIND_NIP29_DELETE_EVENT, +} from "@/shared/constants/kinds"; /** * Aux events (edits/deletions/reactions) already loaded in the channel window @@ -17,17 +21,33 @@ import type { RelayEvent } from "@/shared/api/types"; * * Restricted to non-content kinds so reply content events (which also `#e` the * head as their parent) never leak in here — replies come from `replyEvents`. + * + * Deletion closure: an edit/reaction on the head can itself be deleted by a + * kind:5/9005 that `#e`-references the *overlay's* id, not the head's. Those + * deletions are copied too, so a deleted edit/reaction stays deleted in the + * thread head instead of being resurrected until the async aux backfill lands + * (or permanently if it fails) — mirroring the closure the aux-backfill paths + * build (`mergeAuxEventsWithDeletionBackfill`). */ function headAuxEventsFromChannelWindow( channelEvents: RelayEvent[], headId: string, ): RelayEvent[] { - return channelEvents.filter( + const directAux = channelEvents.filter( (event) => event.id !== headId && !isTimelineContentEvent(event) && event.tags.some((tag) => tag[0] === "e" && tag[1] === headId), ); + const directAuxIds = new Set(directAux.map((event) => event.id)); + const deletionsOfAux = channelEvents.filter( + (event) => + (event.kind === KIND_DELETION || + event.kind === KIND_NIP29_DELETE_EVENT) && + !directAuxIds.has(event.id) && + event.tags.some((tag) => tag[0] === "e" && directAuxIds.has(tag[1])), + ); + return [...directAux, ...deletionsOfAux]; } export function buildIndependentThreadPanel( diff --git a/desktop/tests/e2e/thread-head-stale-edit.spec.ts b/desktop/tests/e2e/thread-head-stale-edit.spec.ts index 529e1449d5..6f865cee03 100644 --- a/desktop/tests/e2e/thread-head-stale-edit.spec.ts +++ b/desktop/tests/e2e/thread-head-stale-edit.spec.ts @@ -1,6 +1,7 @@ import { expect, test } from "@playwright/test"; import { installMockBridge, TEST_IDENTITIES } from "../helpers/bridge"; +import { waitForAnimations } from "../helpers/animations"; // Regression coverage for the reported bug: the top-level timeline shows the // EDITED message body, but opening its thread panel shows the STALE, un-edited @@ -131,5 +132,6 @@ test("thread head reflects the channel-window edit even before thread aux loads" await expect(headBody).toContainText("these PRs?"); await expect(headBody).not.toContainText("these two PRs?"); + await waitForAnimations(page); await page.screenshot({ path: `${SHOT}/thread-head-edited.png` }); });