Skip to content

User notifications to people, step 1: the migration and the store - #95

Merged
limeflash merged 4 commits into
mainfrom
feat/user-notify-store
Dec 3, 2026
Merged

limeflash merged 4 commits into
mainfrom
feat/user-notify-store

Conversation

@limeflash

Copy link
Copy Markdown
Collaborator

Step 1 of the notifications to people (plan: Telegram bot for people + events for the Mistgate app). Storage only: no service, RPC or UI yet.

What

Migration 00165_user_notify.sql and the store for:

  • user_telegram_bot: the people's bot (separate from the admins' one); the token is vault ciphertext.
  • user_telegram_chat: linked chats, the chat id sealed (chat_enc) and found by keyed MAC (chat_mac); the per-person limit is enforced inside the insert.
  • user_telegram_code: one-time link codes, one active per person.
  • user_notice: the outbox for both channels (Telegram = 1, app = 2), with dedupe, leases, retries, owner drafts (approval, draft_id: one failure draft per incident covers every affected person) and Telegram message refs keyed by chat row id for editing an incident message.
  • user_incident: at most one open per person (partial unique index).
  • user_notify_setting / user_notify_override: global and per-person settings; defaults live in code.

Replacing or clearing the bot drops chats, codes and the Telegram channel of unfinished notices; app delivery stays.

Tests

go test ./internal/panel/store/... (table tests: chat limit race on the last slot, code races, lease exclusivity with 4 workers, draft approve/expire, purge, incidents, cascade, migration up/down); schema snapshots updated; scripts/test-edge-store.ps1 passes (fake D1).

🤖 Generated with Claude Code

limeflash and others added 4 commits December 3, 2026 15:47
Migration 00165 and the store code behind the notifications to people (spec notifications-panel-spec, PR 1): the bot of its
own, the chats of the people who linked one with their one-time codes, the outbox user_notice, the incidents and the settings.
No service, RPC or UI yet.

- user_notice is an outbox with at-least-once delivery: dedupe, a lease taken and given back by id, approval for the owner's
  drafts. A dismissed or expired draft is finished at once (done_at and a result of the same name), so retention purges it.
- A failure draft is one per incident while the rows are one per person: draft_id groups them, and approving, dismissing or
  expiring the draft decides every row (SetUserNoticeApprovalByDraft, ExpireUserNoticeApprovals).
- One open incident per person, by a partial unique index; OpenUserIncident returns the open one with ErrUserIncidentOpen.
- A chat links atomically against the limit (the insert holds the check); ErrUserTelegramChatLimit, ErrUserTelegramChatTaken.
- A different bot, or none, drops the chats, the pending codes and the Telegram channel of the unfinished notices.
- Finish and Retry never overwrite what the app writes (the devices that pulled an event); Retry keeps the message ids so a
  retry sends to the chats that have not got it.
- draft_id and incident_id are NULL when absent, so a partial index covers only the rows that have one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hat id

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t and chats

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s it; schema goldens

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@limeflash
limeflash merged commit e989451 into main Dec 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant