feat: pre-fetch next email body to eliminate loading delay after delete #381

Merged
guettlibot merged 2 commits from refs/pull/381/head into main 2026-06-03 23:42:17 +00:00
guettlibot commented 2026-06-03 22:19:37 +00:00 (Migrated from codeberg.org)

Summary

  • When viewing an email and then deleting (or archiving/moving/snoozing) it, the app navigates to the next email in the thread list.
  • getEmailBody fetches from the network on a cache miss, causing the hourglass / loading spinner the issue describes.
  • EmailDetailNotifier now fires a background getEmailBody call for the next thread's latestEmailId as soon as the current email finishes loading.
  • getEmailBody already caches results in the EmailBodies table with a 7-day TTL, so by the time the user triggers a navigation action the body is pre-warmed and renders instantly.

What changed

lib/di.dartEmailDetailNotifier.build() calls _prefetchNextEmailBody (fire-and-forget via unawaited) after loading the current email. The helper respects the afterMailViewAction user preference: if set to showMailbox it does nothing.

Test plan

  • Open an email, delete it — next email should appear without the spinner
  • Verify the same for archive, move, and snooze actions
  • Verify behaviour is unchanged when afterMailViewAction is set to showMailbox
  • Verify the last email in the list still pops back to the mailbox list correctly

Closes #367

## Summary - When viewing an email and then deleting (or archiving/moving/snoozing) it, the app navigates to the next email in the thread list. - `getEmailBody` fetches from the network on a cache miss, causing the hourglass / loading spinner the issue describes. - `EmailDetailNotifier` now fires a background `getEmailBody` call for the next thread's `latestEmailId` as soon as the current email finishes loading. - `getEmailBody` already caches results in the `EmailBodies` table with a 7-day TTL, so by the time the user triggers a navigation action the body is pre-warmed and renders instantly. ## What changed `lib/di.dart` — `EmailDetailNotifier.build()` calls `_prefetchNextEmailBody` (fire-and-forget via `unawaited`) after loading the current email. The helper respects the `afterMailViewAction` user preference: if set to `showMailbox` it does nothing. ## Test plan - [ ] Open an email, delete it — next email should appear without the spinner - [ ] Verify the same for archive, move, and snooze actions - [ ] Verify behaviour is unchanged when `afterMailViewAction` is set to `showMailbox` - [ ] Verify the last email in the list still pops back to the mailbox list correctly Closes #367
Sign in to join this conversation.