diff --git a/CHANGELOG.md b/CHANGELOG.md index bfdbc3d..cfaf624 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/ui/src/components/Chat.tsx b/ui/src/components/Chat.tsx index 1909d53..c841833 100644 --- a/ui/src/components/Chat.tsx +++ b/ui/src/components/Chat.tsx @@ -732,22 +732,30 @@ function Composer() { const textRef = useRef(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(null) @@ -1005,10 +1013,10 @@ function Composer() {
- Replying to {replyingTo.author === myId ? 'yourself' : peerName} + Replying to {replyingTo.author === myId ? 'yourself' : nameOf(replyingTo.author)}
- {summaryOf(replyingTo, replyingTo.author === myId ? myName : peerName)} + {summaryOf(replyingTo, actorOf(replyingTo.author))}
))} diff --git a/ui/src/people.test.ts b/ui/src/people.test.ts index 8b522c1..9cbd8f6 100644 --- a/ui/src/people.test.ts +++ b/ui/src/people.test.ts @@ -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') diff --git a/ui/src/people.ts b/ui/src/people.ts index 2c7cf08..e324b01 100644 --- a/ui/src/people.ts +++ b/ui/src/people.ts @@ -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(JSON.parse(key)) - return (author) => (author === myId ? 'You' : names.get(author) || fallback) + return (author) => (author === myId ? me : names.get(author) || fallback) }