Skip to content

feat(messages): reversible message actions with undo - #310

Merged
hieunc229 merged 16 commits into
hieunc229:mainfrom
antonio-ivanovski:feat/mail-action-undo
Nov 18, 2026
Merged

hieunc229 merged 16 commits into
hieunc229:mainfrom
antonio-ivanovski:feat/mail-action-undo

Conversation

@antonio-ivanovski

Copy link
Copy Markdown
Contributor

Summary

Adds a shared reversible-action layer with an Undo toast, so explicit message changes can be taken back from wherever they were made.

  • Undoable actions: archive, trash, move to inbox or a folder, read/unread, star/unstar, snooze/unsnooze — from list rows, the bulk bar, the reader, and thread cards.
  • Toast stack: bottom-left queue with a 20-second window, dismiss, retry for transient failures, and screen-reader announcements. Timers pause while the toast has focus, while a modal, compose surface, mobile sidebar, or hidden tab owns interaction.
  • Bulk selections restore as a set, with partial results reported when a row can no longer be changed.
  • Reader follows the optimistic state; an action that removes the open message from the view closes it, and late responses cannot navigate back.
  • Deliberately not undoable: permanent delete, empty folder, block/unsubscribe, spam training (spam/not-spam), and automatic mark-read. Block-and-trash still navigates as before.

How it works

  • POST /api/messages/actions applies an action and returns a signed token plus the exact before/after state of every message it actually changed. { "op": "undo" } restores from that token.
  • Tokens are HMAC-signed, bound to the requesting user, expire, and carry a nonce. The message_action_undo_claims table makes each token single-use: the claim is written first, kept once any row commits, and released only on a zero-progress failure so an otherwise safe retry can succeed.
  • Apply uses compare-and-swap on every field the action writes and signs only the state it actually committed. Undo restores only the changed fields, and only while they still hold the action's result, so a later action is never clobbered.
  • Pending overlays and conversation locks keep optimistic read/star/grouped aggregates stable through refetches; settled state is committed to caches before the overlay is dropped.
  • Writes stay bounded for D1: SQLite/Postgres group rows by written field set and run one OR-ed per-row CAS with a CASE SET for values that differ, chunked under D1's bound-parameter limit. MySQL writes per row because its RETURNING shim can over-report a concurrently changed batch.

Migrations

Adds message_action_undo_claims in all three dialects:

  • SQLite/D1: drizzle/migrations/0088_message_action_undo_claims.sql
  • PostgreSQL: drizzle/migrations-pg/0012_message_action_undo_claims.sql
  • MySQL: drizzle/migrations-mysql/0012_message_action_undo_claims.sql

Migration bundles are regenerated and committed. The claims table is registered as internal and deliberately excluded from backups: restoring a stale claim would let an already-used undo token replay. For local D1, apply it with:

npx wrangler d1 migrations apply DB --local

Testing

  • tsc --noEmit: clean.
  • Focused undo and database suites: 107 passed, 2 skipped.
  • Full suite: 760 passed, 7 failed, 2 skipped. The same 7 failures reproduce on main (pt-BR missing account.apps, two overflow/layout checks, sender-check notice, MX replacement, group divider, locale SSR).
  • New coverage includes 120-row apply/undo query bounds, a 100-row snooze restore with distinct timestamps, the folder-move CAS race, token tamper/replay/expiry and cross-user use, partial-undo claims, optimistic overlays across refetches, grouped aggregates, toast queue/focus/accessibility, and an e2e spec under tests/e2e/message-undo.spec.ts.
undo-actions.webm

The recording shows a single archive, a bulk archive, and a reader star all being undone.

@hieunc229
hieunc229 merged commit c738d9c into hieunc229:main Nov 18, 2026
1 check passed
@hieunc229

Copy link
Copy Markdown
Owner

Nice one @antonio-ivanovski, I just move the toast close to the screen's left side and align the toast for sending message at the same position

@antonio-ivanovski

Copy link
Copy Markdown
Contributor Author

Nice one @antonio-ivanovski, I just move the toast close to the screen's left side and align the toast for sending message at the same position

Makes sense - my idea was to have it closer to the design of gmail but having it unified to all toasts makes sense.

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.

2 participants