diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58855d5..f4bf833 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,8 @@ jobs: - run: bun install --frozen-lockfile - name: Type-check, lint, format check run: bun run check + - name: Tests + run: bun run test rust: name: Rust (${{ matrix.os }}) diff --git a/AGENTS.md b/AGENTS.md index acec01b..5b37892 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,7 +4,7 @@ Tightbeam is private chat between two people on the same LAN: a Rust backend (Ta ## Done -- A change is done when the checks in `.github/workflows/ci.yml` pass locally: the UI check from the project root, and fmt, clippy and tests in `src-tauri/`. +- A change is done when the checks in `.github/workflows/ci.yml` pass locally: the UI check and tests from the project root (`bun run check`, `bun run test`), and fmt, clippy and tests in `src-tauri/`. - A protocol change gets a test in `src-tauri/src/chat/protocol_tests.rs`, which runs two engines on an in-memory network with paused time. - A change people will notice also gets a line under `## Unreleased` in `CHANGELOG.md`. That section becomes the release text. - Commit messages and PR titles follow Conventional Commits (`feat:`, `fix:`, `refactor:`, `docs:`, `chore:` โ€ฆ). PRs squash-merge, so the title becomes the commit on `main`. diff --git a/CHANGELOG.md b/CHANGELOG.md index ad27fce..2ad9070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Changes people using Tightbeam will notice. Add a line under **Unreleased** as t ## Unreleased +- Clicking the quote in a reply jumps to the original message even when it's further back than the history loaded so far. Before, it did nothing until you'd scrolled back that far. +- A reply quoting a vanishing message shows "Message vanished" as soon as it vanishes, instead of "Deleted message" until the app restarts. + ## 0.7.0 โ€” 2026-11-24 - Pictures: paste a screenshot, drop pictures on the window, or pick them with the new button beside the message box, with an optional caption. Click one to see it full size, open it, save a copy, or show it in its folder. Pictures can be up to 1 GB, and a transfer that's interrupted picks up where it stopped. Both computers need this version or later. diff --git a/GLOSSARY.md b/GLOSSARY.md index 4124b94..639571f 100644 --- a/GLOSSARY.md +++ b/GLOSSARY.md @@ -43,3 +43,7 @@ _Avoid_: ignored entry, unknown entry **Message**: What the transcript shows for a message entry: its current text with later edits, deletes and reactions folded in. _Avoid_: entry (when meaning the shown result), post + +**Transcript**: +The messages shown, in display order, as far back as they're loaded. Older ones load as the reader scrolls up, or when a search hit or a reply's quote reaches back to them. +_Avoid_: chat log, history (for what's shown), feed diff --git a/README.md b/README.md index 4803918..61959a3 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Windows and macOS. Rust + [Tauri](https://tauri.app) for the app, [iroh](https:/ ```text ui/src/api.ts typed wrappers for the Rust commands, plus the shared types ui/src/store.ts app state (TanStack Store), fed by events from Rust; history paging +ui/src/transcript.ts the transcript: what a page, a live message or an update does to it ui/src/commands.ts slash commands ui/src/components/ the screens: Setup, Pair, Chat, Search, Files, PairDialog, Notice ui/src/components/ui/ shadcn/ui components (generated; update with the shadcn CLI) @@ -71,6 +72,7 @@ For the TypeScript, from the project root: ```powershell bun run check # type-check, lint (oxlint), format check (oxfmt), Markdown lint +bun run test # the UI's tests (bun test) bun run fmt # format ``` diff --git a/bun.lock b/bun.lock index 5f5720d..46691c1 100644 --- a/bun.lock +++ b/bun.lock @@ -23,6 +23,7 @@ "devDependencies": { "@tailwindcss/vite": "^4.3.5", "@tauri-apps/cli": "^2.12.6", + "@types/bun": "^1.4.5", "@types/node": "^26.6.6", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", @@ -348,6 +349,8 @@ "@tybys/wasm-util": ["@tybys/wasm-util@0.10.5", "", { "dependencies": { "tslib": "^2.4.0" } }, "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA=="], + "@types/bun": ["@types/bun@1.4.5", "", { "dependencies": { "bun-types": "1.4.5" } }, "sha512-DpgwNI9z0L1S0gtb45QLCWgwCUcMLnsHYMJHQvpNj7erGiCGBvpggltAIeARrtobNMKMuy0UP7i56tKKgwFs/Q=="], + "@types/debug": ["@types/debug@4.1.13", "", { "dependencies": { "@types/ms": "*" } }, "sha512-KSVgmQmzMwPlmtljOomayoR89W4FynCAi3E8PPs7vmDVPe84hT+vGPKkJfThkmXs0x0jAaa9U8uW8bbfyS2fWw=="], "@types/katex": ["@types/katex@0.16.8", "", {}, "sha512-trgaNyfU+Xh2Tc+ABIb44a5AYUpicB3uwirOioeOkNPPbmgRNtcWyDeeFRzjPZENO9Vq8gvVqfhaaXWLlevVwg=="], @@ -430,6 +433,8 @@ "browserslist": ["browserslist@4.29.6", "", { "dependencies": { "baseline-browser-mapping": "^2.11.37", "caniuse-lite": "^1.0.30001826", "electron-to-chromium": "^1.5.486", "node-releases": "^2.0.64", "update-browserslist-db": "^1.4.0" }, "bin": { "browserslist": "cli.js" } }, "sha512-CmVVIQ3RVc5HxYEc9X84GvxK/C8C1wH8TlKAiO7uTxF8PDwt7r8t9Qk3J9NkMOVzX5O/HbLv3yzxZg9HPrnI9w=="], + "bun-types": ["bun-types@1.4.5", "", { "dependencies": { "@types/node": "*", "undici-types": "*" } }, "sha512-ECHn+9dhL3wv0G6u0+7dQvrnaimXiRDxxerYBmhTaLyJEEuvTPWk2Fye3XIf5Y++JIIiHKfQw4Z7V5D8KuiXbg=="], + "bundle-name": ["bundle-name@4.1.1", "", { "dependencies": { "run-applescript": "^7.0.0" } }, "sha512-DdH81/zPLVS11EUgWq3tEu/xn+EzljlMYooDNdzWEnFha3R3NBMpMV1UqYIpjYHV/SgpFKMIX1Oh7o06SjM/oA=="], "caniuse-lite": ["caniuse-lite@1.0.30001826", "", {}, "sha512-wTB+9tIbLro/BCXwLuNV1meHE4L9dS6dArMDwgYfNBPMYScqClHyGunhkCSDtHhe/69Xl0sHlKgBVZ+fNsYtWA=="], diff --git a/package.json b/package.json index c869c1c..2a7f732 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "fmt:check": "oxfmt --check ui vite.config.ts", "lint:md": "markdownlint-cli2", "check": "tsc --noEmit && oxlint && oxfmt --check ui vite.config.ts && markdownlint-cli2", + "test": "bun test ui", "tauri": "tauri" }, "dependencies": { @@ -31,6 +32,7 @@ "devDependencies": { "@tailwindcss/vite": "^4.3.5", "@tauri-apps/cli": "^2.12.6", + "@types/bun": "^1.4.5", "@types/node": "^26.6.6", "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", diff --git a/src-tauri/src/db.rs b/src-tauri/src/db.rs index a62b226..2e7ad44 100644 --- a/src-tauri/src/db.rs +++ b/src-tauri/src/db.rs @@ -89,6 +89,9 @@ pub struct Message { pub struct Quote { pub author: String, pub seq: u64, + /// Its place in display order, to load the history back to it. `None` when it isn't + /// stored here. + pub hlc: Option, /// Its latest text. `None` when it isn't stored here (cleared, for example) or was /// deleted. pub text: Option, @@ -647,7 +650,7 @@ impl Db { /// Adds a message's current text, and its file's name, to the search index, unless /// it was deleted. fn index(&self, at: &Ref) -> Result<()> { - let Some(original) = self.original(at)? else { return Ok(()) }; + let Some((original, _)) = self.original(at)? else { return Ok(()) }; let current = self.current(at, original)?; if !current.deleted && !self.vanished(at)? { let text = match self.file_of(at)? { @@ -674,14 +677,14 @@ impl Db { Ok(json.flatten().and_then(|j| serde_json::from_str(&j).ok())) } - /// A message's text as first sent, if it's stored here. - fn original(&self, at: &Ref) -> Result> { + /// A message's text as first sent, and its place in display order, if it's stored here. + fn original(&self, at: &Ref) -> Result> { Ok(self .0 .prepare_cached( - "SELECT text FROM messages WHERE author = ?1 AND seq = ?2 AND kind = 'message'", + "SELECT text, hlc FROM messages WHERE author = ?1 AND seq = ?2 AND kind = 'message'", )? - .query_row(params![at.author, at.seq as i64], |r| r.get(0)) + .query_row(params![at.author, at.seq as i64], |r| Ok((r.get(0)?, r.get(1)?))) .optional()?) } @@ -726,12 +729,15 @@ impl Db { } let reply_to = match reply_to { Some(to) => { - let quoted = self.original(&to)?.map(|text| self.current(&to, text)).transpose()?; + let stored = self.original(&to)?; + let hlc = stored.as_ref().map(|(_, hlc)| *hlc); + let quoted = stored.map(|(text, _)| self.current(&to, text)).transpose()?; let vanished = self.vanished(&to)?; let deleted = vanished || quoted.as_ref().is_some_and(|q| q.deleted); let text = quoted.filter(|_| !deleted).map(|q| q.text); let file = if deleted { None } else { self.file_of(&to)? }; - Some(Quote { author: to.author, seq: to.seq, text, deleted, vanished, file }) + let (author, seq) = (to.author, to.seq); + Some(Quote { author, seq, hlc, text, deleted, vanished, file }) } None => None, }; @@ -916,7 +922,7 @@ mod tests { assert_eq!(messages.len(), 2, "reactions aren't messages"); assert_eq!(messages[0].reactions, [Reaction { author: "peer".into(), emoji: "๐Ÿ˜‚".into() }]); let quote = messages[1].reply_to.as_ref().unwrap(); - assert_eq!(quote.text.as_deref(), Some("me1")); + assert_eq!((quote.text.as_deref(), quote.hlc), (Some("me1"), Some(1))); assert_eq!(db.page(None, 10).unwrap().messages, messages); // Reactions sync and count like messages. @@ -926,7 +932,8 @@ mod tests { // A reply to a message that isn't here any more. db.clear("me", None).unwrap(); db.insert(&reply("peer", 4, ("me", 1))).unwrap(); - assert_eq!(db.all().unwrap()[0].reply_to.as_ref().unwrap().text, None); + let gone = db.all().unwrap()[0].reply_to.clone().unwrap(); + assert_eq!((gone.text, gone.hlc), (None, None), "nowhere to jump to"); } #[test] diff --git a/tsconfig.json b/tsconfig.json index 193fde1..541aecb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "moduleResolution": "bundler", "lib": ["ES2022", "DOM", "DOM.Iterable"], "jsx": "react-jsx", - "types": ["vite/client", "node"], + "types": ["vite/client", "node", "bun"], "paths": { "@/*": ["./ui/src/*"] }, "strict": true, "noEmit": true, diff --git a/ui/src/api.ts b/ui/src/api.ts index 0ae4cd6..e002ae8 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -64,6 +64,8 @@ export interface Ref { /** The message a reply answers. */ export interface Quote extends Ref { + /** Its place in display order, to load the history back to it. `null` when it isn't on this computer. */ + hlc: number | null /** Its latest text. `null` when it isn't on this computer (cleared) or was deleted. */ text: string | null /** Deleted, or vanished. */ diff --git a/ui/src/components/Chat.tsx b/ui/src/components/Chat.tsx index c1fb48c..53ce8ba 100644 --- a/ui/src/components/Chat.tsx +++ b/ui/src/components/Chat.tsx @@ -11,7 +11,7 @@ import { Trash2Icon, XIcon, } from 'lucide-react' -import { memo, useCallback, useEffect, useRef, useState } from 'react' +import { memo, useEffect, useRef, useState } from 'react' import { api, type Message as ChatMessage, type Quote, type Reaction } from '@/api' import { type Command, parse, suggest } from '@/commands' @@ -55,8 +55,8 @@ import { addMessage, clearHistory, loadOlder, - messageKey, openSearch, + reveal, run, setDeleting, setEditing, @@ -65,6 +65,7 @@ import { store, unstageFile, } from '@/store' +import { indexOf, messageKey, targetOf } from '@/transcript' /** The reactions on offer. */ const EMOJI = ['๐Ÿ‘', 'โค๏ธ', '๐Ÿ˜‚', '๐Ÿ˜ฎ', '๐Ÿ˜ข', '๐ŸŽ‰'] @@ -195,8 +196,8 @@ function Transcript() { useSelector( store, (s) => ({ - messages: s.messages, - hasOlder: s.hasOlder, + messages: s.transcript.messages, + hasOlder: s.transcript.hasOlder, loadingOlder: s.loadingOlder, myId: s.status?.me.id ?? '', myName: s.status?.me.name || 'You', @@ -301,29 +302,15 @@ function VirtualTranscript({ return () => clearTimeout(timer) }, [highlighted]) - // Stable for the memoized rows: reads the latest messages through a ref. - const messagesRef = useRef(messages) - messagesRef.current = messages const jump = useSelector(store, (s) => s.jump) useEffect(() => { if (!jump) return - const index = messagesRef.current.findIndex((m) => messageKey(m) === jump.key) + const index = indexOf(store.state.transcript, jump.at) if (index < 0) return virtualizer.scrollToIndex(index, { align: 'center' }) - setHighlighted(jump.key) + setHighlighted(messageKey(jump.at)) }, [jump, virtualizer]) - const jumpTo = useCallback( - (quote: Quote) => { - const key = messageKey(quote) - const index = messagesRef.current.findIndex((m) => messageKey(m) === key) - if (index < 0) return // not loaded: older than what's paged in, or cleared - virtualizer.scrollToIndex(index, { align: 'center' }) - setHighlighted(key) - }, - [virtualizer], - ) - return ( ) @@ -573,6 +560,12 @@ function DayMarker({ when }: { when: Date }) { ) } +/** Jumps from a reply to the message it quotes, if it's on this computer. */ +function jumpToQuote(quote: Quote) { + const target = targetOf(quote) + if (target) void reveal(target) +} + /** The message a reply answers, at the top of its bubble. Click to jump to it. */ function QuoteButton({ quote, @@ -930,7 +923,7 @@ function Composer() { } // Up in an empty box edits my last message. if (e.key === 'ArrowUp' && !text && !editing) { - const last = lastOfMine(store.state.messages, myId) + const last = lastOfMine(store.state.transcript.messages, myId) if (last) { e.preventDefault() setEditing(last) diff --git a/ui/src/components/Search.tsx b/ui/src/components/Search.tsx index f3ac0b5..6caa667 100644 --- a/ui/src/components/Search.tsx +++ b/ui/src/components/Search.tsx @@ -10,6 +10,7 @@ import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Spinner } from '@/components/ui/spinner' import { closeSearch, reveal, setSearchActive, setSearchQuery, store } from '@/store' +import { messageKey } from '@/transcript' /** Matches past this many aren't shown (see SEARCH_LIMIT in chat.rs). */ const LIMIT = 100 @@ -98,7 +99,7 @@ export function SearchResults() { <>
    {hits.map((hit, i) => ( -
  • +