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: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Changes people using Tightbeam will notice. Add a line under **Unreleased** as t
- 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.
- Messages from someone you were paired with before keep their name, instead of showing the name of whoever you're paired with now.
- Messages from someone you were paired with before keep their name, in the conversation, in search and when replying, instead of showing the name of whoever you're paired with now.
- 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.
- A problem with what you're sending, like a file that's too big or a message that didn't go, shows just above the message box instead of at the top of the window.
Expand Down
42 changes: 25 additions & 17 deletions ui/src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -732,22 +732,30 @@ function Composer() {
const textRef = useRef<HTMLTextAreaElement>(null)
const typingSentRef = useRef(0)
const { scrollToEnd } = useMessageScroller()
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,
}),
{ compare: shallow },
)
const { replyingTo, editing, peerName, myId, myName, people, 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',
people: peopleKey(s.status?.people),
away: s.status?.away ? (s.status.away.note ?? '') : null,
dndUntil: s.status?.dnd_until ?? null,
staged: s.staged.length,
}),
{ compare: shallow },
)
const dnd = useUntil(dndUntil)
// Replying to someone I was paired with before names them, not whoever's paired now.
const nameOf = useMemo(() => namer(people, myId, peerName), [people, myId, peerName])
const actorOf = useMemo(
() => namer(people, myId, peerName, myName),
[people, myId, peerName, myName],
)
const [showingStatus, setShowingStatus] = useState(false)
// What was in the box before editing started; it comes back when editing ends.
const draftRef = useRef<string | null>(null)
Expand Down Expand Up @@ -1005,10 +1013,10 @@ function Composer() {
<div className="mb-2 flex items-center gap-2 rounded-md border-l-2 border-primary bg-muted py-1 pr-1 pl-2 text-xs">
<div className="min-w-0 flex-1">
<div className="font-medium">
Replying to {replyingTo.author === myId ? 'yourself' : peerName}
Replying to {replyingTo.author === myId ? 'yourself' : nameOf(replyingTo.author)}
</div>
<div className="truncate text-muted-foreground">
{summaryOf(replyingTo, replyingTo.author === myId ? myName : peerName)}
{summaryOf(replyingTo, actorOf(replyingTo.author))}
</div>
</div>
<Button
Expand Down
16 changes: 12 additions & 4 deletions ui/src/components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import { shallow, useSelector } from '@tanstack/react-store'
import { SearchIcon, XIcon } from 'lucide-react'
import { useEffect, useRef } from 'react'
import { useEffect, useMemo, useRef } from 'react'

import type { Hit } from '@/api'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Spinner } from '@/components/ui/spinner'
import { namer, peopleKey } from '@/people'
import { actionInSnippet } from '@/reading'
import { closeSearch, reveal, setSearchActive, setSearchQuery, store } from '@/store'
import { messageKey } from '@/transcript'
Expand Down Expand Up @@ -70,16 +71,23 @@ export function SearchBar() {
}

export function SearchResults() {
const { search, myId, myName, peerName } = useSelector(
const { search, myId, myName, peerName, people } = useSelector(
store,
(s) => ({
search: s.search,
myId: s.status?.me.id ?? '',
myName: s.status?.me.name || 'You',
peerName: s.status?.peer?.name || 'Them',
people: peopleKey(s.status?.people),
}),
{ compare: shallow },
)
// A match from someone I was paired with before names them, as the transcript does.
const nameOf = useMemo(() => namer(people, myId, peerName), [people, myId, peerName])
const actorOf = useMemo(
() => namer(people, myId, peerName, myName),
[people, myId, peerName, myName],
)
const listRef = useRef<HTMLUListElement>(null)
const active = search?.active ?? 0

Expand Down Expand Up @@ -110,11 +118,11 @@ export function SearchResults() {
>
<div className="flex items-baseline justify-between gap-3 text-xs text-muted-foreground">
<span className="font-medium text-foreground">
{hit.message.author === myId ? 'You' : peerName}
{nameOf(hit.message.author)}
</span>
<span>{when(hit.message.ts)}</span>
</div>
<Snippet hit={hit} actor={hit.message.author === myId ? myName : peerName} />
<Snippet hit={hit} actor={actorOf(hit.message.author)} />
</button>
</li>
))}
Expand Down
5 changes: 5 additions & 0 deletions ui/src/people.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ test('each author keeps their own name', () => {
expect(['me', 'bob', 'carol'].map(nameOf)).toEqual(['You', 'Bob', 'Carol'])
})

test('an action names me by my name', () => {
const actorOf = namer(peopleKey(people), 'me', 'Carol', 'Alex')
expect(['me', 'bob'].map(actorOf)).toEqual(['Alex', 'Bob'])
})

test('anyone unknown gets the fallback', () => {
expect(namer(peopleKey(undefined), 'me', 'Them')('stranger')).toBe('Them')
expect(namer(peopleKey([{ id: 'x', name: '' }]), 'me', 'Them')('x')).toBe('Them')
Expand Down
14 changes: 11 additions & 3 deletions ui/src/people.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ import type { Person } from './api'
export const peopleKey = (people: Person[] | undefined) =>
JSON.stringify((people ?? []).map((p) => [p.id, p.name]))

/** Names authors: "You" for me, otherwise their last known name, or else `fallback`. */
export function namer(key: string, myId: string, fallback: string): (author: string) => string {
/**
* Names authors: `me` for me ("You", or my name where an action needs a sentence: "Alex
* waves"), otherwise their last known name, or else `fallback`.
*/
export function namer(
key: string,
myId: string,
fallback: string,
me = 'You',
): (author: string) => string {
const names = new Map<string, string>(JSON.parse(key))
return (author) => (author === myId ? 'You' : names.get(author) || fallback)
return (author) => (author === myId ? me : names.get(author) || fallback)
}
Loading