#14
Fix live mail state persistence
Summary
- persist thread read and unread state through JMAP, including marking a conversation read when it is opened
- report accurate mailbox totals and serialize sidebar count reads to stay within Stalwart's JMAP concurrency limit
- persist archive actions and update Inbox, Unread, and Archived counts optimistically with rollback
- sign out through Better Auth in live mode while preserving the demo flow
- prevent reply shortcuts from entering their key and preserve list queries when closing a conversation tab
Validation
- live-provider dogfood: compose/send, open unread, manual read/unread, archive, search, filter, sort, keyboard compose/reply/navigation, tab close, sign out, and hard-refresh persistence
pnpm test(28 passing)pnpm exec tsc --noEmit- focused ESLint on every changed TypeScript/TSX file
pnpm buildgit diff origin/main --check
Existing repository lint findings
pnpm lint still reports the three pre-existing errors in babel.config.js, postcss.config.js, and components/shell/login-screen.tsx; the changed files pass focused ESLint.
Activity
7mikeyreviewed3mo ago
Addressed the workspace-tab URL-base nit in 0d2a373.
Both URL parsing paths now use one shared neutral http://localhost base, so the helper no longer introduces an extra project-specific hostname and the origin guard stays consistent.
Validated on the updated head with:
pnpm test(28 passing)pnpm exec tsc --noEmitpnpm exec eslint lib/mail/workspace-tabs.tsgit diff origin/main --check
a0e863f into main3mo ago
Review summary
Traced the full mail-state-persistence flow end to end: the new
PATCH /api/mail/threads/[id]endpoint, bothMailProviderimplementations (lib/demo/provider.ts,lib/stalwart/provider.ts), the new JMAP calls inlib/stalwart/client.ts(setEmailsSeen,moveEmails,createMailbox), the optimistic-update/rollback logic incomponents/mail/thread-list.tsxandcomponents/shell/app-shell.tsx(adjustArchiveCounts,adjustUnreadCounts, auto-mark-read effect), and the sidebar count serialization inlib/mail/folder-counts.ts.Specifically checked for:
setThreadUnread/archiveThreadon the Stalwart provider resolve IDs throughmailboxClient(user), the same per-user-scoped JMAP session used by the existinggetThread/listThreadsmethods — no new cross-tenant exposure.fromFolder: the archive endpoint trustsfromFolderfrom the request body to pick a source mailbox, but the actual emails moved are filtered by realmailboxIdsmembership from the server, so a mismatched/maliciousfromFolderjust yields an empty move (returns 404) rather than moving the wrong messages.adjustArchiveCountsandcollectFolderCountsthrough the inbox/smart/archived cases (read vs. unread, archiving from the Unread view vs. a named folder) — the delta math is correct, including decrementing the Unread badge only when an unread inbox thread is archived.calculateTotal: trueand the addedmailboxIdsproperty fetch are actually required for the new total-count and archive-by-membership logic to work — no dangling additions.updatingref inThreadListprevents duplicate in-flight mutations per thread;collectFolderCountswas correctly switched fromPromise.allto a serial loop to respect Stalwart's 4-connection JMAP limit (also covered by the newdoes not fan out provider requeststest).No blocking correctness or security issues found in this pass. One non-blocking nit left inline.
Follow-up worth considering (non-blocking): there's no unit test directly covering
adjustArchiveCounts/adjustUnreadCounts(the sidebar-count reducer inapp-shell.tsx) or the newPATCHroute handler itself — the provider-levelsetThreadUnread/archiveThreadandthread-state.tshelpers are tested, but the count arithmetic and request-validation branches in between aren't. Not required for this PR given the described manual dogfooding, but a small unit test onadjustArchiveCountswould guard against a silent regression in the badge math.