Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
```

Expand Down
5 changes: 5 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
25 changes: 16 additions & 9 deletions src-tauri/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i64>,
/// Its latest text. `None` when it isn't stored here (cleared, for example) or was
/// deleted.
pub text: Option<String>,
Expand Down Expand Up @@ -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)? {
Expand All @@ -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<Option<String>> {
/// A message's text as first sent, and its place in display order, if it's stored here.
fn original(&self, at: &Ref) -> Result<Option<(String, i64)>> {
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()?)
}

Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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.
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
37 changes: 15 additions & 22 deletions ui/src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -55,8 +55,8 @@ import {
addMessage,
clearHistory,
loadOlder,
messageKey,
openSearch,
reveal,
run,
setDeleting,
setEditing,
Expand All @@ -65,6 +65,7 @@ import {
store,
unstageFile,
} from '@/store'
import { indexOf, messageKey, targetOf } from '@/transcript'

/** The reactions on offer. */
const EMOJI = ['👍', '❤️', '😂', '😮', '😢', '🎉']
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 (
<MessageScroller className="flex-1">
<MessageScrollerViewport
Expand Down Expand Up @@ -355,7 +342,7 @@ function VirtualTranscript({
groupStart={!prev || !sameGroup(prev, m)}
groupEnd={!next || !sameGroup(m, next)}
highlighted={highlighted === item.key}
onJump={jumpTo}
onJump={jumpToQuote}
/>
</div>
)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion ui/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,7 +99,7 @@ export function SearchResults() {
<>
<ul ref={listRef} className="p-2">
{hits.map((hit, i) => (
<li key={`${hit.message.author}:${hit.message.seq}`}>
<li key={messageKey(hit.message)}>
<button
type="button"
className={`block w-full rounded-md px-3 py-2 text-left ${i === active ? 'bg-accent text-accent-foreground' : ''}`}
Expand Down
Loading
Loading