From 789b550301e47f223af7dc3ad4e01e3694baaa73 Mon Sep 17 00:00:00 2001 From: Mateusz Pstrucha Date: Wed, 23 Sep 2026 15:32:35 +0200 Subject: [PATCH] Add Junk, spam actions and infinite scroll MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Junk joins the system views; Report spam / Not spam come from the toolbar, menu and `!`; messages show their spam score as a badge. Rules gains an Add spam filter preset — score over 5 → Junk, placed first and stopping later rules — and the editor offers only numeric comparisons for spam score. Conversation lists now load older pages. The list previously only ever showed the newest 50 conversations, leaving older mail unreachable even though the API returned a cursor. Pages load as the end scrolls into view, when j walks past the end, or via a Load older button that also covers keyboard use. Refreshing after an action re-reads as many rows as were loaded, so a deep scroll doesn't collapse back to one page. Co-Authored-By: Claude Opus 5.5 --- README.md | 8 +++--- src/lib/ActionMenu.svelte | 8 +++++- src/lib/MailShell.svelte | 49 +++++++++++++++++++++++++++++++++++-- src/lib/RuleEditor.svelte | 16 +++++++++--- src/lib/RulesView.svelte | 34 +++++++++++++++++++++++-- src/lib/ShortcutHelp.svelte | 1 + src/lib/ThreadList.svelte | 38 ++++++++++++++++++++++++++++ src/lib/ThreadView.svelte | 17 +++++++++++++ src/lib/api.ts | 16 ++++++++---- 9 files changed, 171 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index afb581a..40979bc 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Desktop webapp client for [Tern](../) — see [`docs/webapp-client-spec.md`](docs/webapp-client-spec.md) and [`docs/branding-spec.md`](docs/branding-spec.md). -**Status: mail client with organisation** (build order phases 3–5). What's here: +**Status: mail client with organisation and spam handling** (build order phases 3–6). What's here: - Vite + Svelte 5 + TypeScript, no other runtime dependencies, per the spec's "fast and simple" priority (§1) and browser-API-only approach (§5). - The decided color palette wired up as CSS custom properties with `data-theme` light/dark/system switching (§4). @@ -13,11 +13,13 @@ Desktop webapp client for [Tern](../) — see [`docs/webapp-client-spec.md`](doc - **Compose, reply and reply-all** in a native ``, with drafts. Replying to your own sent message addresses the people you wrote to, not yourself. `Ctrl+Enter` sends. - **Outbox** view for drafts, queued and failed messages, showing retry timing and the last error, with Retry/Delete for failures. - Opening a conversation marks it read. -- **Views, folders and tags** in the sidebar (Inbox, All mail, Sent, Outbox, Trash, your folders, your tags), with tag chips on list rows. +- **Views, folders and tags** in the sidebar (Inbox, All mail, Sent, Outbox, Junk, Trash, your folders, your tags), with tag chips on list rows. +- **Conversation lists load older pages as you scroll** (or press `j` past the end), with a *Load older* button as a keyboard-reachable fallback. +- **Spam** — *Report spam* / *Not spam* (`!`), each message's spam score shown as a badge, and an **Add spam filter** preset in Rules. - **Conversation actions** — archive, delete/restore, mark read/unread, move, tag — from a toolbar, a right-click context menu (native Popover API, §5), or the keyboard. Keyboard actions apply to the row under the cursor when nothing is open, so mail can be triaged straight from the list. - **Rules editor** — conditions and actions edited as the structured JSON they're stored as, so anything the API accepts the editor can show. Each rule can stop later rules when it matches, and **Run now** applies it to existing mail. Server validation errors (e.g. a bad regex) appear inline without losing the form. - **Trash** shows when each conversation will be permanently deleted. -- **Keyboard shortcuts** (§4a): `j`/`k`, `Enter`/`o`, `u`/`Esc`, `g`/`G`, `e` archive, `#` delete/restore, `Shift+I`/`Shift+U` read/unread, `v`/`l` move/tag, `c`, `r`/`a`, `Shift+R`, `?`. +- **Keyboard shortcuts** (§4a): `j`/`k`, `Enter`/`o`, `u`/`Esc`, `g`/`G`, `e` archive, `#` delete/restore, `!` spam/not spam, `Shift+I`/`Shift+U` read/unread, `v`/`l` move/tag, `c`, `r`/`a`, `Shift+R`, `?`. - Polls `/events` while the tab is open, since WebSocket push is phase 7. - No PWA, no service worker, no offline cache — matches §2's explicit scope cut. diff --git a/src/lib/ActionMenu.svelte b/src/lib/ActionMenu.svelte index c99842d..543e0a5 100644 --- a/src/lib/ActionMenu.svelte +++ b/src/lib/ActionMenu.svelte @@ -50,6 +50,7 @@ } const inTrash = $derived(view.kind === 'trash'); + const inJunk = $derived(view.kind === 'junk'); const tagged = (id: string) => thread?.tag_ids.includes(id) ?? false; @@ -66,6 +67,11 @@ {:else} + {#if inJunk} + + {:else} + + {/if} {/if} {#if thread.unread_count > 0} @@ -75,7 +81,7 @@

Move to

- {#each folders as f (f.id)} + {#each folders.filter((f) => f.role !== 'junk') as f (f.id)} {/each} diff --git a/src/lib/MailShell.svelte b/src/lib/MailShell.svelte index 65d8b90..fc66462 100644 --- a/src/lib/MailShell.svelte +++ b/src/lib/MailShell.svelte @@ -45,6 +45,8 @@ let folders = $state([]); let tags = $state([]); let threads = $state([]); + let nextCursor = $state(null); + let loadingMore = $state(false); let outbox = $state([]); let section = $state<'mail' | 'outbox' | 'rules'>('mail'); let mailView = $state({ kind: 'inbox' }); @@ -71,6 +73,7 @@ case 'all': return 'All mail'; case 'sent': return 'Sent'; case 'trash': return 'Trash'; + case 'junk': return 'Junk'; case 'folder': { const id = mailView.id; return folders.find((f) => f.id === id)?.name ?? 'Folder'; } case 'tag': { const id = mailView.id; return tags.find((t) => t.id === id)?.name ?? 'Tag'; } } @@ -81,11 +84,20 @@ return !('id' in v) || ('id' in mailView && v.id === mailView.id); } + const PAGE = 50; + const MAX_PAGE = 200; + + /** + * Re-reads the list from the top. Asks for as many rows as are currently + * loaded (up to the API's cap), so refreshing after an action doesn't + * collapse a list the reader has scrolled deep into back to one page. + */ async function refresh() { error = null; try { - const page = await listThreads(mailView); + const page = await listThreads(mailView, undefined, Math.min(MAX_PAGE, Math.max(PAGE, threads.length))); threads = page.threads; + nextCursor = page.next_cursor; // Keep the open conversation's summary current (tags, counts), or // drop it if an action moved it out of this view. if (selected) selected = threads.find((t) => t.thread_id === selected!.thread_id) ?? null; @@ -97,6 +109,24 @@ } } + async function loadMore() { + if (!nextCursor || loadingMore) return; + loadingMore = true; + const view = mailView; + try { + const page = await listThreads(view, nextCursor, PAGE); + // The view may have changed while this was in flight. + if (view !== mailView) return; + const known = new Set(threads.map((t) => t.thread_id)); + threads = [...threads, ...page.threads.filter((t) => !known.has(t.thread_id))]; + nextCursor = page.next_cursor; + } catch (e) { + error = e instanceof Error ? e.message : 'failed to load older conversations'; + } finally { + loadingMore = false; + } + } + async function refreshMeta() { [folders, tags] = await Promise.all([listFolders(), listTags()]); } @@ -136,6 +166,8 @@ function showView(v: MailView) { section = 'mail'; mailView = v; + threads = []; + nextCursor = null; selected = null; activeIndex = 0; loading = true; @@ -274,6 +306,8 @@ case 'j': event.preventDefault(); activeIndex = Math.min(activeIndex + 1, threads.length - 1); + // Walking off the end with j pulls in the next page. + if (activeIndex >= threads.length - 5) loadMore(); break; case 'k': event.preventDefault(); @@ -322,6 +356,12 @@ act(t, [inTrash ? { type: 'restore' } : { type: 'delete' }]); } break; + case '!': + if (t && !inTrash) { + event.preventDefault(); + act(t, [mailView.kind === 'junk' ? { type: 'move', folder_id: null } : { type: 'junk' }]); + } + break; case 'I': if (t) { event.preventDefault(); @@ -369,13 +409,15 @@ Outbox {#if outboxCount > 0}{outboxCount}{/if} +
Folders
- {#each folders as f (f.id)} + + {#each folders.filter((f) => f.role !== 'junk') as f (f.id)}
+
+ {#if !hasSpamFilter} + + {/if} + +

Applied to new mail in this order; every matching rule runs unless one above it is set to stop. Run now applies a single rule to mail you already have — disabled rules included, so you can try one before switching it on. @@ -169,6 +195,10 @@ margin: 0; font-size: 1.1rem; } + .header-actions { + display: flex; + gap: 0.4rem; + } .hint, .empty, .error { diff --git a/src/lib/ShortcutHelp.svelte b/src/lib/ShortcutHelp.svelte index 361e0dd..185e7d6 100644 --- a/src/lib/ShortcutHelp.svelte +++ b/src/lib/ShortcutHelp.svelte @@ -18,6 +18,7 @@ ['g / G', 'Jump to first / last'], ['e', 'Archive'], ['#', 'Delete (restore, in Trash)'], + ['!', 'Report spam (not spam, in Junk)'], ['Shift+I / Shift+U', 'Mark read / unread'], ['v or l', 'Move or tag'], ['c', 'Compose'], diff --git a/src/lib/ThreadList.svelte b/src/lib/ThreadList.svelte index 2b27800..d830470 100644 --- a/src/lib/ThreadList.svelte +++ b/src/lib/ThreadList.svelte @@ -9,6 +9,9 @@ tags, onSelect, onContextMenu, + hasMore, + loadingMore, + onLoadMore, }: { threads: ThreadSummary[]; selectedId: string | null; @@ -17,8 +20,27 @@ onSelect: (thread: ThreadSummary, index: number) => void; /** Right-click on a row (§4a: context menus instead of a "…" per row). */ onContextMenu: (thread: ThreadSummary, index: number, x: number, y: number) => void; + hasMore: boolean; + loadingMore: boolean; + onLoadMore: () => void; } = $props(); + let sentinel = $state(null); + + // Infinite scroll: fetch the next page as the end of the list comes into + // view (with some margin, so it's usually there before it's needed). + $effect(() => { + if (!sentinel || !hasMore) return; + const observer = new IntersectionObserver( + (entries) => { + if (entries.some((e) => e.isIntersecting)) onLoadMore(); + }, + { root: listEl, rootMargin: '300px' }, + ); + observer.observe(sentinel); + return () => observer.disconnect(); + }); + const tagById = $derived(new Map(tags.map((t) => [t.id, t]))); function purgeText(at: string): string { @@ -79,6 +101,13 @@ {/if} {/each} + {#if hasMore} + + + {/if}