Files
webmail/lib/mark-as-read-delay.ts
T
Peterka35 bbc3c2123e fix: follow markAsReadDelay when expanding a conversation or opening a Pro folder row
Expanding a conversation in the message list (row click, expand chevron,
or the `x` shortcut) and clicking a row in a Pro folder tab marked the
messages read straight away. They ignored "Mark as read: Never" and any
delay, which the reading pane and the conversation view follow.

Route them through one helper, scheduleAutoMarkAsRead: -1 never marks,
0 marks at once, any other value marks after that many milliseconds and
returns a cancel function.

- New store action autoMarkExpandedThreadAsRead keeps one pending timer
  per thread key. Collapsing the thread, or collapsing all threads, drops
  it. Both expansion paths (EmailList and the `x` handler in MailApp) use
  it.
- MailApp's handleEmailSelect drops the pending mark of every expanded
  thread other than the one the newly opened message belongs to, through
  cancelAutoMarkThreadAsRead. Moving on with `j`/`k` or a click no longer
  lets the delayed mark land on a conversation the user has left. The
  thread stays expanded.
- ProFolderTabBody schedules the row mark through the helper and drops a
  pending one when another row is opened or the tab unmounts.
2026-10-17 21:01:34 +02:00

25 lines
960 B
TypeScript

// Automatic "mark as read" timing for surfaces that mark a message read
// because it was shown. Used by thread expansion and Pro folder rows; same
// rules as the reading pane (`mail-app.tsx`) and `useMarkReadWhenShown`.
//
// `markAsReadDelay` is the user's setting in milliseconds: -1 = never,
// 0 = instantly, anything else = after that many milliseconds. Surfaces that
// skipped the setting marked mail read even with "Never" selected.
const noop = () => {};
/**
* Runs `mark` according to `markAsReadDelay` and returns a function that
* cancels a still-pending delayed mark. "Never" (any negative value) does
* nothing; 0 runs `mark` synchronously.
*/
export function scheduleAutoMarkAsRead(markAsReadDelay: number, mark: () => void): () => void {
if (markAsReadDelay < 0) return noop;
if (markAsReadDelay === 0) {
mark();
return noop;
}
const timeout = setTimeout(mark, markAsReadDelay);
return () => clearTimeout(timeout);
}