Skip to content

Harden Gmail delete flow and sort selection handling#92

Open
ZingBing wants to merge 1 commit intoInboxWhiz:mainfrom
ZingBing:mass-delete-banner
Open

Harden Gmail delete flow and sort selection handling#92
ZingBing wants to merge 1 commit intoInboxWhiz:mainfrom
ZingBing:mass-delete-banner

Conversation

@ZingBing
Copy link

Fixes #81

Summary

This PR hardens Gmail delete automation to be safer and more reliable across both normal and bulk delete flows, including Gmail AI sort variations and asynchronous bulk-delete toasts.

What Changed

Delete flow safety and scope control

  • Added strict search-scope checks so destructive actions only run when the expected query is active.
  • Added query helpers to build and validate expected from:(...) search scope.

Sort behavior (Most recent)

  • Added best-effort _ensureMostRecentFilter() logic:
    • If sort controls are present, attempts to switch to Most recent.
    • If controls are absent (e.g. non-AI Gmail), logs and continues without blocking deletion.

Bulk vs non-bulk handling

  • Unified delete execution into a single flow that:
    • Selects current-page results
    • Detects optional Select all conversations... banner
    • Only attempts bulk-confirm dialog handling when bulk selection is actually used
  • Bulk confirm detection targets the correct Gmail dialog structure (dialog/alertdialog, data-mdc-dialog-action="ok").

Success detection (toast handling)

  • Improved delete confirmation detection to support both:
    • Standard success toasts (moved to Trash/Bin)
    • Async bulk toasts (e.g. “remaining conversations in a few minutes”, “might take longer”)
  • Uses both mutation observation and polling to reduce missed toast updates.

Error behavior

  • Missing critical controls now fail explicitly (e.g. visible Delete button not found).
  • Prevents false success when key destructive steps did not actually execute.

Why

Previously there were two opposite failure modes:

  • False success when deletion did not fully apply.
  • False error when deletion succeeded but toast/confirmation detection missed variant Gmail messaging.

This PR keeps strict safety checks while improving practical reliability of user-facing success/error status.

Testing Notes

Manually tested in Gmail:

  • Non-bulk delete (single-page results): delete + success path.
  • Bulk delete (with Select all conversations...): confirm dialog + async toast variant.
  • Sort control on Most recent vs Most relevant.
  • Sort control fallback behavior remains non-blocking.

Notes

  • No UI component changes; behavior changes are in content-script service logic.
  • package-lock.json was not included in this PR.
  • I added some safety guards because I accidentally bulk deleted my entire inbox when testing... whoops

@ZingBing
Copy link
Author

As an additional note, this PR may also address #82 (the deleting portion, unsubscribe has not been addressed) and #73. I can look into the errors from 73 but this PR changes the way bulk deletes are handled.

@anna-st-40 Would you or copilot be able to review this PR? I believe it would help the overall functionality of the extension.

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.

Extension can only delete one page of emails at a time

1 participant