Prototype administrative discussion mute controls
Let owners/operators mute or unmute new public/private sends from a human seat while retaining history, incoming messages, gameplay and credentials. Fence metadata and durable audit writes with live authority, membership and versions. Preserve exact admin/message retries and inherit restrictions through seat recovery. Validation: types/lint, 5431 offline tests, build, 52 HTTP integration tests, 24 administrator HTTP groups, independent SQL/privacy/UI review and desktop/mobile refresh acceptance. All 2230 prior games and 4746 seats preserved. Additive migration 0016. Verified runtime fingerprint 588967fbb9c2e3b6abe2990c4fce96ee69e2256fb7e3ee416314b87593cebba9; documentation-only grammar/button-label review gives b5e57bdd26812debede91c588e38f247f1fa895ad23e7ae30bc8550eedcd90ec. New-revision deployed acceptance remains open; full admin/rules scope is unfinished.
This commit is contained in:
1 parent
2cddf03932
commit
160fdc1f30
26 files changed
+3008
-33
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { randomId } from './random-id';
|
||||
import { validAdminDiscussionInput, validAdminDiscussionView, type AdminDiscussionInput, type AdminDiscussionView, type AdminDiscussionResult } from './admin-discussion';
|
||||
type Storage = Pick<globalThis.Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
||||
const key = (account: string, code: string) => `dune.admin-discussion-request.v1:${account}:${code}`;
|
||||
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value);
|
||||
|
||||
export function adminDiscussionResponse(value: unknown, code: string): AdminDiscussionView {
|
||||
if (!validAdminDiscussionView(value) || value.code !== code) throw new Error('The server returned unreadable participant discussion settings.');
|
||||
return value;
|
||||
}
|
||||
export function adminDiscussionConfirmation(value: unknown, code: string, input: AdminDiscussionInput): AdminDiscussionResult {
|
||||
if (!object(value) || Object.keys(value).length !== 4 || !['operationId','replayed','appliedRevision','room'].every(key => Object.hasOwn(value, key)) ||
|
||||
value.operationId !== input.operationId || typeof value.replayed !== 'boolean' || value.appliedRevision !== input.expectedRevision + 1)
|
||||
throw new Error('The server did not confirm this participant discussion request.');
|
||||
const room = adminDiscussionResponse(value.room, code), target = room.players.find(player => player.id === input.target);
|
||||
if (room.version < input.expectedVersion || (target && target.revision < Number(value.appliedRevision)))
|
||||
throw new Error('The server returned participant settings older than the confirmed change.');
|
||||
return value as AdminDiscussionResult;
|
||||
}
|
||||
export function newAdminDiscussionRequest(view: AdminDiscussionView, target: string, muted: boolean, reason: string): AdminDiscussionInput {
|
||||
if (!view.editable) throw new Error(view.blockedReason ?? 'Refresh participant discussion settings.');
|
||||
const player = view.players.find(player => player.id === target && player.control !== 'ai');
|
||||
if (!player || player.muted === muted) throw new Error('Choose a human participant with a different discussion setting.');
|
||||
const input = { operationId: randomId(), expectedVersion: view.version, expectedRevision: player.revision, target, muted, reason: reason.trim() };
|
||||
if (!validAdminDiscussionInput(input)) throw new Error('Choose a participant and a reason of 1–300 characters on one line.');
|
||||
return input;
|
||||
}
|
||||
export function readAdminDiscussionRequest(storage: Storage, account: string, code: string): AdminDiscussionInput | null {
|
||||
const raw = storage.getItem(key(account, code)); if (raw === null) return null;
|
||||
let value: unknown; try { value = raw.length <= 2048 ? JSON.parse(raw) : null; } catch { value = null; }
|
||||
if (!validAdminDiscussionInput(value)) throw new Error('This tab’s saved discussion request is unreadable. Inspect the room before discarding its local retry record.');
|
||||
return value;
|
||||
}
|
||||
export function saveAdminDiscussionRequest(storage: Storage, account: string, code: string, input: AdminDiscussionInput) {
|
||||
if (!validAdminDiscussionInput(input)) throw new Error('Invalid participant discussion request.');
|
||||
const previous = readAdminDiscussionRequest(storage, account, code), encoded = JSON.stringify(input);
|
||||
if (previous && JSON.stringify(previous) !== encoded) throw new Error('Resolve the saved discussion request before sending a different change.');
|
||||
storage.setItem(key(account, code), encoded);
|
||||
if (storage.getItem(key(account, code)) !== encoded) throw new Error('The discussion request could not be preserved in this tab. Nothing was sent.');
|
||||
}
|
||||
export function clearAdminDiscussionRequest(storage: Storage, account: string, code: string) {
|
||||
storage.removeItem(key(account, code));
|
||||
if (storage.getItem(key(account, code)) !== null) throw new Error('The saved discussion request could not be cleared.');
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { FACTIONS } from '../game/catalog';
|
||||
|
||||
export type AdminDiscussionInput = {
|
||||
operationId: string; expectedVersion: number; expectedRevision: number;
|
||||
target: string; muted: boolean; reason: string;
|
||||
};
|
||||
export type AdminDiscussionView = {
|
||||
code: string; version: number; removed: boolean; closed: boolean; archived: boolean;
|
||||
status: 'lobby' | 'setup' | 'playing' | 'finished' | 'unreadable';
|
||||
editable: boolean; blockedReason: string | null;
|
||||
players: { id: string; name: string; faction: string; control: 'human' | 'autopilot' | 'ai'; muted: boolean; revision: number }[];
|
||||
};
|
||||
export type AdminDiscussionResult = { operationId: string; replayed: boolean; appliedRevision: number; room: AdminDiscussionView };
|
||||
const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === 'object' && !Array.isArray(value);
|
||||
const keys = (value: Record<string, unknown>, names: string[]) => Object.keys(value).length === names.length && names.every(name => Object.hasOwn(value, name));
|
||||
const counter = (value: unknown) => Number.isSafeInteger(value) && Number(value) >= 0 && Number(value) < Number.MAX_SAFE_INTEGER;
|
||||
const oneLine = (value: unknown, max: number): value is string => typeof value === 'string' && value.length <= max && !!value.trim() &&
|
||||
!value.split('').some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127);
|
||||
|
||||
export function validAdminDiscussionInput(value: unknown): value is AdminDiscussionInput {
|
||||
return object(value) && keys(value, ['operationId','expectedVersion','expectedRevision','target','muted','reason']) &&
|
||||
typeof value.operationId === 'string' && value.operationId.length === 36 && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(value.operationId) &&
|
||||
counter(value.expectedVersion) && counter(value.expectedRevision) && oneLine(value.target, 80) && value.target.trim() === value.target &&
|
||||
typeof value.muted === 'boolean' && oneLine(value.reason, 300);
|
||||
}
|
||||
export function validAdminDiscussionView(value: unknown): value is AdminDiscussionView {
|
||||
return object(value) && keys(value, ['code','version','removed','closed','archived','status','editable','blockedReason','players']) &&
|
||||
typeof value.code === 'string' && value.code.length === 8 && /^[A-Z2-9]{8}$/.test(value.code) && counter(value.version) &&
|
||||
['removed','closed','archived','editable'].every(key => typeof value[key] === 'boolean') &&
|
||||
['lobby','setup','playing','finished','unreadable'].includes(String(value.status)) && (value.blockedReason === null || typeof value.blockedReason === 'string') &&
|
||||
Array.isArray(value.players) && value.players.length <= 6 && value.players.every(player => object(player) &&
|
||||
keys(player, ['id','name','faction','control','muted','revision']) && oneLine(player.id, 80) && typeof player.name === 'string' && player.name.length <= 80 &&
|
||||
FACTIONS.some(faction => faction.id === player.faction) && ['human','autopilot','ai'].includes(String(player.control)) &&
|
||||
typeof player.muted === 'boolean' && counter(player.revision));
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@ export type TalkMessage = {
|
||||
text: string;
|
||||
createdAt: number;
|
||||
};
|
||||
export type TalkPage = { messages: TalkMessage[]; before: string | null };
|
||||
export type TalkPage = { messages: TalkMessage[]; before: string | null; muted: boolean };
|
||||
export const talkId = (value: unknown): value is string =>
|
||||
typeof value === 'string' &&
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(value);
|
||||
|
||||
Reference in new issue
Block a user