Skip to content

Commit 6604062

Browse files
npub12uu53ml9upy7ww9apmtv6vm0u8xlcldx7znsjvwgsr7uvy5g0kssw943cabrow
andcommitted
Hydrate the Inbox structural aux closure two hops deep
Cold Inbox hydration fetched only the one-hop structural aux set for the context message ids, so a kind:5 deletion that targets an edit event was never fetched. formatTimelineMessages suppresses an edit only when the edit's own id is in the deletion set, so a cold Inbox open re-applied a retracted edit and showed content the author had already withdrawn. Route the fetch through fetchStructuralAuxForMessages, the same helper the channel and thread paths use, which resolves the second hop via fetchAuxDeletionEventsForAuxEvents. The refresh path delegates to the same callback, so it is covered too. Co-authored-by: Tom Brow <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent 4a20cd0 commit 6604062

2 files changed

Lines changed: 158 additions & 9 deletions

File tree

‎desktop/src/features/home/useInboxThreadContext.ts‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import * as React from "react";
22

33
import { isInboxThreadContextEvent } from "@/features/home/lib/inboxViewHelpers";
44
import { relayEventFromFeedItem } from "@/features/home/lib/inbox";
5+
import { fetchStructuralAuxForMessages } from "@/features/messages/lib/auxBackfill";
56
import { getThreadReference } from "@/features/messages/lib/threading";
67
import { relayClient } from "@/shared/api/relayClient";
7-
import {
8-
buildChannelReactionAuxFilter,
9-
buildChannelStructuralAuxFilter,
10-
} from "@/shared/api/relayChannelFilters";
8+
import { buildChannelReactionAuxFilter } from "@/shared/api/relayChannelFilters";
119
import { getEventById } from "@/shared/api/tauri";
1210
import type { FeedItem, RelayEvent } from "@/shared/api/types";
1311
import {
@@ -282,11 +280,12 @@ export function useInboxThreadContext(
282280
}
283281

284282
try {
285-
return await relayClient.fetchAuxEventsByReference(
286-
selectedChannelId,
287-
eventIds,
288-
buildChannelStructuralAuxFilter,
289-
);
283+
// Two hops, not one. A deletion can target an edit event rather than the
284+
// original message, and `formatTimelineMessages` drops an edit only when
285+
// the edit's own id is in the deletion set. A one-hop fetch therefore
286+
// re-applies retracted content on a cold Inbox open. The channel and
287+
// thread paths already resolve this closure with the same helper.
288+
return await fetchStructuralAuxForMessages(selectedChannelId, eventIds);
290289
} catch (error) {
291290
console.error(
292291
"Failed to hydrate structural events for Inbox context messages",

‎desktop/tests/e2e/inbox-edit.spec.ts‎

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ const EMPTY_DELETE_REPLY_ID = "b2".repeat(32);
1212
const EMPTY_DELETE_ROOT_CONTENT = "Inbox empty-edit root message.";
1313
const EMPTY_DELETE_REPLY_CONTENT =
1414
"Selected Inbox reply remains after root deletion.";
15+
const COLD_ROOT_ID = "c3".repeat(32);
16+
const COLD_SELECTED_REPLY_ID = "f4".repeat(32);
17+
const COLD_DELETED_EDIT_ID = "0a".repeat(32);
18+
const COLD_SIBLING_REPLY_ID = "1b".repeat(32);
19+
const COLD_SIBLING_EDIT_ID = "2c".repeat(32);
20+
const COLD_ROOT_CONTENT = "Cold Inbox thread root.";
21+
const COLD_SELECTED_ORIGINAL_CONTENT = "Cold Inbox reply original text.";
22+
const COLD_SELECTED_RETRACTED_CONTENT = "Cold Inbox reply retracted edit text.";
23+
const COLD_SIBLING_ORIGINAL_CONTENT = "Cold Inbox sibling reply original text.";
24+
const COLD_SIBLING_EDITED_CONTENT = "Cold Inbox sibling reply edited text.";
1525
const ATTACHMENT_URL = `https://mock.relay/media/${"a".repeat(64)}.pdf`;
1626
const ATTACHMENT_FILENAME = "inbox-edit-proof.pdf";
1727
const SHOTS = "test-results/inbox-edit";
@@ -40,6 +50,8 @@ type MockWindow = Window & {
4050
pubkey?: string;
4151
mentionPubkeys?: string[];
4252
id?: string;
53+
kind?: number;
54+
extraTags?: string[][];
4355
}) => {
4456
content: string;
4557
created_at: number;
@@ -498,3 +510,141 @@ test("cancelling an empty Inbox edit deletion preserves content and edit mode",
498510
),
499511
).toBe(0);
500512
});
513+
514+
// Regression test for the cold Inbox hydration closure. A deletion can target
515+
// an edit event instead of the original message, and `formatTimelineMessages`
516+
// drops an edit only when the edit's own id is in the deletion set. A one-hop
517+
// `#e` fetch over the context message ids returns the edit but not the deletion
518+
// of that edit, so a cold Inbox open re-applies retracted content. The sibling
519+
// reply is the positive control: its live edit is NOT deleted, so it must still
520+
// render as edited after the same cold fetch.
521+
test("cold Inbox open drops an edit that was itself deleted", async ({
522+
page,
523+
}) => {
524+
await installMockBridge(page);
525+
await page.goto("/");
526+
await expect(page.getByTestId("home-inbox-list")).toBeVisible();
527+
await page.waitForFunction(() => {
528+
const win = window as MockWindow;
529+
return (
530+
typeof win.__BUZZ_E2E_EMIT_MOCK_MESSAGE__ === "function" &&
531+
typeof win.__BUZZ_E2E_PUSH_MOCK_FEED_ITEM__ === "function"
532+
);
533+
});
534+
535+
await page.evaluate(
536+
({
537+
channelId,
538+
currentPubkey,
539+
deletedEditId,
540+
rootContent,
541+
rootId,
542+
selectedOriginalContent,
543+
selectedReplyId,
544+
selectedRetractedContent,
545+
siblingEditId,
546+
siblingEditedContent,
547+
siblingOriginalContent,
548+
siblingReplyId,
549+
}) => {
550+
const win = window as MockWindow;
551+
const emit = win.__BUZZ_E2E_EMIT_MOCK_MESSAGE__;
552+
const push = win.__BUZZ_E2E_PUSH_MOCK_FEED_ITEM__;
553+
if (!emit || !push) {
554+
throw new Error("Mock bridge helpers are unavailable.");
555+
}
556+
557+
const root = emit({
558+
channelName: "general",
559+
content: rootContent,
560+
id: rootId,
561+
pubkey: currentPubkey,
562+
});
563+
const selectedReply = emit({
564+
channelName: "general",
565+
content: selectedOriginalContent,
566+
id: selectedReplyId,
567+
mentionPubkeys: [currentPubkey],
568+
parentEventId: root.id,
569+
pubkey: currentPubkey,
570+
});
571+
const siblingReply = emit({
572+
channelName: "general",
573+
content: siblingOriginalContent,
574+
id: siblingReplyId,
575+
parentEventId: root.id,
576+
pubkey: currentPubkey,
577+
});
578+
579+
// The retracted edit: published, then deleted by a kind:5 that targets
580+
// the EDIT event, never the reply itself.
581+
const retractedEdit = emit({
582+
channelName: "general",
583+
content: selectedRetractedContent,
584+
extraTags: [["e", selectedReply.id]],
585+
id: deletedEditId,
586+
kind: 40003,
587+
pubkey: currentPubkey,
588+
});
589+
emit({
590+
channelName: "general",
591+
content: "",
592+
extraTags: [["e", retractedEdit.id]],
593+
kind: 5,
594+
pubkey: currentPubkey,
595+
});
596+
597+
// Positive control: a live edit with no deletion of its own.
598+
emit({
599+
channelName: "general",
600+
content: siblingEditedContent,
601+
extraTags: [["e", siblingReply.id]],
602+
id: siblingEditId,
603+
kind: 40003,
604+
pubkey: currentPubkey,
605+
});
606+
607+
push({
608+
category: "mention",
609+
channel_id: channelId,
610+
channel_name: "general",
611+
content: selectedReply.content,
612+
created_at: selectedReply.created_at,
613+
id: selectedReply.id,
614+
kind: selectedReply.kind,
615+
pubkey: selectedReply.pubkey,
616+
tags: selectedReply.tags,
617+
});
618+
},
619+
{
620+
channelId: GENERAL_CHANNEL_ID,
621+
currentPubkey: CURRENT_PUBKEY,
622+
deletedEditId: COLD_DELETED_EDIT_ID,
623+
rootContent: COLD_ROOT_CONTENT,
624+
rootId: COLD_ROOT_ID,
625+
selectedOriginalContent: COLD_SELECTED_ORIGINAL_CONTENT,
626+
selectedReplyId: COLD_SELECTED_REPLY_ID,
627+
selectedRetractedContent: COLD_SELECTED_RETRACTED_CONTENT,
628+
siblingEditId: COLD_SIBLING_EDIT_ID,
629+
siblingEditedContent: COLD_SIBLING_EDITED_CONTENT,
630+
siblingOriginalContent: COLD_SIBLING_ORIGINAL_CONTENT,
631+
siblingReplyId: COLD_SIBLING_REPLY_ID,
632+
},
633+
);
634+
635+
// First selection of this item: every edit and deletion must come from the
636+
// hydration fetch, not from an optimistic local write.
637+
await page.getByTestId(`home-inbox-item-${COLD_SELECTED_REPLY_ID}`).click();
638+
const detail = page.getByTestId("home-inbox-detail");
639+
const siblingRow = detail.locator(
640+
`[data-message-id="${COLD_SIBLING_REPLY_ID}"]`,
641+
);
642+
await expect(siblingRow).toContainText(COLD_SIBLING_EDITED_CONTENT);
643+
644+
const selectedRow = detail.locator(
645+
`[data-message-id="${COLD_SELECTED_REPLY_ID}"]`,
646+
);
647+
await expect(selectedRow).toContainText(COLD_SELECTED_ORIGINAL_CONTENT);
648+
await expect(selectedRow).not.toContainText(COLD_SELECTED_RETRACTED_CONTENT);
649+
await expect(detail).not.toContainText(COLD_SELECTED_RETRACTED_CONTENT);
650+
});

0 commit comments

Comments
 (0)