Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
A moderator can mute and unmute over /live, never the owner or another moderator, and receives the muted list #304
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/226-a-moderator-can-mute-and-unmute-over-liv → main 3 commits fork
4 files
changed +83
−25
Software/README.md +4 −2
| @@ -464,7 +464,9 @@ its live pose and the cameras. Driving needs a name and a turn. | ||
| 464 | 464 | the queue, delete messages, mute people and ban them (long-press or |
| 465 | 465 | right-click a chat line). |
| 466 | 466 | - Moderators (names the owner lists under `moderators` on `/admin`) can delete |
| 467 | chat lines and do nothing else of the owner's. They must be signed in through | |
| 467 | chat lines, and mute and unmute people who are signed in and here now (never | |
| 468 | the owner, another moderator, or anyone not connected), and do nothing else | |
| 469 | of the owner's. They must be signed in through | |
| 468 | 470 | the forge: a guest who picked a listed name is not one. In the page, long-press |
| 469 | 471 | or right-click a chat line and choose **Delete message**. In the terminal, chat |
| 470 | 472 | lines show their number (`#12 bob: …`) to moderators and the owner: `/delete |
| @@ -514,7 +516,7 @@ watches. A line you type is said in the chat; commands start with `/`: | ||
| 514 | 516 | - `/end [name]`, owner: end that turn (no name: whoever drives), or take |
| 515 | 517 | them out of the line. |
| 516 | 518 | - `/removed`, `/restore #<n>`, owner: list the latest removed chat lines, and put one back for everyone. |
| 517 | - `/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. | |
| 519 | - `/mute <name> [10m|1h|24h|forever]`, `/unmute <name>`, owner or moderator. A mute without a length is for good; a timed one ends on its own and the owner's list says when. | |
| 518 | 520 | - `/table here`, owner: the page's "Table is here", the same |
| 519 | 521 | `POST /settings/table-here`: the table plane goes under the arm's lowest |
| 520 | 522 | link now. `/table <mm>`, owner: sets `tableOffsetMm` (-100 to 100) by |
Software/so101/src/lobby.test.ts +39
| @@ -346,6 +346,45 @@ describe("lobby", () => { | ||
| 346 | 346 | expect(section).toContain(`<b>bob</b> deleted chat line ${said.message.id}`); |
| 347 | 347 | }); |
| 348 | 348 | |
| 349 | test("a moderator mutes and unmutes, is logged and sees the muted list; never the owner or another moderator; a plain user is refused", async () => { | |
| 350 | const admin = new Admin(); | |
| 351 | admin.set({ id: "u-owner", name: "trevato", owner: true }, { moderators: ["bob", "carol"] }); | |
| 352 | const port = await start(undefined, undefined, admin); | |
| 353 | const alice = await join(port, ALICE); | |
| 354 | const owner = await join(port, OWNER); | |
| 355 | const bob = await join(port, BOB); | |
| 356 | const carol = await join(port, CAROL); | |
| 357 | expect((await bob.first((m) => m.type === "muted")).muted).toEqual([]); | |
| 358 | ||
| 359 | bob.send({ type: "mute", id: "u-alice", on: true, for: "1h" }); | |
| 360 | expect((await alice.next((m) => m.type === "hello")).muted).toBe(true); | |
| 361 | expect((await bob.next((m) => m.type === "muted")).muted).toMatchObject([{ id: "u-alice", name: "alice" }]); | |
| 362 | expect(admin.log.at(-1)).toMatchObject({ by: { id: "u-bob", name: "bob" }, what: "muted alice" }); | |
| 363 | bob.send({ type: "mute", id: "u-alice", on: false }); | |
| 364 | expect((await bob.next((m) => m.type === "muted")).muted).toEqual([]); | |
| 365 | expect(admin.log.at(-1)).toMatchObject({ by: { name: "bob" }, what: "unmuted alice" }); | |
| 366 | ||
| 367 | const logged = admin.log.length; | |
| 368 | bob.send({ type: "mute", id: "u-owner", on: true }); | |
| 369 | expect((await bob.next((m) => m.type === "error")).error).toContain("only the owner can mute"); | |
| 370 | bob.send({ type: "mute", id: "u-carol", on: true }); | |
| 371 | expect((await bob.next((m) => m.type === "error")).error).toContain("only the owner can mute"); | |
| 372 | expect(admin.log.length).toBe(logged); | |
| 373 | // nobody who has not joined can be told from the owner or a moderator: refused, and nothing changes | |
| 374 | owner.ws.close(); | |
| 375 | carol.ws.close(); | |
| 376 | await new Promise((r) => setTimeout(r, 100)); | |
| 377 | for (const id of ["u-owner", "u-carol", "u-dave"]) { | |
| 378 | bob.send({ type: "mute", id, on: true }); | |
| 379 | expect((await bob.next((m) => m.type === "error")).error).toContain("only the owner can mute"); | |
| 380 | } | |
| 381 | expect(admin.log.length).toBe(logged); | |
| 382 | ||
| 383 | alice.send({ type: "mute", id: "u-bob", on: true }); | |
| 384 | expect((await alice.next((m) => m.type === "error")).error).toBe("only the owner can do that"); | |
| 385 | expect(admin.log.length).toBe(logged); | |
| 386 | }); | |
| 387 | ||
| 349 | 388 | 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 | 389 | const admin = new Admin(); |
| 351 | 390 | const port = await start(undefined, undefined, admin); |
Software/so101/src/lobby.ts +38 −21
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | * {"type": "post", "text": "…"} say something |
| 13 | 13 | * {"type": "end", "id": "<user id>"} owner: end that turn, or take them out of the line |
| 14 | 14 | * {"type": "delete", "id": 12} owner or a moderator: delete a chat line |
| 15 | * {"type": "mute", "id": "<user id>", "on": true|false, "for": "10m"|"1h"|"24h"|"forever"} owner | |
| 15 | * {"type": "mute", "id": "<user id>", "on": true|false, "for": "10m"|"1h"|"24h"|"forever"} owner or a moderator (never the owner or a moderator) | |
| 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 |
| @@ -263,8 +263,8 @@ export class Lobby { | ||
| 263 | 263 | this.send(seat, this.hello(seat)); |
| 264 | 264 | this.send(seat, this.state()); |
| 265 | 265 | this.send(seat, this.chatLog()); |
| 266 | if (this.mayHearMuted(seat)) this.send(seat, this.mutedList()); | |
| 266 | 267 | if (who?.owner) { |
| 267 | this.send(seat, this.mutedList()); | |
| 268 | 268 | this.send(seat, this.bannedList()); |
| 269 | 269 | this.send(seat, this.wordsList()); |
| 270 | 270 | this.send(seat, this.adminState()); |
| @@ -326,7 +326,10 @@ export class Lobby { | ||
| 326 | 326 | return; |
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | if (!who.owner && m.type === "delete" && seat.verified && this.admin.isModerator(who.name)) return this.deleteLine(who, m.id); | |
| 329 | if (!who.owner && seat.verified && this.admin.isModerator(who.name)) { | |
| 330 | if (m.type === "delete") return this.deleteLine(who, m.id); | |
| 331 | if (m.type === "mute") return this.muteUser(seat, who, m); | |
| 332 | } | |
| 330 | 333 | if (!who.owner) return this.send(seat, { type: "error", error: "only the owner can do that" }); |
| 331 | 334 | switch (m.type) { |
| 332 | 335 | case "end": |
| @@ -349,23 +352,8 @@ export class Lobby { | ||
| 349 | 352 | for (const s of this.seats) if (s.who?.owner) this.send(s, this.wordsList()); |
| 350 | 353 | return; |
| 351 | 354 | } |
| 352 | case "mute": { | |
| 353 | if (typeof m.id !== "string" || !USER_ID.test(m.id) || typeof m.on !== "boolean") return this.send(seat, { type: "error", error: "mute whom?" }); | |
| 354 | if (m.for !== undefined && (typeof m.for !== "string" || !Object.hasOwn(MUTE_FOR, m.for))) return this.send(seat, { type: "error", error: "mute for 10m, 1h, 24h or forever" }); | |
| 355 | const id = m.id; | |
| 356 | const name = [...this.seats].find((s) => s.who?.id === id)?.who?.name ?? [...this.chat.messages].reverse().find((x) => x.from?.id === id)?.from?.name ?? this.chat.muted.get(id) ?? id; | |
| 357 | const span = MUTE_FOR[m.for ?? "forever"]; | |
| 358 | if (m.on) this.chat.mute(id, name, span === null ? null : this.now() + span); | |
| 359 | else this.chat.unmute(id); | |
| 360 | this.admin.record(who, `${m.on ? "muted" : "unmuted"} ${name}`); | |
| 361 | this.broadcastAdmin(); | |
| 362 | for (const s of this.seats) { | |
| 363 | if (s.who?.id === id) this.send(s, this.hello(s)); | |
| 364 | if (s.who?.owner) this.send(s, this.mutedList()); | |
| 365 | } | |
| 366 | this.moderator?.muted(id); | |
| 367 | return; | |
| 368 | } | |
| 355 | case "mute": | |
| 356 | return this.muteUser(seat, who, m); | |
| 369 | 357 | case "ban": { |
| 370 | 358 | if (typeof m.id !== "string" || !USER_ID.test(m.id) || typeof m.on !== "boolean") return this.send(seat, { type: "error", error: "ban whom?" }); |
| 371 | 359 | const id = m.id; |
| @@ -413,6 +401,35 @@ export class Lobby { | ||
| 413 | 401 | this.send(seat, { type: "error", error: "unknown request" }); |
| 414 | 402 | } |
| 415 | 403 | |
| 404 | /** Mute or unmute as the owner or a moderator; a moderator may not touch the owner or another moderator. The admin log says who. */ | |
| 405 | private muteUser(seat: Seat, who: Person, m: Record<string, unknown>): void { | |
| 406 | if (typeof m.id !== "string" || !USER_ID.test(m.id) || typeof m.on !== "boolean") return this.send(seat, { type: "error", error: "mute whom?" }); | |
| 407 | if (m.for !== undefined && (typeof m.for !== "string" || !Object.hasOwn(MUTE_FOR, m.for))) return this.send(seat, { type: "error", error: "mute for 10m, 1h, 24h or forever" }); | |
| 408 | const id = m.id; | |
| 409 | const there = [...this.seats].find((s) => s.who?.id === id)?.who; | |
| 410 | const name = there?.name ?? [...this.chat.messages].reverse().find((x) => x.from?.id === id)?.from?.name ?? this.chat.muted.get(id) ?? id; | |
| 411 | // A moderator fails closed: the target must be positively known as a plain user (here now and neither owner nor listed | |
| 412 | // moderator), or be on the muted list already (to lift it). Anyone who has not joined cannot be told from the owner. | |
| 413 | if (!who.owner && !(there ? !there.owner && !this.admin.isModerator(there.name) : !m.on && this.chat.muted.has(id) && !this.admin.isModerator(name))) { | |
| 414 | return this.send(seat, { type: "error", error: "only the owner can mute the owner, a moderator or anyone who is not here" }); | |
| 415 | } | |
| 416 | const span = MUTE_FOR[(m.for as string | undefined) ?? "forever"] ?? null; | |
| 417 | if (m.on) this.chat.mute(id, name, span === null ? null : this.now() + span); | |
| 418 | else this.chat.unmute(id); | |
| 419 | this.admin.record(who, `${m.on ? "muted" : "unmuted"} ${name}`); | |
| 420 | this.broadcastAdmin(); | |
| 421 | for (const s of this.seats) { | |
| 422 | if (s.who?.id === id) this.send(s, this.hello(s)); | |
| 423 | if (this.mayHearMuted(s)) this.send(s, this.mutedList()); | |
| 424 | } | |
| 425 | this.moderator?.muted(id); | |
| 426 | } | |
| 427 | ||
| 428 | /** The owner and a verified moderator are sent the muted list. */ | |
| 429 | private mayHearMuted(s: Seat): boolean { | |
| 430 | return Boolean(s.who && (s.who.owner || (s.verified && this.admin.isModerator(s.who.name)))); | |
| 431 | } | |
| 432 | ||
| 416 | 433 | /** Delete a chat line as the owner or a moderator; the admin log says who. */ |
| 417 | 434 | private deleteLine(who: Person, id: unknown): void { |
| 418 | 435 | if (!Number.isSafeInteger(id)) throw new ChatError("delete which line?"); |
| @@ -504,7 +521,7 @@ export class Lobby { | ||
| 504 | 521 | if (!ended.length) return; |
| 505 | 522 | for (const s of this.seats) { |
| 506 | 523 | if (s.who && ended.includes(s.who.id)) this.send(s, this.hello(s)); |
| 507 | if (s.who?.owner) this.send(s, this.mutedList()); | |
| 524 | if (this.mayHearMuted(s)) this.send(s, this.mutedList()); | |
| 508 | 525 | } |
| 509 | 526 | } |
| 510 | 527 |
Software/so101/src/terminal.ts +2 −2
| @@ -20,7 +20,7 @@ | ||
| 20 | 20 | * /stop the driver or an admin: halt the arm and hold it, whatever drives it, until /resume |
| 21 | 21 | * /resume the driver or an admin: end the hold; the arm stays put until a new command |
| 22 | 22 | * /end [who] owner: end that turn (none: whoever drives), or take them out of the line |
| 23 | * /mute <who> [10m|1h|24h|forever] /unmute <who> owner | |
| 23 | * /mute <who> [10m|1h|24h|forever] /unmute <who> owner or moderator (never the owner or a moderator) | |
| 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 | 25 | * /removed owner: the latest removed chat lines, with their numbers and who removed them |
| 26 | 26 | * /restore #<n> owner: put a removed line back for everyone (Lobby.restoreLine; it is logged) |
| @@ -139,7 +139,7 @@ const said = (room: Room, m: unknown): string => { | ||
| 139 | 139 | return from ? `${tag}${plain(from.name)}: ${plain(message?.text)}` : `· ${plain(message?.text)}`; |
| 140 | 140 | }; |
| 141 | 141 | |
| 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"; | |
| 142 | export const HELP = "type to chat · /join /leave /ready /extend · /stop /resume (driver, owner) · /end [who] /table here|<mm> (owner) · /mute <who> /unmute <who> (owner, moderator) · /delete <who|#id> (owner, moderator) · /removed /restore #<id> (owner) · /machine [off] · /who · /quit"; | |
| 143 | 143 | |
| 144 | 144 | /** The Machine feed's socket beside the lobby's: same app, same port. */ |
| 145 | 145 | export const machineUrl = (live: string): string => live.replace(/\/live$/, "/machine"); |
new above
offline