Public: anyone can read this; the crew can change it.

A client list row offers Send again: it replaces the forge link with a fresh one and the old link stops working, with a receipt #13507

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/13485-a-client-list-row-offers-send-again-it-r → main 2 commits fork 2 threads · 2 unresolved

  • Merged. torque/13485-a-client-list-row-offers-send-again-it-r was merged into main as c1154f6.

Review

Sign in to review this change.
3 files changed +134 −2
src/spawn/clients.ts +28 −2
@@ -110,6 +110,11 @@ export interface ClientRow {
110110 * not say.
111111 */
112112 readonly link: LinkInfo | null;
113 /**
114 * When its link was last sent again and the old one ended (the `forge.claim_reissued` event),
115 * ISO; null when never.
116 */
117 readonly replacedAt?: string | null;
113118 /** Why this forge needs its owner now; null when it does not. */
114119 readonly attention: Attention | null;
115120 /**
@@ -317,6 +322,7 @@ export async function clientRows(app: App, options: { probe?: boolean } = {}): P
317322 const people = await Promise.all(children.map((c) => (c.done ? childPerson(childDirOf(app, c.bodyId)) : undefined)));
318323 const links = await Promise.all(children.map((c) => (c.apps.length === 0 ? [] : appLinkLines(app, c))));
319324 const notices = readNotices(app);
325 const replaced = linksReplaced(app);
320326 // Asked once, and only when a forge here is not in a cell: what its row says depends on whether
321327 // this host could hold it in one.
322328 const cells: CellsVerdict = children.some((c) => c.placement !== "cell") ? await cellsHere() : { ok: true };
@@ -356,6 +362,7 @@ export async function clientRows(app: App, options: { probe?: boolean } = {}): P
356362 disk: liveChildDisk(app.config.dataDir, c.bodyId, mountinfo),
357363 lastHeartbeatAt: beats[i] === undefined ? null : new Date(beats[i]!.receivedAt).toISOString(),
358364 link: states[i]?.link ?? null,
365 replacedAt: replaced.get(c.name) ?? null,
359366 // Read from the record this forge wrote when it made the child, never from the child's word.
360367 madeFrom: madeFromOf(childDirOf(app, c.bodyId)) ?? null,
361368 nextStep: nextStepOf(states[i]?.claimed ?? null, beats[i]?.beat),
@@ -364,6 +371,20 @@ export async function clientRows(app: App, options: { probe?: boolean } = {}): P
364371 );
365372 }
366373
374 /**
375 * When each forge's link was last replaced, from the receipts in this forge's own events: one
376 * query. It reads only `forge.claim_reissued` rows through the `event_kind_seq(kind, seq)` index,
377 * and those are one per owner tap on Send again, so the scan is small and not per-forge.
378 */
379 function linksReplaced(app: App): ReadonlyMap<string, string> {
380 const rows = app.db
381 .query<{ name: string | null; at: string }, []>(
382 "SELECT json_extract(payload, '$.name') AS name, MAX(created_at) AS at FROM event WHERE kind = 'forge.claim_reissued' GROUP BY name",
383 )
384 .all();
385 return new Map(rows.flatMap((r) => (r.name === null ? [] : [[r.name, r.at] as const])));
386 }
387
367388 type Month = NonNullable<ClientRow["month"]>;
368389 interface Months {
369390 readonly cache: Map<string, { at: number; value: Month | null }>;
@@ -602,13 +623,17 @@ export interface Seen {
602623 readonly openedAt: string | null;
603624 /** ISO of a person's last action there; null until they signed in. */
604625 readonly lastSeenAt: string | null;
626 /**
627 * ISO of the last "send again", which ended the earlier link; null once claimed or when never.
628 */
629 readonly replacedAt?: string | null;
605630 }
606631
607632 /** Null while the forge is still being made or did not answer: nothing is claimed unknown. */
608 export function seenOf(r: Pick<ClientRow, "made" | "claimed" | "sentAt" | "link" | "lastActivityAt">): Seen | null {
633 export function seenOf(r: Pick<ClientRow, "made" | "claimed" | "sentAt" | "link" | "lastActivityAt" | "replacedAt">): Seen | null {
609634 if (!r.made || r.claimed === null || r.link === null) return null;
610635 const openedAt = r.link.openedAt ?? null;
611 return { sentAt: r.sentAt, opened: openedAt !== null || r.link.usedAt != null || r.link.state === "used", openedAt, lastSeenAt: r.claimed ? r.lastActivityAt : null };
636 return { sentAt: r.sentAt, opened: openedAt !== null || r.link.usedAt != null || r.link.state === "used", openedAt, lastSeenAt: r.claimed ? r.lastActivityAt : null, replacedAt: r.claimed ? null : r.replacedAt ?? null };
612637 }
613638
614639 /** The one line as parts to join with " · ": the words, and the instant to say beside them. */
@@ -616,6 +641,7 @@ export function seenParts(s: Seen): { words: string; at: string | null }[] {
616641 return [
outdated

Show 'link replaced' only while the forge is unclaimed. After a claim it is stale noise next to 'last seen'. Add a test.

617642 ...(s.sentAt === null ? [] : [{ words: "sent", at: s.sentAt }]),
618643 s.opened ? { words: s.openedAt === null ? "opened (time not noted)" : "opened", at: s.openedAt } : { words: "not opened yet", at: null },
644 ...(s.replacedAt == null ? [] : [{ words: "link replaced", at: s.replacedAt }]),
619645 ...(s.lastSeenAt === null ? [] : [{ words: "last seen", at: s.lastSeenAt }]),
620646 ];
621647 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs