Skip to content

Commit 67ed94b

Browse files
committed
Fix Inbox review recovery, focus and membership projection
Signed-off-by: tulsi <[email protected]>
1 parent 1bfa929 commit 67ed94b

10 files changed

Lines changed: 250 additions & 30 deletions

File tree

‎docs/inbox.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ does not enable it.
3030
- Stable conversation IDs, newest relevant activity ordering and the oldest
3131
observed unread message as the opening anchor (latest when read). Selecting an
3232
unread row opens inline detail and marks its verified observed prefix read; a
33-
failed read leaves the dot and shows an error. Hosts without frontier sync keep
33+
failed read leaves the dot and shows an error with Retry above both panes,
34+
including when narrow detail hides the list. Hosts without frontier sync keep
3435
the dot. The DM and thread views reuse the shared timeline, thread panel and
3536
scoped composer. Normal threads, DM previews and selected drafts share the
3637
same rounded, lightly bordered conversation treatment with a compact header,
@@ -63,7 +64,8 @@ does not enable it.
6364
recovery disables sending without rebinding the draft to another root.
6465
The top-right Open in origin arrow navigates to the original conversation
6566
separately. Delete remains a
66-
small destructive action gated by confirmation; storage failures keep the
67+
small destructive action gated by confirmation; focus moves to the confirmation
68+
action and returns to the original trigger on Cancel. Storage failures keep the
6769
draft. The list remains usable beside the conversation (or above it when
6870
the Inbox column is narrow), with a bounded, scrollable history area. The
6971
inner close icon dismisses selection; Back to Inbox is the only page-return
@@ -81,7 +83,9 @@ evidence and read actions. `session.inboxFeed` owns finite, verified addressed
8183
history and live reconciliation. Its admitted channel events contribute to the
8284
shared unread fold, never a second raw row projection that could resurrect
8385
own/deleted messages or invent unresolved conversation roots. Nonchat projection
84-
stays bounded; project updates use the evidenced issue/PR root kind, otherwise
86+
stays bounded and reprojects retained candidates on membership changes, including
87+
an empty admitted view becoming eligible after joining; this starts no new read.
88+
Project updates use the evidenced issue/PR root kind, otherwise
8589
open the repository rather than guessing an item type. Arrivals and admitted
8690
deletions during a finite read are reconciled inside that attempt's bounds and
8791
generation. Inbox owns only presentation, filtering and selection. No parallel signing or persistence capability is added. Optional

‎src/bundled/inbox/DraftsView.tsx‎

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
1+
import {
2+
useEffect,
3+
useLayoutEffect,
4+
useMemo,
5+
useRef,
6+
useState,
7+
useSyncExternalStore,
8+
} from "react";
29
import type { ConversationExtensions } from "../../features/conversation/contracts";
310
import { ThreadPanel } from "../../features/messages/ThreadPanel";
411
import { ChannelPreview } from "./ChannelPreview";
@@ -68,6 +75,16 @@ export function DraftsView({
6875
const channels = list.channels;
6976
const [limit, setLimit] = useState(50);
7077
const [confirmDelete, setConfirmDelete] = useState(false);
78+
const deleteTrigger = useRef<HTMLButtonElement>(null);
79+
const deleteConfirm = useRef<HTMLButtonElement>(null);
80+
const deleteFocus = useRef<"confirm" | "trigger" | undefined>(undefined);
81+
useLayoutEffect(() => {
82+
const target = deleteFocus.current;
83+
deleteFocus.current = undefined;
84+
if (target === "confirm" && confirmDelete) deleteConfirm.current?.focus();
85+
else if (target === "trigger" && !confirmDelete)
86+
deleteTrigger.current?.focus();
87+
}, [confirmDelete]);
7188
const [error, setError] = useState<string>();
7289
const active = entries.find((entry) => entry.key === selected);
7390
const channelFor = (channelId: string) =>
@@ -372,7 +389,11 @@ export function DraftsView({
372389
<Button
373390
size="sm"
374391
variant="destructive"
375-
onClick={() => setConfirmDelete(true)}
392+
ref={deleteTrigger}
393+
onClick={() => {
394+
deleteFocus.current = "confirm";
395+
setConfirmDelete(true);
396+
}}
376397
>
377398
Delete draft…
378399
</Button>
@@ -381,13 +402,21 @@ export function DraftsView({
381402
<span className="text-body">
382403
Delete this saved draft on this device?
383404
</span>
384-
<Button size="sm" variant="destructive" onClick={remove}>
405+
<Button
406+
ref={deleteConfirm}
407+
size="sm"
408+
variant="destructive"
409+
onClick={remove}
410+
>
385411
Delete draft
386412
</Button>
387413
<Button
388414
size="sm"
389415
variant="ghost"
390-
onClick={() => setConfirmDelete(false)}
416+
onClick={() => {
417+
deleteFocus.current = "trigger";
418+
setConfirmDelete(false);
419+
}}
391420
>
392421
Cancel
393422
</Button>

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,3 +2022,26 @@ it("a two-step read retries its rejected thread prefix without losing the saved
20222022
);
20232023
expect(h.journal()?.state.frontiers[`msg:${root.id}`]).toBe(30);
20242024
});
2025+
2026+
it("hands keyboard focus into draft deletion and back on cancel without changing the saved draft", async () => {
2027+
const h = fixture({ withWriter: true });
2028+
writeView(h.owner.session.scope, "draft:room", "Keep this draft");
2029+
render(h.view);
2030+
await screen.findByText("Please review this");
2031+
const user = userEvent.setup();
2032+
await user.click(screen.getByRole("button", { name: "Drafts" }));
2033+
await user.click(
2034+
screen.getByRole("button", { name: "Open draft for #Design" }),
2035+
);
2036+
const trigger = screen.getByRole("button", { name: "Delete draft…" });
2037+
trigger.focus();
2038+
await user.keyboard("{Enter}");
2039+
expect(screen.getByRole("button", { name: "Delete draft" })).toHaveFocus();
2040+
await user.tab();
2041+
expect(screen.getByRole("button", { name: "Cancel" })).toHaveFocus();
2042+
await user.keyboard("{Enter}");
2043+
expect(screen.getByRole("button", { name: "Delete draft…" })).toHaveFocus();
2044+
expect(readView(h.owner.session.scope, "draft:room", "")).toBe(
2045+
"Keep this draft",
2046+
);
2047+
});

‎src/bundled/inbox/InboxPage.tsx‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,14 @@ export function InboxView({
448448
</Button>
449449
}
450450
/>
451+
{!drafts && failure && (
452+
<div className={styles.notice} role="alert">
453+
<p className="text-body">{failure}</p>
454+
<Button size="sm" disabled={pending} onClick={retry}>
455+
Retry inbox
456+
</Button>
457+
</div>
458+
)}
451459
<div
452460
className={styles.workspace}
453461
data-selected={(!drafts && !!selected) || undefined}
@@ -496,14 +504,6 @@ export function InboxView({
496504
/>
497505
) : (
498506
<div className={styles.scroll}>
499-
{failure && (
500-
<div className={styles.notice} role="alert">
501-
<p className="text-body">{failure}</p>
502-
<Button size="sm" disabled={pending} onClick={retry}>
503-
Retry inbox
504-
</Button>
505-
</div>
506-
)}
507507
{inbox.freshness === "stale" && !failure && (
508508
<div className={styles.notice} role="status">
509509
<span className="text-body text-subtle">

‎src/features/relay/inbox-feed.test.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,53 @@ it.each([false, true])(
401401
expect(notify).not.toHaveBeenCalled();
402402
},
403403
);
404+
405+
it("reprojects retained nonchat candidates after joining from an empty admitted snapshot without another feed read", async () => {
406+
const h = setup();
407+
h.live.receive([
408+
roster(h.relay, "room", [h.alice.pubkey], 10),
409+
metadata(h.relay, "room", "Room", 10, [["public"]]),
410+
]);
411+
const issue = signed(h.alice, {
412+
kind: 1621,
413+
content: "Addressed issue",
414+
created_at: 20,
415+
tags: [
416+
["h", "room"],
417+
["p", h.viewer.pubkey],
418+
],
419+
});
420+
const approval = signed(h.alice, {
421+
kind: 46010,
422+
content: "Approval",
423+
created_at: 21,
424+
tags: [
425+
["h", "room"],
426+
["p", h.viewer.pubkey],
427+
],
428+
});
429+
const work = h.session.inboxFeed.ensure();
430+
(await take(h, 9)).resolve([issue]);
431+
(await take(h, 46010)).resolve([approval]);
432+
await work;
433+
expect(h.session.inboxFeed.snapshot()).toMatchObject({
434+
status: "ready",
435+
mentions: [],
436+
needsAction: [],
437+
});
438+
const reads = h.query.mock.calls.filter(([filters]) =>
439+
filters.some((f) => f.kinds?.includes(46010) || f.kinds?.includes(9)),
440+
).length;
441+
h.admit([h.viewer.pubkey, h.alice.pubkey], 30);
442+
expect(h.session.inboxFeed.snapshot()).toMatchObject({
443+
status: "ready",
444+
mentions: [issue],
445+
needsAction: [approval],
446+
});
447+
await h.session.inboxFeed.ensure();
448+
expect(
449+
h.query.mock.calls.filter(([filters]) =>
450+
filters.some((f) => f.kinds?.includes(46010) || f.kinds?.includes(9)),
451+
).length,
452+
).toBe(reads);
453+
});

‎src/features/relay/inbox-feed.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function createInboxFeed({
6565
});
6666
const listeners = new Set<() => void>();
6767
const stopChannels = channels.subscribeList(() => {
68-
if (snapshot.mentions.length || snapshot.needsAction.length) publish({});
68+
if (rawMentions.length || rawActions.length) publish({});
6969
});
7070
const admitted = (event: RelayEvent) => {
7171
if (!event.tags.some(([name, value]) => name === "p" && value === viewer))

‎tests/browser/inbox.spec.mjs‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,3 +754,91 @@ test.describe("Inbox session reply admission", () => {
754754
]);
755755
});
756756
});
757+
758+
// Browser-only: CSS hides the list at this width. Real IndexedDB rejection must
759+
// remain visible/retryable while the selected detail is mounted, not just in DOM.
760+
test("narrow selected detail keeps a rejected read save and its captured Retry visible", async ({
761+
page,
762+
app,
763+
}) => {
764+
await page.setViewportSize({ width: 390, height: 844 });
765+
await page.addInitScript(() => {
766+
const put = IDBObjectStore.prototype.put;
767+
window.inboxReadFailure = { armed: false, failures: 0, saves: 0 };
768+
IDBObjectStore.prototype.put = function (value, ...args) {
769+
if (
770+
this.name === "partitions" &&
771+
this.transaction.db.name === "buzz-read-state-v1"
772+
) {
773+
if (
774+
window.inboxReadFailure.armed &&
775+
Object.keys(value?.state?.frontiers ?? {}).length
776+
) {
777+
window.inboxReadFailure.failures++;
778+
throw new Error("Synthetic read storage failure");
779+
}
780+
this.transaction.addEventListener(
781+
"complete",
782+
() => {
783+
window.inboxReadFailure.saves++;
784+
},
785+
{ once: true },
786+
);
787+
}
788+
return put.call(this, value, ...args);
789+
};
790+
});
791+
await open(page, app);
792+
await page
793+
.getByRole("button", { name: "Show navigation", exact: true })
794+
.click();
795+
await page.getByRole("button", { name: "Inbox", exact: true }).click();
796+
const inbox = page.getByRole("region", { name: "Inbox", exact: true });
797+
await expect(inbox.getByText("Checking recent activity…")).toHaveCount(0);
798+
await inbox.getByRole("combobox", { name: "Activity type" }).click();
799+
await page.getByRole("option", { name: "Mentions", exact: true }).click();
800+
const row = inbox
801+
.getByRole("list", { name: "Inbox conversations" })
802+
.getByRole("listitem")
803+
.first();
804+
await expect(row.getByRole("img", { name: "Unread" })).toBeVisible();
805+
await page.evaluate(() => {
806+
window.inboxReadFailure.armed = true;
807+
});
808+
try {
809+
await row.getByRole("button", { name: /^Open / }).click();
810+
const detail = inbox.getByRole("complementary", {
811+
name: "Thread",
812+
exact: true,
813+
});
814+
await expect(detail).toBeVisible();
815+
const alert = inbox
816+
.getByRole("alert")
817+
.filter({ hasText: "Synthetic read storage failure" });
818+
await expect(alert).toBeVisible();
819+
await expect(
820+
alert.getByRole("button", { name: "Retry inbox" }),
821+
).toBeInViewport();
822+
await expect(
823+
inbox.getByRole("list", { name: "Inbox conversations" }),
824+
).not.toBeVisible();
825+
const saves = await page.evaluate(() => {
826+
window.inboxReadFailure.armed = false;
827+
return window.inboxReadFailure.saves;
828+
});
829+
await alert.getByRole("button", { name: "Retry inbox" }).click();
830+
await expect(alert).toHaveCount(0);
831+
await expect
832+
.poll(() => page.evaluate(() => window.inboxReadFailure.saves))
833+
.toBeGreaterThan(saves);
834+
await expect(detail).toBeVisible();
835+
await detail
836+
.getByRole("button", { name: "Close thread", exact: true })
837+
.click();
838+
await expect(row.getByRole("img", { name: "Unread" })).toHaveCount(0);
839+
} finally {
840+
await page.evaluate(() => {
841+
window.inboxReadFailure.armed = false;
842+
});
843+
}
844+
});

‎tests/browser/layout.spec.mjs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,14 @@ test("Projects directory fits the workspace and page navigation survives plugin
898898
// Header search owns page navigation, including while narrow Settings
899899
// collapses the sidebar; its Pages group must preserve plugin ordering.
900900
const search = page.getByRole("dialog", { name: "Search Buzz", exact: true });
901-
const titles = ["Messages", "Projects", "Agents", "Sessions", "Workflows"];
901+
const titles = [
902+
"Messages",
903+
"Projects",
904+
"Agents",
905+
"Inbox",
906+
"Sessions",
907+
"Workflows",
908+
];
902909
const expectPageOrder = async (expected) => {
903910
const choices = await pageChoices(page);
904911
await expect(choices.getByRole("option")).toHaveText([
@@ -971,7 +978,13 @@ test("Projects directory fits the workspace and page navigation survives plugin
971978
});
972979
await projects.click();
973980
await expect(projects).toHaveAttribute("aria-checked", "false");
974-
await expectPageOrder(["Messages", "Agents", "Sessions", "Workflows"]);
981+
await expectPageOrder([
982+
"Messages",
983+
"Agents",
984+
"Inbox",
985+
"Sessions",
986+
"Workflows",
987+
]);
975988
await closeSearch();
976989
await projects.click();
977990
await expect(projects).toHaveAttribute("aria-checked", "true");

‎tests/browser/sidenav-polish.spec.mjs‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ test("shell toggle restores the shared sidebar for Channels and Agents", async (
555555
});
556556

557557
// A real grid/overlay measurement is needed: DOM presence misses implicit columns.
558-
test("placeholder destinations retain companion layout across navigation and resize", async ({
558+
test("Inbox and placeholder destinations retain companion layout across navigation and resize", async ({
559559
page,
560560
app,
561561
}) => {
@@ -570,12 +570,12 @@ test("placeholder destinations retain companion layout across navigation and res
570570
name: "Conversation",
571571
exact: true,
572572
});
573-
const checkGeometry = async (overlay) => {
573+
const checkGeometry = async (overlay, surface = conversation) => {
574574
await expect(companion).toBeVisible();
575575
await expect
576576
.poll(async () => {
577577
const card = await companion.boundingBox();
578-
const body = await conversation.boundingBox();
578+
const body = await surface.boundingBox();
579579
if (!card || !body) return false;
580580
return overlay
581581
? Math.abs(card.x + card.width - body.x - body.width) < 2 &&
@@ -603,7 +603,10 @@ test("placeholder destinations retain companion layout across navigation and res
603603
await page.setViewportSize({ width, height: 950 });
604604
await selectChannel("Inbox");
605605
await launcher.click();
606-
await checkGeometry(width <= 1000);
606+
await checkGeometry(
607+
width <= 1000,
608+
page.getByRole("region", { name: "Inbox", exact: true }),
609+
);
607610
await selectChannel("Bestie");
608611
await expect(
609612
conversation.getByRole("heading", { name: "Bestie", exact: true }),
@@ -614,7 +617,10 @@ test("placeholder destinations retain companion layout across navigation and res
614617
await selectChannel("Alpha");
615618
await launcher.click();
616619
await selectChannel("Inbox");
617-
await checkGeometry(width <= 1000);
620+
await checkGeometry(
621+
width <= 1000,
622+
page.getByRole("region", { name: "Inbox", exact: true }),
623+
);
618624
await launcher.click();
619625
}
620626
});

0 commit comments

Comments
 (0)