Unread message count label per folder #83

Closed
opened 2026-07-02 02:03:42 +00:00 by JMR-dev · 0 comments
JMR-dev commented 2026-07-02 02:03:42 +00:00 (Migrated from github.com)

Context

The drawer (FolderDrawer.kt) lists each account's folders with a friendly label and role icon
(folderDisplayLabel/folderIcon, FolderDrawer.kt:129-150), but gives no indication of how much
unread mail each folder holds. Folder (domain/model/Folder.kt) carries no count, and neither
FolderDao nor MessageDao exposes a per-folder unread aggregate today — MessageDao only reads/writes
row-level isRead (no GROUP BY query), and FolderDao.observeForAccount/getForAccountOnce just
return the folder list.

Proposed behavior

Each folder row in the drawer shows its unread count when > 0 (e.g. "Inbox 12"), the common mail-client
convention. Material3's NavigationDrawerItem already has a badge slot
(NavigationDrawerItem(..., badge = { Text(count.toString()) })), so the drawer-side change is additive
once the count is available.

Suggested approach

  1. Add a MessageDao query aggregating unread, synced (inInbox = 1) rows per folder for an account,
    e.g. SELECT folder, COUNT(*) AS count FROM messages WHERE accountId = :accountId AND inInbox = 1 AND isRead = 0 GROUP BY folder, exposed as a Flow Room can map to a small data class or Map<String, Int>.
  2. Thread it through MailRepository/MailboxViewModel alongside folders (MailboxViewModel.kt:80-88),
    since FolderDrawer already receives the List<Folder> that would carry (or be zipped with) counts.
  3. Pass the count into NavigationDrawerItem's badge in FolderDrawer.kt:91-101.
  4. Hide the badge at 0 (matches how the Drafts/Outbox banners already hide at 0 in
    MailboxScreen.kt:257-264); consider a display cap (e.g. "99+") for very large counts.

Shares its data plumbing with #84 (bold account rows for unread mail) — worth building the underlying
per-account/per-folder unread-count source once and consuming it from both places.

Acceptance criteria

  • Each folder in the drawer shows its unread count when > 0, and nothing when 0.
  • Counts update live as mail is read/synced, with no manual refresh needed.
  • Unit test for the new DAO query / repository aggregation.
## Context The drawer (`FolderDrawer.kt`) lists each account's folders with a friendly label and role icon (`folderDisplayLabel`/`folderIcon`, `FolderDrawer.kt:129-150`), but gives no indication of how much unread mail each folder holds. `Folder` (`domain/model/Folder.kt`) carries no count, and neither `FolderDao` nor `MessageDao` exposes a per-folder unread aggregate today — `MessageDao` only reads/writes row-level `isRead` (no `GROUP BY` query), and `FolderDao.observeForAccount`/`getForAccountOnce` just return the folder list. ## Proposed behavior Each folder row in the drawer shows its unread count when > 0 (e.g. "Inbox 12"), the common mail-client convention. Material3's `NavigationDrawerItem` already has a `badge` slot (`NavigationDrawerItem(..., badge = { Text(count.toString()) })`), so the drawer-side change is additive once the count is available. ## Suggested approach 1. Add a `MessageDao` query aggregating unread, synced (`inInbox = 1`) rows per folder for an account, e.g. `SELECT folder, COUNT(*) AS count FROM messages WHERE accountId = :accountId AND inInbox = 1 AND isRead = 0 GROUP BY folder`, exposed as a `Flow` Room can map to a small data class or `Map<String, Int>`. 2. Thread it through `MailRepository`/`MailboxViewModel` alongside `folders` (`MailboxViewModel.kt:80-88`), since `FolderDrawer` already receives the `List<Folder>` that would carry (or be zipped with) counts. 3. Pass the count into `NavigationDrawerItem`'s `badge` in `FolderDrawer.kt:91-101`. 4. Hide the badge at 0 (matches how the Drafts/Outbox banners already hide at 0 in `MailboxScreen.kt:257-264`); consider a display cap (e.g. "99+") for very large counts. Shares its data plumbing with #84 (bold account rows for unread mail) — worth building the underlying per-account/per-folder unread-count source once and consuming it from both places. ## Acceptance criteria - [ ] Each folder in the drawer shows its unread count when > 0, and nothing when 0. - [ ] Counts update live as mail is read/synced, with no manual refresh needed. - [ ] Unit test for the new DAO query / repository aggregation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: JMR-dev/LibreMail#83