Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
A removed chat message can be restored from /admin, and it reappears for everyone live #294
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/197-a-removed-chat-message-can-be-restored-f → main 2 commits fork
9 files
changed +171
−21
Software/README.md +8
| @@ -417,6 +417,13 @@ its live pose and the cameras. Driving needs a name and a turn. | ||
| 417 | 417 | everyone and logs it for **restore**; `mute-suggest` shows the owner a |
| 418 | 418 | one-click mute. A model that is down or over budget leaves the line standing. |
| 419 | 419 | Settings and log: `$FORGE_APP_DATA/so101/crew.json`. |
| 420 | - **Removed lines.** A chat line the owner or a moderator removes is hidden for | |
| 421 | everyone live but kept, with who removed it and when (last 200, in the chat | |
| 422 | file). `/admin` lists them under **Removed lines**; the owner restores one | |
| 423 | with its Restore button, with `{"type":"restore","id":N}` over `/live`, or | |
| 424 | with `/removed` and `/restore #N` in the terminal. All go through | |
| 425 | `Lobby.restoreLine`: the line reappears for every open page and the restore | |
| 426 | is logged (`restored chat line N`). Moderators can see the list, not restore. | |
| 420 | 427 | - The owner (anyone who may write this repository) can take control at |
| 421 | 428 | any time (this skips the queue), end anyone's turn, take people out of |
| 422 | 429 | the queue, delete messages, mute people and ban them (long-press or |
| @@ -471,6 +478,7 @@ watches. A line you type is said in the chat; commands start with `/`: | ||
| 471 | 478 | `resumed` when it is resumed. |
| 472 | 479 | - `/end [name]`, owner: end that turn (no name: whoever drives), or take |
| 473 | 480 | them out of the line. |
| 481 | - `/removed`, `/restore #<n>`, owner: list the latest removed chat lines, and put one back for everyone. | |
| 474 | 482 | - `/mute <name> [10m|1h|24h|forever]`, `/unmute <name>`, owner. A mute without a length is for good; a timed one ends on its own and the owner's list says when. |
| 475 | 483 | - `/table here`, owner: the page's "Table is here", the same |
| 476 | 484 | `POST /settings/table-here`: the table plane goes under the arm's lowest |
Software/so101/src/admin-page.ts +12 −2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | import { createHash } from "node:crypto"; |
| 8 | 8 | import { ANNOUNCEMENT_CHARS, type AdminSettings, type LogEntry } from "./admin.ts"; |
| 9 | import type { Removed } from "./chat.ts"; | |
| 9 | 10 | import type { Person, Who } from "./identity.ts"; |
| 10 | 11 | import type { Snapshot } from "./turns.ts"; |
| 11 | 12 | |
| @@ -53,7 +54,7 @@ time { color: var(--dim); font-variant-numeric: tabular-nums; } | ||
| 53 | 54 | export const ADMIN_CSP = `default-src 'none'; style-src 'sha256-${createHash("sha256").update(STYLE).digest("base64")}'; form-action 'self'; frame-ancestors 'none'; base-uri 'none'`; |
| 54 | 55 | |
| 55 | 56 | /** The fixed lines a redirect back may ask for; nothing from the request is echoed. */ |
| 56 | export const DONE = { saved: "Saved.", paused: "Paused: nobody new gets a turn.", resumed: "Open again: the next in line has control.", ended: "Turn ended.", taken: "You have control." } as const; | |
| 57 | export const DONE = { saved: "Saved.", paused: "Paused: nobody new gets a turn.", resumed: "Open again: the next in line has control.", ended: "Turn ended.", taken: "You have control.", restored: "Line restored." } as const; | |
| 57 | 58 | export type Done = keyof typeof DONE; |
| 58 | 59 | |
| 59 | 60 | export interface AdminPage { |
| @@ -63,6 +64,8 @@ export interface AdminPage { | ||
| 63 | 64 | settings: AdminSettings; |
| 64 | 65 | snapshot: Snapshot; |
| 65 | 66 | log: readonly LogEntry[]; |
| 67 | /** Chat lines a person removed, newest first. */ | |
| 68 | removed?: readonly Removed[]; | |
| 66 | 69 | done?: Done | null; |
| 67 | 70 | error?: string | null; |
| 68 | 71 | } |
| @@ -106,7 +109,13 @@ const action = (name: string, text: string, cls = "", disabled = false) => | ||
| 106 | 109 | `<form method="post" action="/admin"><input type="hidden" name="action" value="${name}"><button class="${cls}"${disabled ? " disabled" : ""}>${text}</button></form>`; |
| 107 | 110 | |
| 108 | 111 | /** The log lines that are moderation: chat-line deletions, removals from the line, mutes, bans and their reversals. */ |
| 109 | export const isModeration = (e: LogEntry): boolean => /^(banned|unbanned|muted|unmuted|deleted chat line|took .+ out of the line)/.test(e.what); | |
| 112 | export const isModeration = (e: LogEntry): boolean => /^(banned|unbanned|muted|unmuted|deleted chat line|restored chat line|took .+ out of the line)/.test(e.what); | |
| 113 | ||
| 114 | /** Removed chat lines, each with who took it down and, for the owner, a Restore button. */ | |
| 115 | const removedLines = (list: readonly Removed[], canEdit: boolean): string => | |
| 116 | list.length | |
| 117 | ? `<ol>${list.map((r) => `<li>${time(r.at)}<span><b>${esc(r.by.name)}</b> removed ${esc(r.message.from?.name ?? "system")}: ${esc(r.message.text)}${canEdit ? ` <form method="post" action="/admin" class="inline"><input type="hidden" name="action" value="restore"><input type="hidden" name="id" value="${r.message.id}"><button aria-label="Restore line ${r.message.id}: ${esc([...r.message.text].slice(0, 40).join(""))}">Restore</button></form>` : ""}</span></li>`).join("")}</ol>` | |
| 118 | : `<p class="empty">No removed lines.</p>`; | |
| 110 | 119 | |
| 111 | 120 | export function renderAdmin(p: AdminPage): string { |
| 112 | 121 | const s = p.settings; |
| @@ -148,6 +157,7 @@ ${p.canEdit ? `<div class="save"><button class="go">Save settings</button></div> | ||
| 148 | 157 | </section> |
| 149 | 158 | <section aria-labelledby="mods"><h2 id="mods">Moderators</h2>${mods}</section> |
| 150 | 159 | <section aria-labelledby="moderation"><h2 id="moderation">Moderation</h2>${actions}</section> |
| 160 | <section aria-labelledby="removed"><h2 id="removed">Removed lines</h2>${removedLines(p.removed ?? [], p.canEdit)}</section> | |
| 151 | 161 | <section aria-labelledby="log"><h2 id="log">Log</h2>${log}</section>`, |
| 152 | 162 | ); |
| 153 | 163 | } |
Software/so101/src/admin-routes.ts +7 −1
| @@ -34,7 +34,7 @@ export function serveAdminPage(lobby: Lobby, req: IncomingMessage, res: ServerRe | ||
| 34 | 34 | return null; |
| 35 | 35 | } |
| 36 | 36 | const show = (status: number, done: Done | null, error: string | null) => |
| 37 | html(status, renderAdmin({ who, canEdit, settings: lobby.admin.settings, snapshot: lobby.turns.snapshot(), log: lobby.admin.log, done, error })); | |
| 37 | html(status, renderAdmin({ who, canEdit, settings: lobby.admin.settings, snapshot: lobby.turns.snapshot(), log: lobby.admin.log, removed: lobby.chat.removed, done, error })); | |
| 38 | 38 | if (req.method === "GET" || req.method === "HEAD") { |
| 39 | 39 | const done = url.searchParams.get("done"); |
| 40 | 40 | show(200, done && Object.hasOwn(DONE, done) ? (done as Done) : null, null); |
| @@ -96,6 +96,12 @@ export async function handleAdmin(lobby: Lobby, req: IncomingMessage, res: Serve | ||
| 96 | 96 | lobby.takeControl(who); |
| 97 | 97 | done = "taken"; |
| 98 | 98 | break; |
| 99 | case "restore": { | |
| 100 | const id = Number(form.get("id")); | |
| 101 | if (!lobby.restoreLine(who, id)) throw new AdminError("that line is not in the log"); | |
| 102 | done = "restored"; | |
| 103 | break; | |
| 104 | } | |
| 99 | 105 | default: |
| 100 | 106 | throw new AdminError("no such action"); |
| 101 | 107 | } |
Software/so101/src/chat.test.ts +17
| @@ -81,4 +81,21 @@ describe("chat", () => { | ||
| 81 | 81 | const chat = new Chat({ file: old, now: () => 1e12 }); |
| 82 | 82 | expect(chat.muted.get("c")).toBe("carol"); |
| 83 | 83 | }); |
| 84 | ||
| 85 | test("a removed line is kept with who removed it, survives a restart, and goes back in order", () => { | |
| 86 | const file = join(mkdtempSync(join(tmpdir(), "so101-chat-")), "chat.json"); | |
| 87 | let clock = 0; | |
| 88 | const chat = new Chat({ file, now: () => (clock += 5000) }); | |
| 89 | const first = chat.post(alice, "one"); | |
| 90 | chat.post(bob, "two"); | |
| 91 | chat.delete(first.id, bob); | |
| 92 | expect(chat.messages.map((m) => m.text)).toEqual(["two"]); | |
| 93 | const again = new Chat({ file }); | |
| 94 | expect(again.removed[0]).toMatchObject({ message: { text: "one" }, by: { id: "b", name: "bob" } }); | |
| 95 | expect(again.system("x").id).toBe(3); | |
| 96 | expect(again.unremove(first.id)?.message.text).toBe("one"); | |
| 97 | expect(again.messages.map((m) => m.text)).toEqual(["one", "two", "x"]); | |
| 98 | expect(again.unremove(first.id)).toBeNull(); | |
| 99 | expect(new Chat({ file }).removed).toEqual([]); | |
| 100 | }); | |
| 84 | 101 | }); |
Software/so101/src/chat.ts +36 −11
| @@ -20,6 +20,13 @@ export interface Message { | ||
| 20 | 20 | text: string; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | /** A line taken down by a person: kept, with who and when, so it can be put back. */ | |
| 24 | export interface Removed { | |
| 25 | message: Message; | |
| 26 | by: { id: string; name: string }; | |
| 27 | at: number; | |
| 28 | } | |
| 29 | ||
| 23 | 30 | export class ChatError extends Error {} |
| 24 | 31 | |
| 25 | 32 | export interface ChatOptions { |
| @@ -42,6 +49,8 @@ export function cleanText(text: unknown): string { | ||
| 42 | 49 | |
| 43 | 50 | export class Chat { |
| 44 | 51 | messages: Message[] = []; |
| 52 | /** Lines a person removed, newest first; the last `KEEP` are kept. */ | |
| 53 | removed: Removed[] = []; | |
| 45 | 54 | /** id → mute; `until` null is for good. */ |
| 46 | 55 | private readonly mutes = new Map<string, { name: string; until: number | null }>(); |
| 47 | 56 | /** id → name of everyone muted; kept in step with `mutes`, expired ones pruned on read. */ |
| @@ -87,14 +96,28 @@ export class Chat { | ||
| 87 | 96 | return this.add(null, text); |
| 88 | 97 | } |
| 89 | 98 | |
| 90 | delete(id: number): boolean { | |
| 91 | const before = this.messages.length; | |
| 92 | this.messages = this.messages.filter((m) => m.id !== id); | |
| 93 | if (this.messages.length === before) return false; | |
| 99 | /** Takes a line down; with `by` it is kept as removed so `unremove` can bring it back. */ | |
| 100 | delete(id: number, by?: { id: string; name: string }): boolean { | |
| 101 | const message = this.messages.find((m) => m.id === id); | |
| 102 | if (!message) return false; | |
| 103 | this.messages = this.messages.filter((m) => m !== message); | |
| 104 | if (by) { | |
| 105 | this.removed.unshift({ message, by: { id: by.id, name: by.name }, at: this.now() }); | |
| 106 | this.removed.length = Math.min(this.removed.length, KEEP); | |
| 107 | } | |
| 94 | 108 | this.save(); |
| 95 | 109 | return true; |
| 96 | 110 | } |
| 97 | 111 | |
| 112 | /** Puts a removed line back where its id puts it; null when it was not removed. */ | |
| 113 | unremove(id: number): Removed | null { | |
| 114 | const i = this.removed.findIndex((r) => r.message.id === id); | |
| 115 | if (i < 0) return null; | |
| 116 | const [entry] = this.removed.splice(i, 1); | |
| 117 | this.restore(entry!.message); | |
| 118 | return entry!; | |
| 119 | } | |
| 120 | ||
| 98 | 121 | /** Puts a removed line back where its id puts it. */ |
| 99 | 122 | restore(message: Message): void { |
| 100 | 123 | if (this.messages.some((m) => m.id === message.id)) return; |
| @@ -143,16 +166,18 @@ export class Chat { | ||
| 143 | 166 | } |
| 144 | 167 | |
| 145 | 168 | private load(file: string): void { |
| 146 | let stored: { messages?: unknown; muted?: unknown }; | |
| 169 | let stored: { messages?: unknown; removed?: unknown; muted?: unknown }; | |
| 147 | 170 | try { |
| 148 | 171 | stored = JSON.parse(readFileSync(file, "utf8")); |
| 149 | 172 | } catch { |
| 150 | 173 | return; // none yet, or unreadable: start over rather than refuse to start |
| 151 | 174 | } |
| 152 | if (Array.isArray(stored.messages)) { | |
| 153 | this.messages = stored.messages | |
| 154 | .filter((m): m is Message => typeof m?.id === "number" && typeof m.at === "number" && typeof m.text === "string" && (m.from === null || (typeof m.from?.id === "string" && typeof m.from?.name === "string"))) | |
| 155 | .slice(-KEEP); | |
| 175 | const valid = (m: any): m is Message => typeof m?.id === "number" && typeof m.at === "number" && typeof m.text === "string" && (m.from === null || (typeof m.from?.id === "string" && typeof m.from?.name === "string")); | |
| 176 | if (Array.isArray(stored.messages)) this.messages = stored.messages.filter(valid).slice(-KEEP); | |
| 177 | if (Array.isArray(stored.removed)) { | |
| 178 | this.removed = stored.removed | |
| 179 | .filter((r): r is Removed => valid(r?.message) && typeof r.by?.id === "string" && typeof r.by?.name === "string" && typeof r.at === "number") | |
| 180 | .slice(0, KEEP); | |
| 156 | 181 | } |
| 157 | 182 | if (stored.muted && typeof stored.muted === "object") { |
| 158 | 183 | // a name string is the old format: muted for good |
| @@ -165,13 +190,13 @@ export class Chat { | ||
| 165 | 190 | } |
| 166 | 191 | } |
| 167 | 192 | for (const [id, m] of this.mutes) this.names.set(id, m.name); |
| 168 | this.next = Math.max(0, ...this.messages.map((m) => m.id)) + 1; | |
| 193 | this.next = Math.max(0, ...this.messages.map((m) => m.id), ...this.removed.map((r) => r.message.id)) + 1; | |
| 169 | 194 | } |
| 170 | 195 | |
| 171 | 196 | private save(): void { |
| 172 | 197 | if (!this.file) return; |
| 173 | 198 | mkdirSync(dirname(this.file), { recursive: true }); |
| 174 | writeFileSync(`${this.file}.tmp`, JSON.stringify({ messages: this.messages, muted: Object.fromEntries([...this.mutes].map(([id, m]) => [id, m.until === null ? m.name : m])) })); | |
| 199 | writeFileSync(`${this.file}.tmp`, JSON.stringify({ messages: this.messages, removed: this.removed, muted: Object.fromEntries([...this.mutes].map(([id, m]) => [id, m.until === null ? m.name : m])) })); | |
| 175 | 200 | renameSync(`${this.file}.tmp`, this.file); |
| 176 | 201 | } |
| 177 | 202 | } |
Software/so101/src/lobby.test.ts +31
| @@ -346,6 +346,37 @@ describe("lobby", () => { | ||
| 346 | 346 | expect(section).toContain(`<b>bob</b> deleted chat line ${said.message.id}`); |
| 347 | 347 | }); |
| 348 | 348 | |
| 349 | test("a removed line is kept with who removed it, and Restore on /admin or over /live brings it back for everyone, logged", async () => { | |
| 350 | const admin = new Admin(); | |
| 351 | const port = await start(undefined, undefined, admin); | |
| 352 | const alice = await join(port, ALICE); | |
| 353 | const owner = await join(port, OWNER); | |
| 354 | alice.send({ type: "post", text: "oops <i>x</i>" }); | |
| 355 | const id = (await owner.next((m) => m.type === "said")).message.id; | |
| 356 | owner.send({ type: "delete", id }); | |
| 357 | await alice.next((m) => m.type === "unsaid"); | |
| 358 | const admin_ = `http://127.0.0.1:${port}/admin`; | |
| 359 | const html = await (await fetch(admin_, { headers: OWNER })).text(); | |
| 360 | expect(html).toContain("<b>trevato</b> removed alice: oops <i>x</i>"); | |
| 361 | expect(html).toContain("Restore"); | |
| 362 | ||
| 363 | owner.send({ type: "restore", id }); | |
| 364 | for (const c of [alice, owner]) expect((await c.next((m) => m.type === "chat")).messages.map((x: any) => x.text)).toEqual(["oops <i>x</i>"]); | |
| 365 | expect(admin.log.at(-1)).toMatchObject({ by: { name: "trevato" }, what: `restored chat line ${id}` }); | |
| 366 | owner.send({ type: "restore", id }); | |
| 367 | expect((await owner.next((m) => m.type === "error")).error).toBe("that line is not in the log"); | |
| 368 | ||
| 369 | // and the same through the admin form, which a plain user may not post | |
| 370 | owner.send({ type: "delete", id }); | |
| 371 | await alice.next((m) => m.type === "unsaid"); | |
| 372 | const post = (headers: Record<string, string>) => fetch(admin_, { method: "POST", headers: { ...headers, "content-type": "application/x-www-form-urlencoded" }, body: `action=restore&id=${id}`, redirect: "manual" }); | |
| 373 | expect((await post(ALICE)).status).toBe(404); | |
| 374 | const back = alice.next((m) => m.type === "chat"); | |
| 375 | expect((await post(OWNER)).status).toBe(303); | |
| 376 | expect((await back).messages.map((x: any) => x.id)).toEqual([id]); | |
| 377 | expect((await post(OWNER)).status).toBe(400); | |
| 378 | }); | |
| 379 | ||
| 349 | 380 | test("the owner's delete is logged with the owner as who did it, and a delete without an integer id is refused", async () => { |
| 350 | 381 | const admin = new Admin(); |
| 351 | 382 | const port = await start(undefined, undefined, admin); |
Software/so101/src/lobby.ts +19 −6
| @@ -16,7 +16,8 @@ | ||
| 16 | 16 | * {"type": "pause", "on": true|false} owner: maintenance; nobody new gets a turn |
| 17 | 17 | * {"type": "settings", "set": {…}} owner: any of src/admin.ts's settings |
| 18 | 18 | * {"type": "crew", "settings": {"enabled", "rules", "maxPerMinute"}} owner: the moderator's settings |
| 19 | * {"type": "restore", "id": 12} owner: put back a line the crew hid | |
| 19 | * {"type": "removed"} owner: the latest removed lines, answered with {"type": "removed", "lines": [...]} | |
| 20 | * {"type": "restore", "id": 12} owner: put back a removed line, or one the crew hid | |
| 20 | 21 | * {"type": "dismiss", "id": 12} owner: dismiss a mute suggestion |
| 21 | 22 | * {"type": "ban", "id": "<user id>", "on": true|false} owner: bars their account, name and address; they still watch |
| 22 | 23 | * {"type": "words", "words": ["…"]} owner: the chat's word filter; a line with a listed word is refused |
| @@ -399,11 +400,10 @@ export class Lobby { | ||
| 399 | 400 | this.send(seat, { type: "error", error: (err as Error).message }); |
| 400 | 401 | } |
| 401 | 402 | return; |
| 403 | case "removed": | |
| 404 | return this.send(seat, { type: "removed", lines: this.chat.removed.slice(0, 20).map((r) => ({ id: r.message.id, by: r.by.name, from: r.message.from?.name ?? null, text: r.message.text })) }); | |
| 402 | 405 | case "restore": { |
| 403 | const back = Number.isSafeInteger(m.id) ? this.moderator?.restore(m.id as number) : null; | |
| 404 | if (!back) return this.send(seat, { type: "error", error: "that line is not in the log" }); | |
| 405 | this.chat.restore(back); | |
| 406 | this.broadcast(this.chatLog()); | |
| 406 | if (!this.restoreLine(who, m.id)) this.send(seat, { type: "error", error: "that line is not in the log" }); | |
| 407 | 407 | return; |
| 408 | 408 | } |
| 409 | 409 | case "dismiss": |
| @@ -416,12 +416,25 @@ export class Lobby { | ||
| 416 | 416 | /** Delete a chat line as the owner or a moderator; the admin log says who. */ |
| 417 | 417 | private deleteLine(who: Person, id: unknown): void { |
| 418 | 418 | if (!Number.isSafeInteger(id)) throw new ChatError("delete which line?"); |
| 419 | if (!this.chat.delete(id as number)) return; | |
| 419 | if (!this.chat.delete(id as number, who)) return; | |
| 420 | 420 | this.admin.record(who, `deleted chat line ${id}`); |
| 421 | 421 | this.broadcast({ type: "unsaid", id }); |
| 422 | 422 | this.broadcastAdmin(); |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | /** Put a removed chat line back for everyone, from the owner's removals or the moderator's log; the admin log says who. */ | |
| 426 | restoreLine(who: Person, id: unknown): boolean { | |
| 427 | if (!Number.isSafeInteger(id)) return false; | |
| 428 | const line = this.chat.unremove(id as number); | |
| 429 | const back = line?.message ?? this.moderator?.restore(id as number); | |
| 430 | if (!back) return false; | |
| 431 | if (!line) this.chat.restore(back); | |
| 432 | this.admin.record(who, `restored chat line ${id}`); | |
| 433 | this.broadcast(this.chatLog()); | |
| 434 | this.broadcastAdmin(); | |
| 435 | return true; | |
| 436 | } | |
| 437 | ||
| 425 | 438 | private turnChanged(event: TurnEvent): void { |
| 426 | 439 | if (event.kind === "turn") { |
| 427 | 440 | const { ended, started } = event; |
Software/so101/src/terminal.test.ts +27
| @@ -368,6 +368,33 @@ describe("terminal door", () => { | ||
| 368 | 368 | expect(lobby!.admin.log.at(-1)).toMatchObject({ by: { id: "u-bob", name: "bob" }, what: `deleted chat line ${one.message.id}` }); |
| 369 | 369 | }); |
| 370 | 370 | |
| 371 | test("removed and restore: the owner's terminal lists removals and restores one for web viewers; anyone else's gets nothing", async () => { | |
| 372 | const port = await start(); | |
| 373 | const page = await viewer(port); | |
| 374 | const alicePage = await viewer(port, web("u-alice", "alice")); | |
| 375 | alicePage.send({ type: "post", text: "one" }); | |
| 376 | const one = await page.heardOne((m) => m.type === "said" && m.message.text === "one", "the line"); | |
| 377 | const owner = await terminal(port, ttyEnv("u-owner", "trevato", "admin")); | |
| 378 | const carol = await terminal(port, ttyEnv("u-carol", "carol", "user")); | |
| 379 | await owner.printedLine(/^you are trevato \(owner\)$/); | |
| 380 | owner.door.input("/removed"); | |
| 381 | await owner.printedLine(/^no removed lines$/); | |
| 382 | owner.door.input(`/delete #${one.message.id}`); | |
| 383 | await page.heardOne((m) => m.type === "unsaid", "the line going"); | |
| 384 | owner.door.input("/removed"); | |
| 385 | await owner.printedLine(new RegExp(`^removed #${one.message.id} by trevato, alice: one$`)); | |
| 386 | carol.door.input("/removed"); | |
| 387 | await carol.printedLine(/^error: only the owner can do that$/); | |
| 388 | carol.door.input(`/restore #${one.message.id}`); | |
| 389 | await carol.printedLine(/^error: only the owner can do that$/); | |
| 390 | expect(lobby!.chat.messages.length).toBe(0); | |
| 391 | owner.door.input(`/restore #${one.message.id}`); | |
| 392 | expect((await page.heardOne((m) => m.type === "chat" && m.messages.length === 1, "the line back")).messages[0].text).toBe("one"); | |
| 393 | expect(lobby!.admin.log.at(-1)).toMatchObject({ what: `restored chat line ${one.message.id}` }); | |
| 394 | owner.door.input("/restore x"); | |
| 395 | await owner.printedLine(/^usage: \/restore/); | |
| 396 | }); | |
| 397 | ||
| 371 | 398 | test("end-turn: only the owner's terminal may; the page sees the turn pass on", async () => { |
| 372 | 399 | const port = await start(); |
| 373 | 400 | const alicePage = await viewer(port, web("u-alice", "alice")); |
Software/so101/src/terminal.ts +14 −1
| @@ -22,6 +22,8 @@ | ||
| 22 | 22 | * /end [who] owner: end that turn (none: whoever drives), or take them out of the line |
| 23 | 23 | * /mute <who> [10m|1h|24h|forever] /unmute <who> owner |
| 24 | 24 | * /delete <who|#id> owner or moderator: remove that person's latest chat line, or the line numbered #id (shown to those who may) |
| 25 | * /removed owner: the latest removed chat lines, with their numbers and who removed them | |
| 26 | * /restore #<n> owner: put a removed line back for everyone (Lobby.restoreLine; it is logged) | |
| 25 | 27 | * /table here admin: put the table under the arm's lowest link now (POST /settings/table-here) |
| 26 | 28 | * /table <mm> admin: set the table offset, -100..100 mm (PUT /settings tableOffsetMm) |
| 27 | 29 | * /machine [off] the Machine panel (/machine, src/machine-feed.ts): the joints, the link and the server as they are, |
| @@ -137,7 +139,7 @@ const said = (room: Room, m: unknown): string => { | ||
| 137 | 139 | return from ? `${tag}${plain(from.name)}: ${plain(message?.text)}` : `· ${plain(message?.text)}`; |
| 138 | 140 | }; |
| 139 | 141 | |
| 140 | export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /mute <who> /unmute <who> /table here|<mm> (owner) · /delete <who|#id> (owner, moderator) · /machine [off] · /who · /quit"; | |
| 142 | export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /mute <who> /unmute <who> /table here|<mm> (owner) · /delete <who|#id> (owner, moderator) · /removed /restore #<id> (owner) · /machine [off] · /who · /quit"; | |
| 141 | 143 | |
| 142 | 144 | /** The Machine feed's socket beside the lobby's: same app, same port. */ |
| 143 | 145 | export const machineUrl = (live: string): string => live.replace(/\/live$/, "/machine"); |
| @@ -228,6 +230,11 @@ export function hear(room: Room, frame: Frame): string[] { | ||
| 228 | 230 | } |
| 229 | 231 | case "unsaid": |
| 230 | 232 | return ["· a line was removed"]; |
| 233 | case "removed": { | |
| 234 | const lines = Array.isArray(frame.lines) ? frame.lines : []; | |
| 235 | if (!lines.length) return ["no removed lines"]; | |
| 236 | return lines.map((l: { id?: unknown; by?: unknown; from?: unknown; text?: unknown }) => `removed #${plain(l?.id)} by ${plain(l?.by)}, ${l?.from ? plain(l.from) : "system"}: ${plain(l?.text)}`); | |
| 237 | } | |
| 231 | 238 | case "error": |
| 232 | 239 | return [`error: ${plain(frame.error)}`]; |
| 233 | 240 | default: |
| @@ -283,6 +290,12 @@ export function typed(room: Room, input: string): Typed { | ||
| 283 | 290 | const id = number ? Number(number[1]) : room.latest.get(target(room, arg) ?? ""); |
| 284 | 291 | return id === undefined ? { print: `error: no line from ${plain(arg)} seen` } : { send: { type: "delete", id } }; |
| 285 | 292 | } |
| 293 | case "removed": | |
| 294 | return { send: { type: "removed" } }; | |
| 295 | case "restore": { | |
| 296 | const number = /^#?(\d{1,15})$/.exec(arg); | |
| 297 | return number ? { send: { type: "restore", id: Number(number[1]) } } : { print: "usage: /restore #<line number>" }; | |
| 298 | } | |
| 286 | 299 | case "stop": |
| 287 | 300 | case "resume": |
| 288 | 301 | return { post: `/${verb.toLowerCase()}` as "/stop" | "/resume" }; |
new above
offline