aaac816dc2
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 15s
CI / ui (pull_request) Successful in 49s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m16s
Persist per-message read state as a chat_messages.unread_seats bitmask
(migration 00008): a text message seeds every recipient seat's bit, a nudge
only the awaited seat's. A seat's bit clears when the player opens the move
history or chat (POST /games/:id/chat/read, sent only when something is
unread), and a nudge additionally clears when its recipient answers by moving
(a wired game NudgeClearer, dependency-inverted so game keeps off social).
UI shows a per-viewer unread dot in the lobby (next to the opponent) and the
game score bar — the unread_chat game-view flag seeds it from authoritative
REST views, live chat/nudge events raise it. Opening the move history counts
as reading (even without entering chat): the 💬 fade-blinks twice and the
client acks. Admin Messages gains an unread-only filter, a read/unread column,
and a per-message card with the per-seat read breakdown. Observability:
chat_read_duration histogram + chat_unread_messages gauge + social tracing.
21 lines
1.1 KiB
SQL
21 lines
1.1 KiB
SQL
-- +goose Up
|
|
-- A per-message bitmask of the seats that have NOT yet read this chat entry: bit i is
|
|
-- set while seat i still has the message unread, and is cleared when that seat reads it
|
|
-- (opens the move history / chat, or — for a nudge — takes its move). A text message
|
|
-- starts with the bits of every seated recipient except the sender; a nudge starts with
|
|
-- only the awaited player's bit. The mask is inverted so "anything unread" is a plain
|
|
-- `unread_seats <> 0`, which the lobby badge, the admin filter and the unread gauge all
|
|
-- use. The read time itself is not retained. See docs/ARCHITECTURE.md §8 (Read receipts).
|
|
SET search_path = backend, pg_catalog;
|
|
|
|
ALTER TABLE chat_messages ADD COLUMN unread_seats smallint NOT NULL DEFAULT 0;
|
|
|
|
-- Partial index serving the unread scans (per-viewer lobby lookup, admin unread filter,
|
|
-- the unread-count gauge): only the comparatively few still-unread rows are indexed.
|
|
CREATE INDEX chat_messages_unread_idx ON chat_messages (game_id) WHERE unread_seats <> 0;
|
|
|
|
-- +goose Down
|
|
SET search_path = backend, pg_catalog;
|
|
DROP INDEX chat_messages_unread_idx;
|
|
ALTER TABLE chat_messages DROP COLUMN unread_seats;
|