Humans can discuss plans publicly or message another human seat privately while pending game decisions stay intact. The conversation panel provides plain text, explicit recipient names and factions, saved history, private pagination and exact retries through refresh. Human AI-control owners can still talk; bots do not interpret messages or negotiate. Existing game actions execute agreements. An additive indexed D1 message table stores discussion separately from game JSON, versioning, readiness and bot continuation. Every read/insert checks active seat credentials and membership; direct audiences and cursor lookups are filtered before limiting. Public history has no private activity counts or sequential IDs. Recovery/handover inherits seat history while fencing old credentials. Independent review found two retry races: a rotation between a committed insert and receipt read, and stale unmounted completion deleting a newer retry record. Both are fixed with regressions. A prior uncertain retry stays pending on later rejection. The nine focused offline cases and two HTTP cases cover production SQL, concurrent/altered receipts, audience/cursor privacy, rotation/membership races, actual saved-kit recovery and unchanged sealed setup state. Types, lint, all 4963 offline tests, production build and 48 HTTP tests pass on stable source. An initial check caught an invalid checklist status label; that was corrected before the successful final2 verification. Desktop browser checks send public/private messages, receive a peer reply, retain private history after refresh and remove it on channel switch. Literal markup and URLs remain text. Recipient and bystander API reads confirm the browser messages' audiences. Screenshot capture was unavailable and the viewport override did not take effect; mobile, full keyboard/visual and injected browser network-failure acceptance remain open. No final rules, mode, AI or publication gate changes. All 1373 pre-existing rooms, 2883 seats and auxiliary rows are unchanged. SQLite integrity/foreign keys pass; migration 0007 adds messages without replacing data. The healthy server was reused without restart. Private evidence: 20260921-table-talk. Verified source tree: 236dd55b6c15d55dbced735be67427e5fbd7fa348d583f119e67a03894ec21b0
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
export const TALK_LIMIT = 1000;
|
|
export const TALK_PAGE_SIZE = 50;
|
|
export type TalkDraft = {
|
|
id: string;
|
|
recipientId: string | null;
|
|
text: string;
|
|
};
|
|
export type TalkMessage = {
|
|
id: string;
|
|
senderId: string;
|
|
senderName: string;
|
|
senderFaction: string;
|
|
recipientId: string | null;
|
|
recipientName: string | null;
|
|
text: string;
|
|
createdAt: number;
|
|
};
|
|
export type TalkPage = { messages: TalkMessage[]; before: string | null };
|
|
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);
|
|
export function validTalkDraft(value: unknown): value is TalkDraft {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
const draft = value as Record<string, unknown>;
|
|
return (
|
|
Object.keys(draft).length === 3 &&
|
|
talkId(draft.id) &&
|
|
(draft.recipientId === null || talkId(draft.recipientId)) &&
|
|
typeof draft.text === 'string' &&
|
|
draft.text.length <= TALK_LIMIT &&
|
|
draft.text.trim().length > 0 &&
|
|
Array.from(draft.text).every((character) => {
|
|
const code = character.codePointAt(0)!;
|
|
return (
|
|
code === 9 || code === 10 || code === 13 || (code >= 32 && code !== 127)
|
|
);
|
|
})
|
|
);
|
|
}
|
|
export function talkDraftKey(room: string, seat: string) {
|
|
return `dune-table-talk-v1:${room}:${seat}`;
|
|
}
|
|
export function restoreTalkDraft(raw: string | null): TalkDraft | null {
|
|
if (!raw) return null;
|
|
try {
|
|
const value: unknown = JSON.parse(raw);
|
|
return validTalkDraft(value) ? value : null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
/** A bounded page merge: UUIDs identify only already-entitled messages. */
|
|
export function mergeTalkPages(older: TalkMessage[], newer: TalkMessage[]) {
|
|
const seen = new Set(newer.map((message) => message.id));
|
|
return [...older.filter((message) => !seen.has(message.id)), ...newer];
|
|
}
|
|
|
|
/** A late response may clear only its own tab-scoped retry proof. */
|
|
export function clearTalkDraft(
|
|
storage: Pick<Storage, 'getItem' | 'removeItem'>,
|
|
key: string,
|
|
draft: TalkDraft,
|
|
): boolean {
|
|
const saved = restoreTalkDraft(storage.getItem(key));
|
|
if (
|
|
!saved ||
|
|
saved.id !== draft.id ||
|
|
saved.recipientId !== draft.recipientId ||
|
|
saved.text !== draft.text
|
|
)
|
|
return false;
|
|
storage.removeItem(key);
|
|
return true;
|
|
}
|