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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes people using Tightbeam will notice. Add a line under **Unreleased** as t

## Unreleased

- Replies, quotes and search show /me messages the way the conversation does ("Alex waves"), instead of the raw text. A quote of a deleted message says "Message deleted", as the message itself does.
- Send any file, not just pictures: pick files with the paperclip, or drop them on the window. Files up to 1 GB go straight from disk, so big ones don't slow the app down. Changing or moving the original afterwards doesn't affect what was sent. The other side needs version 0.7 or later.
- More kinds of received files open in their app with one click: PDFs, text and Office documents, audio and video, as well as pictures. Programs, scripts, web pages and archives can only be shown in their folder.
- After unpairing and pairing with someone new, they get only the messages written from then on. Before, they also received every message sent to the previous person. Editing or deleting those older messages stays on your computer.
Expand Down
8 changes: 8 additions & 0 deletions GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ _Avoid_: ignored entry, unknown entry
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

**Action**:
A message whose text starts with `/me`, shown as what its author does ("Alex waves") instead of as something said. A message with a file is never an action.
_Avoid_: emote, me-message

**Summary**:
A message in one line, where it's quoted or listed rather than shown in full: its text or caption, what its file is, or that it's gone.
_Avoid_: preview (that's a picture's), excerpt, snippet (that's a search match's)

**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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ui/src/api.ts typed wrappers for the Rust commands, plus the shared
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/people.ts whose name each message shows
ui/src/reading.ts how a message reads: placeholders, actions, its summary
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
3 changes: 2 additions & 1 deletion src-tauri/src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ pub fn on_message(app: &AppHandle, message: &Message) {
let unread = desktop.unread.fetch_add(1, Ordering::Relaxed) + 1;
show_unread(app, &window, unread);
if desktop.notifications() && !core.dnd() && !recently_notified(&desktop) {
// A vanishing message's text would outlive it in the notification center.
// A vanishing message's text would outlive it in the notification center. The
// rest follows how the UI words a message (`ui/src/reading.ts`).
let text = match message.text.strip_prefix("/me ") {
_ if message.vanish.is_some() => "Vanishing message".to_string(),
Some(action) => format!("{} {action}", title(core.peer_name(), "They")),
Expand Down
54 changes: 23 additions & 31 deletions ui/src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { memo, useEffect, useMemo, useRef, useState } from 'react'

import { api, type Message as ChatMessage, type Quote, type Reaction } from '@/api'
import { type Command, parse, suggest } from '@/commands'
import { describeFile, FileView, StagedFiles, Viewer } from '@/components/Files'
import { FileView, StagedFiles, Viewer } from '@/components/Files'
import { Linkified } from '@/components/Linkified'
import { NoteCard } from '@/components/Notice'
import { SearchBar, SearchResults } from '@/components/Search'
Expand Down Expand Up @@ -54,6 +54,7 @@ import { Spinner } from '@/components/ui/spinner'
import { Textarea } from '@/components/ui/textarea'
import { formatDuration, formatUntil } from '@/lib/duration'
import { namer, peopleKey } from '@/people'
import { goneText, readingOf, summaryOf } from '@/reading'
import {
addMessage,
clearHistory,
Expand All @@ -71,7 +72,7 @@ import {
store,
unstageFile,
} from '@/store'
import { indexOf, messageKey, targetOf } from '@/transcript'
import { indexOf, messageKey, refOf, targetOf } from '@/transcript'

/** The reactions on offer. */
const EMOJI = ['👍', '❤️', '😂', '😮', '😢', '🎉']
Expand Down Expand Up @@ -405,31 +406,28 @@ const Row = memo(function Row({
const mine = receipt !== null
const align = mine ? 'end' : 'start'
const myReaction = message.reactions.find((r) => r.author === myId)?.emoji
// Who does an action: my name, not "You", so "Alex waves" reads as a sentence.
const actorOf = (author: string) => (author === myId ? myName : nameOf(author))
// Picking my current reaction again takes it back.
const react = (emoji: string) =>
void run(
api.react({ author: message.author, seq: message.seq }, emoji === myReaction ? '' : emoji),
)
void run(api.react(refOf(message), emoji === myReaction ? '' : emoji))
const footer = groupEnd && (
<MessageFooter className="text-[11px] font-normal">
{when.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })}
{receipt && ` · ${receipt}`}
</MessageFooter>
)

if (message.deleted) {
const reading = readingOf(message)
if (reading.kind === 'gone') {
return (
<div className={groupStart ? 'pt-3' : 'pt-0.5'}>
{newDay && <DayMarker when={when} />}
<Message align={align}>
<MessageContent className="gap-1">
<Bubble variant="outline" align={align}>
<BubbleContent className="text-muted-foreground italic" title={when.toLocaleString()}>
{message.vanished
? 'Message vanished'
: mine
? 'You deleted this message'
: 'Message deleted'}
{goneText(reading.why, mine)}
</BubbleContent>
</Bubble>
{footer}
Expand All @@ -440,15 +438,15 @@ const Row = memo(function Row({
}

// `/me waves`: an action line, "Alex waves", instead of a bubble.
const action = message.text.startsWith('/me ') && !message.file ? message.text.slice(4) : null
const action = reading.kind === 'action' ? reading.action : null
const { file } = message
const words = (
<>
{action === null ? (
<Linkified text={message.text} />
) : (
<span className="italic">
<span className="font-semibold not-italic">{mine ? myName : nameOf(message.author)}</span>{' '}
<span className="font-semibold not-italic">{actorOf(message.author)}</span>{' '}
<Linkified text={action} />
</span>
)}
Expand Down Expand Up @@ -479,6 +477,7 @@ const Row = memo(function Row({
<QuoteButton
quote={message.reply_to}
name={nameOf(message.reply_to.author)}
actor={actorOf(message.reply_to.author)}
onJump={onJump}
/>
)}
Expand Down Expand Up @@ -580,10 +579,13 @@ function jumpToQuote(quote: Quote) {
function QuoteButton({
quote,
name,
actor,
onJump,
}: {
quote: Quote
name: string
/** Its author as an action names them: my name rather than "You". */
actor: string
onJump: (quote: Quote) => void
}) {
return (
Expand All @@ -593,17 +595,7 @@ function QuoteButton({
onClick={() => onJump(quote)}
>
<span className="font-medium">{name}</span>
<span className="line-clamp-2 opacity-80">
{quote.vanished
? 'Message vanished'
: quote.deleted
? 'Deleted message'
: quote.file && !quote.text
? describeFile(quote.file)
: quote.text?.startsWith('/me ')
? `* ${quote.text.slice(4)}`
: (quote.text ?? 'A message that isn’t on this computer')}
</span>
<span className="line-clamp-2 opacity-80">{summaryOf(quote, actor)}</span>
</button>
)
}
Expand Down Expand Up @@ -740,14 +732,15 @@ function Composer() {
const textRef = useRef<HTMLTextAreaElement>(null)
const typingSentRef = useRef(0)
const { scrollToEnd } = useMessageScroller()
const { replyingTo, editing, peerName, myId, away, dndUntil, staged, hint } = useSelector(
const { replyingTo, editing, peerName, myId, myName, away, dndUntil, staged, hint } = useSelector(
store,
(s) => ({
hint: s.hint,
replyingTo: s.replyingTo,
editing: s.editing,
peerName: s.status?.peer?.name || 'them',
myId: s.status?.me.id ?? '',
myName: s.status?.me.name || 'You',
away: s.status?.away ? (s.status.away.note ?? '') : null,
dndUntil: s.status?.dnd_until ?? null,
staged: s.staged.length,
Expand Down Expand Up @@ -834,7 +827,7 @@ function Composer() {
return
}
const saved = await run(
api.editMessage({ author: of.author, seq: of.seq }, value).then(() => true),
api.editMessage(refOf(of), value).then(() => true),
'composer',
)
if (saved) setEditing(null)
Expand Down Expand Up @@ -864,7 +857,7 @@ function Composer() {
setSending(true)
for (const [i, s] of store.state.staged.entries()) {
const first = i === 0
const to = first && reply ? { author: reply.author, seq: reply.seq } : undefined
const to = first && reply ? refOf(reply) : undefined
const withText = first ? caption : ''
const sent = await run(
'pasted' in s.source
Expand Down Expand Up @@ -894,7 +887,7 @@ function Composer() {
reset()
setReplyingTo(null)
typingSentRef.current = 0 // the next message signals typing right away
const to = reply ? { author: reply.author, seq: reply.seq } : undefined
const to = reply ? refOf(reply) : undefined
const sent = await run(api.sendMessage(value, to, vanish), 'composer')
if (sent) {
addMessage(sent)
Expand Down Expand Up @@ -1015,7 +1008,7 @@ function Composer() {
Replying to {replyingTo.author === myId ? 'yourself' : peerName}
</div>
<div className="truncate text-muted-foreground">
{replyingTo.text || (replyingTo.file && describeFile(replyingTo.file))}
{summaryOf(replyingTo, replyingTo.author === myId ? myName : peerName)}
</div>
</div>
<Button
Expand Down Expand Up @@ -1192,8 +1185,7 @@ function DeleteDialog() {
onClick={() => {
// AlertDialogAction is a plain button: it doesn't close the dialog itself.
setDeleting(null)
if (deleting)
void run(api.deleteMessage({ author: deleting.author, seq: deleting.seq }))
if (deleting) void run(api.deleteMessage(refOf(deleting)))
}}
>
Delete
Expand Down
5 changes: 1 addition & 4 deletions ui/src/components/Files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSelector } from '@tanstack/react-store'
import { DownloadIcon, ExternalLinkIcon, FileIcon, FolderOpenIcon, XIcon } from 'lucide-react'
import { useState } from 'react'

import { api, type Attachment, type FileInfo } from '@/api'
import { api, type Attachment } from '@/api'
import { Button } from '@/components/ui/button'
import { fitWithin, formatBytes } from '@/lib/files'
import { run, setViewing, store, unstageFile } from '@/store'
Expand All @@ -18,9 +18,6 @@ const onMac = navigator.userAgent.includes('Mac')
const SHOW_IN_FOLDER = onMac ? 'Show in Finder' : 'Show in folder'
const SAVE_A_COPY = 'Save a copy…'

/** A picture, or a file's name: for quotes, the reply bar, and notifications. */
export const describeFile = (file: FileInfo) => (file.width ? 'Picture' : file.name)

/** A message's file: the picture itself, or a card for any other file. */
export function FileView({ file, peer }: { file: Attachment; peer: string }) {
// The other side can't always show what the sender could, like HEIC on Windows.
Expand Down
19 changes: 13 additions & 6 deletions ui/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Hit } from '@/api'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Spinner } from '@/components/ui/spinner'
import { actionInSnippet } from '@/reading'
import { closeSearch, reveal, setSearchActive, setSearchQuery, store } from '@/store'
import { messageKey } from '@/transcript'

Expand Down Expand Up @@ -69,11 +70,12 @@ export function SearchBar() {
}

export function SearchResults() {
const { search, myId, peerName } = useSelector(
const { search, myId, myName, peerName } = useSelector(
store,
(s) => ({
search: s.search,
myId: s.status?.me.id ?? '',
myName: s.status?.me.name || 'You',
peerName: s.status?.peer?.name || 'Them',
}),
{ compare: shallow },
Expand Down Expand Up @@ -112,7 +114,7 @@ export function SearchResults() {
</span>
<span>{when(hit.message.ts)}</span>
</div>
<Snippet text={hit.snippet} />
<Snippet hit={hit} actor={hit.message.author === myId ? myName : peerName} />
</button>
</li>
))}
Expand Down Expand Up @@ -141,11 +143,16 @@ function when(ts: number) {
return `${date}, ${d.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' })}`
}

/** A snippet from Rust, with the matches (between \u0002 and \u0003) highlighted. */
function Snippet({ text }: { text: string }) {
const [before, ...rest] = text.split('\u0002')
/**
* A match's snippet from Rust, with the matches (between \u0002 and \u0003) highlighted.
* An action reads as the transcript shows it: "Alex waves", with `actor` as the name.
*/
function Snippet({ hit, actor }: { hit: Hit; actor: string }) {
const action = actionInSnippet(hit)
const [before, ...rest] = (action ?? hit.snippet).split('\u0002')
return (
<p className="mt-0.5 line-clamp-2 text-sm break-words">
<p className={`mt-0.5 line-clamp-2 text-sm break-words ${action === null ? '' : 'italic'}`}>
{action !== null && <span className="font-semibold not-italic">{actor} </span>}
{before}
{rest.map((part, i) => {
const [match, after = ''] = part.split('\u0003')
Expand Down
Loading
Loading