Skip to content

Commit 30606ad

Browse files
johnmatthewtennantSol
andauthored
fix(inbox): exclude channel-archived conversations (#757)
Signed-off-by: Sol <49aa1f65411fd096d2e2ec144f1e7aa36fdc76d1b907cfdf7be000c66f9d3b8e@buzz.block.builderlab.xyz> Co-authored-by: Sol <49aa1f65411fd096d2e2ec144f1e7aa36fdc76d1b907cfdf7be000c66f9d3b8e@buzz.block.builderlab.xyz>
1 parent 5d3c640 commit 30606ad

6 files changed

Lines changed: 451 additions & 7 deletions

File tree

‎docs/inbox.md‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,18 @@ never become duplicate conversations. Current membership gates the feed's
124124
completeness targets and unread's rows; joining alone does not materialize
125125
pre-membership history without fresh shared admission. Inbox renders those shared
126126
conversation rows directly; there is no second project/approval row merge or
127-
feed-owned reconciliation buffer and deletion-count abort. PR4 owns only
128-
presentation, filtering and selection. No parallel signing or persistence is
127+
feed-owned reconciliation buffer and deletion-count abort.
128+
129+
Channel-archived rooms are excluded from the shared Inbox projection in every
130+
activity view. Signed archive/unarchive metadata invalidates that projection even
131+
when membership and channel type stay unchanged. Archiving removes their rows and
132+
closes a selected Inbox detail, without clearing retained evidence or read/local-unread
133+
intent. Unarchiving makes retained conversations eligible again; it does not
134+
reopen the detail. Ordinary Channels/search retain member history access and
135+
archived posting restrictions. This is Inbox eligibility, not access revocation or
136+
notification policy.
137+
138+
PR4 owns only presentation, filtering and selection. No parallel signing or persistence is
129139
added. Optional profile enrichment belongs to PR4; access, cache clear and
130140
session retirement fence these projections. Opening Inbox does not mark rows
131141
read; selecting an unread row does. Canonical Messages keeps its own reading

‎src/bundled/inbox/InboxPage.test.tsx‎

Lines changed: 214 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ afterEach(() => {
5858
function fixture(
5959
options: {
6060
failRoster?: boolean;
61+
archivedChannel?: boolean;
6162
withDm?: boolean;
6263
withSenders?: boolean;
6364
holdProfiles?: boolean;
@@ -84,6 +85,8 @@ function fixture(
8485
let rosterGate: Promise<void> | undefined;
8586
let rosterStarted = false;
8687
let evidenceReads = 0;
88+
let unreadGate: Promise<void> | undefined;
89+
let unreadStarted = false;
8790
const historyRequests: string[] = [];
8891
const threadRequests: string[] = [];
8992
const exactRequests: string[] = [];
@@ -179,7 +182,10 @@ function fixture(
179182
["private"],
180183
["about", "Buzz session (buzz.sessions/v1)"],
181184
]
182-
: [["t", "stream"]],
185+
: [
186+
["t", "stream"],
187+
...(options.archivedChannel ? [["archived", "true"]] : []),
188+
],
183189
),
184190
profile(alice, { name: "Alice" }),
185191
...roots,
@@ -234,6 +240,15 @@ function fixture(
234240
viewer: viewer.pubkey,
235241
relayAuthor: relayKey.pubkey,
236242
query: async (filters) => {
243+
if (
244+
filters.some(
245+
(filter) =>
246+
filter.include_aux && !!filter["#h"] && filter.kinds?.includes(9),
247+
)
248+
) {
249+
unreadStarted = true;
250+
await unreadGate;
251+
}
237252
if (
238253
filters.some((filter) => !!filter["#p"] && filter.kinds?.includes(9))
239254
)
@@ -409,6 +424,18 @@ function fixture(
409424
readSteps,
410425
evidenceReads: () => evidenceReads,
411426
historyRequests,
427+
unreadStarted: () => unreadStarted,
428+
holdUnread() {
429+
unreadStarted = false;
430+
let release = () => {};
431+
unreadGate = new Promise<void>((resolve) => {
432+
release = resolve;
433+
});
434+
return () => {
435+
unreadGate = undefined;
436+
release();
437+
};
438+
},
412439
holdAddressed() {
413440
addressedGate = new Promise<void>((resolve) => {
414441
releaseAddressed = resolve;
@@ -563,6 +590,14 @@ function fixture(
563590
events.push(restored);
564591
emit([restored, mention, reply, ...roots]);
565592
},
593+
archiveRoom(archived: boolean, time: number) {
594+
const state = metadata(relayKey, "room", "Design", time, [
595+
["t", "stream"],
596+
["archived", String(archived)],
597+
]);
598+
events.push(state);
599+
emit([state]);
600+
},
566601
renameRoom() {
567602
const renamed = metadata(relayKey, "room", "Renamed", 99, [
568603
["t", "stream"],
@@ -627,6 +662,184 @@ async function openRowMenu(
627662
}
628663
return screen.findByRole("menuitem", { name: "Mark unread" });
629664
}
665+
it("excludes archived-channel mentions and threads without hiding active DMs", async () => {
666+
const h = fixture({ archivedChannel: true, withDm: true });
667+
render(h.view);
668+
await screen.findByText("A direct reply");
669+
await waitFor(() =>
670+
expect(
671+
screen.queryByText("Checking recent activity…"),
672+
).not.toBeInTheDocument(),
673+
);
674+
expect(rows()).toHaveLength(1);
675+
expect(rows()[0]).toHaveTextContent("A direct reply");
676+
await chooseFilter("Mentions");
677+
expect(rows()).toHaveLength(0);
678+
await chooseFilter("Threads");
679+
expect(rows()).toHaveLength(0);
680+
});
681+
682+
it.each(["Please review", "A thread update"])(
683+
"closes selected Inbox detail on channel archive and restores unread intent on unarchive (%s)",
684+
async (preview) => {
685+
const h = fixture({ withWriter: true });
686+
render(h.view);
687+
await waitFor(() => expect(rows()).toHaveLength(2));
688+
const row = rows().find((item) => item.textContent?.includes(preview));
689+
if (!row) throw new Error("Missing fixture conversation");
690+
fireEvent.click(within(row).getByRole("button", { name: /^Open / }));
691+
const detail = screen.getByRole("region", { name: "Inbox detail" });
692+
await within(detail).findByText(
693+
preview === "Please review" ? /Please review/ : "A thread update",
694+
);
695+
await waitFor(() =>
696+
expect(
697+
within(row).queryByRole("img", { name: "Unread" }),
698+
).not.toBeInTheDocument(),
699+
);
700+
fireEvent.contextMenu(within(row).getByRole("button", { name: /^Open / }));
701+
fireEvent.click(
702+
await screen.findByRole("menuitem", { name: "Mark unread" }),
703+
);
704+
await waitFor(() =>
705+
expect(
706+
within(row).getByRole("img", { name: "Unread" }),
707+
).toBeInTheDocument(),
708+
);
709+
const journal = h.journal();
710+
act(() => h.archiveRoom(true, 100));
711+
await waitFor(() => expect(rows()).toHaveLength(0));
712+
expect(
713+
screen.queryByRole("region", { name: "Inbox detail" }),
714+
).not.toBeInTheDocument();
715+
expect(
716+
screen.getByRole("combobox", { name: "Activity type" }),
717+
).toHaveFocus();
718+
expect(h.journal()).toEqual(journal);
719+
act(() => h.archiveRoom(false, 101));
720+
await waitFor(() => expect(rows()).toHaveLength(2));
721+
const restored = rows().find((item) => item.textContent?.includes(preview));
722+
if (!restored) throw new Error("Missing restored conversation");
723+
expect(
724+
within(restored).getByRole("img", { name: "Unread" }),
725+
).toBeInTheDocument();
726+
expect(
727+
screen.queryByRole("region", { name: "Inbox detail" }),
728+
).not.toBeInTheDocument();
729+
expect(h.journal()).toEqual(journal);
730+
},
731+
);
732+
733+
it.each([false, true])(
734+
"retires selected visits only on explicit archive during a held unread refresh (archive=%s)",
735+
async (archive) => {
736+
const h = fixture();
737+
render(h.view);
738+
await screen.findByText("Please review this");
739+
await waitFor(() =>
740+
expect(h.owner.session.unread.inbox().status).toBe("ready"),
741+
);
742+
await chooseFilter("Mentions");
743+
fireEvent.click(
744+
screen.getByRole("button", { name: "Open Alice in #Design" }),
745+
);
746+
await within(
747+
screen.getByRole("region", { name: "Inbox detail" }),
748+
).findByText(/Please review/);
749+
await waitFor(() =>
750+
expect(
751+
screen.queryByRole("img", { name: "Unread" }),
752+
).not.toBeInTheDocument(),
753+
);
754+
const journal = h.journal();
755+
const release = h.holdUnread();
756+
let refresh: Promise<void> | undefined;
757+
try {
758+
act(() => {
759+
refresh = h.owner.session.unread.refresh();
760+
});
761+
await waitFor(() => expect(h.unreadStarted()).toBe(true));
762+
expect(h.owner.session.unread.inbox().status).toBe("loading");
763+
expect(
764+
screen.getByRole("region", { name: "Inbox detail" }),
765+
).toBeInTheDocument();
766+
if (archive) {
767+
act(() => h.archiveRoom(true, 100));
768+
await waitFor(() => expect(rows()).toHaveLength(0));
769+
expect(
770+
screen.queryByRole("region", { name: "Inbox detail" }),
771+
).not.toBeInTheDocument();
772+
act(() => h.archiveRoom(false, 101));
773+
await waitFor(() => expect(rows()).toHaveLength(1));
774+
expect(h.owner.session.unread.inbox().status).toBe("loading");
775+
expect(
776+
screen.queryByRole("region", { name: "Inbox detail" }),
777+
).not.toBeInTheDocument();
778+
expect(
779+
screen.getByRole("combobox", { name: "Activity type" }),
780+
).toHaveFocus();
781+
expect(h.journal()).toEqual(journal);
782+
}
783+
} finally {
784+
await act(async () => {
785+
release();
786+
await refresh;
787+
});
788+
}
789+
await waitFor(() =>
790+
expect(h.owner.session.unread.inbox().status).toBe("ready"),
791+
);
792+
expect(!!screen.queryByRole("region", { name: "Inbox detail" })).toBe(
793+
!archive,
794+
);
795+
expect(h.journal()).toEqual(journal);
796+
},
797+
);
798+
799+
it("retires a failed captured read on archive during a held unread refresh", async () => {
800+
const h = fixture();
801+
render(h.view);
802+
await screen.findByText("Please review this");
803+
await waitFor(() =>
804+
expect(h.owner.session.unread.inbox().status).toBe("ready"),
805+
);
806+
await chooseFilter("Mentions");
807+
h.failSave();
808+
fireEvent.click(
809+
screen.getByRole("button", { name: "Open Alice in #Design" }),
810+
);
811+
expect(await screen.findByRole("alert")).toHaveTextContent("disk full");
812+
const release = h.holdUnread();
813+
let refresh: Promise<void> | undefined;
814+
try {
815+
act(() => {
816+
refresh = h.owner.session.unread.refresh();
817+
});
818+
await waitFor(() => expect(h.unreadStarted()).toBe(true));
819+
act(() => h.archiveRoom(true, 100));
820+
await waitFor(() => expect(rows()).toHaveLength(0));
821+
act(() => h.archiveRoom(false, 101));
822+
await waitFor(() => expect(rows()).toHaveLength(1));
823+
expect(h.owner.session.unread.inbox().status).toBe("loading");
824+
expect(
825+
screen.queryByRole("button", { name: "Retry inbox" }),
826+
).not.toBeInTheDocument();
827+
} finally {
828+
await act(async () => {
829+
release();
830+
await refresh;
831+
});
832+
}
833+
await waitFor(() =>
834+
expect(h.owner.session.unread.inbox().status).toBe("ready"),
835+
);
836+
expect(
837+
screen.queryByRole("region", { name: "Inbox detail" }),
838+
).not.toBeInTheDocument();
839+
expect(h.journal()?.state.frontiers[`msg:${h.mention.id}`]).toBeUndefined();
840+
expect(screen.getByRole("img", { name: "Unread" })).toBeInTheDocument();
841+
});
842+
630843
it("filters real session evidence, opens an exact message and marks it read, and shares durable local unread", async () => {
631844
const h = fixture();
632845
render(h.view);

‎src/bundled/inbox/InboxPage.tsx‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,23 @@ export function InboxView({
253253
invokingRow.current = null;
254254
setRestoringFocus(false);
255255
}, [selectedTarget, restoringFocus, pending]);
256+
const selectedArchived = list.channels.some(
257+
(channel) => channel.id === selectedTarget?.channelId && channel.archived,
258+
);
256259
useEffect(() => {
257-
if (selectedTarget && !selected && inbox.status !== "loading") {
260+
if (
261+
selectedTarget &&
262+
(selectedArchived || (!selected && inbox.status !== "loading"))
263+
) {
264+
if (selectedArchived) {
265+
intentRevision.current++;
266+
failedMutation.current = undefined;
267+
setError(undefined);
268+
}
258269
setRestoringFocus(true);
259270
setSelectedTarget(undefined);
260271
}
261-
}, [selectedTarget, selected, inbox.status]);
272+
}, [selectedTarget, selected, selectedArchived, inbox.status]);
262273
useEffect(() => {
263274
if (menu && !items.some((item) => item.id === menu.id)) setMenu(undefined);
264275
}, [items, menu]);

‎src/features/relay/unread.test.ts‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,6 +2570,70 @@ it("inbox groups relevant conversations, preserves read rows and exact unread re
25702570
stop();
25712571
});
25722572

2573+
it.each([false, true])(
2574+
"inbox hides archived channels and restores retained unread state (subscribed=%s)",
2575+
async (subscribed) => {
2576+
const h = setup();
2577+
h.grant("room");
2578+
h.grant("dm");
2579+
h.emit([metadata(h.relay, "dm", "DM", 11, [["t", "dm"]])]);
2580+
const root = message(h.viewer, "room", "My thread", 20);
2581+
const mention = message(h.alice, "room", "Mention", 21, [
2582+
["p", h.viewer.pubkey],
2583+
]);
2584+
const reply = message(h.alice, "room", "Reply", 22, [
2585+
["e", root.id, "", "reply"],
2586+
]);
2587+
const dm = message(h.alice, "dm", "Direct hello", 23);
2588+
h.emit([root, mention, reply, dm]);
2589+
const unread = h.session.unread;
2590+
await unread.markMessageRead("room", mention.id);
2591+
await unread.markUnreadLocal({
2592+
kind: "message",
2593+
channelId: "room",
2594+
messageId: mention.id,
2595+
});
2596+
const before = unread.inbox();
2597+
expect(before.items).toHaveLength(3);
2598+
const journal = h.journal();
2599+
const snapshot = h.snapshot();
2600+
const generation = unread.generation();
2601+
const noticed: string[][] = [];
2602+
const stop = subscribed
2603+
? unread.subscribeInbox(() =>
2604+
noticed.push(unread.inbox().items.map((item) => item.channelId)),
2605+
)
2606+
: () => {};
2607+
h.emit([metadata(h.relay, "room", "room", 30, [["archived", "true"]])]);
2608+
expect(unread.inbox().items.map((item) => item.channelId)).toEqual(["dm"]);
2609+
if (subscribed) expect(noticed.at(-1)).toEqual(["dm"]);
2610+
expect(h.snapshot()).toEqual(snapshot);
2611+
expect(unread.generation()).toBe(generation);
2612+
expect(h.journal()).toEqual(journal);
2613+
// Fresh addressed evidence stays hidden, not discarded or marked read.
2614+
const fresh = message(h.alice, "room", "Fresh mention", 31, [
2615+
["p", h.viewer.pubkey],
2616+
]);
2617+
h.emit([fresh]);
2618+
expect(unread.inbox().items.map((item) => item.channelId)).toEqual(["dm"]);
2619+
h.emit([metadata(h.relay, "room", "room", 32, [["archived", "false"]])]);
2620+
const restored = unread.inbox();
2621+
expect(restored.items).toHaveLength(4);
2622+
for (const item of before.items)
2623+
expect(restored.items).toContainEqual(item);
2624+
expect(
2625+
restored.items.find((item) => item.messageId === fresh.id)?.unreadCount,
2626+
).toBe(1);
2627+
expect(h.journal()).toEqual(journal);
2628+
// Renaming is not an Inbox invalidation input.
2629+
const count = noticed.length;
2630+
h.emit([metadata(h.relay, "room", "Renamed", 33)]);
2631+
expect(unread.inbox()).toBe(restored);
2632+
expect(noticed).toHaveLength(count);
2633+
stop();
2634+
},
2635+
);
2636+
25732637
it("inbox folds edits and deletions and revokes all evidence before a reentrant subscriber", async () => {
25742638
const h = setup();
25752639
h.grant("room");

0 commit comments

Comments
 (0)