Skip to content

fix(tui): sync unread badge on delete#1491

Open
youdie006 wants to merge 1 commit into
floatpane:masterfrom
youdie006:fix/unread-counter-sync
Open

fix(tui): sync unread badge on delete#1491
youdie006 wants to merge 1 commit into
floatpane:masterfrom
youdie006:fix/unread-counter-sync

Conversation

@youdie006

@youdie006 youdie006 commented Jun 19, 2026

Copy link
Copy Markdown

What?

After deleting or archiving emails, the delete/archive Update handlers (DeleteEmailMsg, ArchiveEmailMsg, BatchDeleteEmailsMsg, BatchArchiveEmailsMsg) now call m.syncUnreadBadge(), mirroring the read/unread handlers, so the unread badge recomputes immediately. syncUnreadBadge also caches the count on every OS so the behavior is unit-testable. Adds four tests asserting the macOS badge drops to 0 after the last unread email is deleted/archived.

Why?

The delete/archive handlers mutated the unread stores but never recomputed the unread menu bar badge, so the counter only refreshed on the next fetch.

The delete/archive Update handlers mutated the unread stores but never
recomputed the badge, so the unread counter only refreshed on the next fetch.
Call m.syncUnreadBadge() after the store mutation in DeleteEmailMsg,
ArchiveEmailMsg, BatchDeleteEmailsMsg and BatchArchiveEmailsMsg, mirroring the
read/unread handlers. syncUnreadBadge now also caches the count on every OS so
the behavior is testable.

Closes floatpane#1404
@youdie006 youdie006 requested a review from a team as a code owner June 19, 2026 06:24

@floatpanebot floatpanebot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @youdie006! Please fix the following issues with your PR:

  • Title: Is too long (40 characters). The PR title must be strictly under 40 characters.
  • Body: Missing the ## What? or ## Why? headings required by the PR template.

@floatpanebot floatpanebot added bug Something isn't working size/M Diff: 51–200 lines labels Jun 19, 2026
@floatpanebot

Copy link
Copy Markdown
Member

Benchmark report — no significant change

Metrics worse: 0 · better: 0 (threshold: ±3%).

benchstat output
goos: linux
goarch: amd64
pkg: github.com/floatpane/matcha/backend
cpu: AMD EPYC 7763 64-Core Processor                
                           │   old.txt    │              new.txt               │
                           │    sec/op    │    sec/op     vs base              │
ParseSearchQuery_Simple-4    2.580µ ± 21%   2.578µ ± 30%       ~ (p=0.818 n=6)
ParseSearchQuery_Complex-4   6.023µ ± 55%   8.266µ ± 32%       ~ (p=0.310 n=6)
TokenizeSearchQuery-4        4.910µ ± 35%   4.754µ ± 95%       ~ (p=0.981 n=6)
geomean                      4.241µ         4.662µ        +9.92%

                           │   old.txt   │              new.txt               │
                           │    B/op     │    B/op     vs base                │
ParseSearchQuery_Simple-4    26.00 ± 23%   26.00 ± 0%       ~ (p=1.000 n=6)
ParseSearchQuery_Complex-4   762.0 ±  0%   762.0 ± 0%       ~ (p=1.000 n=6) ¹
TokenizeSearchQuery-4        176.0 ±  0%   176.0 ± 0%       ~ (p=1.000 n=6) ¹
geomean                      151.6         151.6       +0.00%
¹ all samples are equal

                           │  old.txt   │              new.txt               │
                           │ allocs/op  │ allocs/op   vs base                │
ParseSearchQuery_Simple-4    2.000 ± 0%   2.000 ± 0%       ~ (p=1.000 n=6) ¹
ParseSearchQuery_Complex-4   23.00 ± 0%   23.00 ± 0%       ~ (p=1.000 n=6) ¹
TokenizeSearchQuery-4        9.000 ± 0%   9.000 ± 0%       ~ (p=1.000 n=6) ¹
geomean                      7.453        7.453       +0.00%
¹ all samples are equal

pkg: github.com/floatpane/matcha/tui
                    │   old.txt    │               new.txt               │
                    │    sec/op    │    sec/op      vs base              │
LogPanelView-4        162.6µ ± 14%    167.3µ ± 11%       ~ (p=0.937 n=6)
SearchOverlayView-4   169.5µ ± 15%    190.1µ ± 11%       ~ (p=0.065 n=6)
InboxConstruction-4   947.2µ ± 14%   1028.7µ ±  7%       ~ (p=0.093 n=6)
geomean               296.7µ          319.8µ        +7.80%

                    │    old.txt    │               new.txt               │
                    │     B/op      │     B/op       vs base              │
LogPanelView-4        44.67Ki ± 51%   44.67Ki ± 51%       ~ (p=1.000 n=6)
SearchOverlayView-4   56.14Ki ± 41%   56.14Ki ± 41%       ~ (p=0.556 n=6)
InboxConstruction-4   874.3Ki ±  0%   874.3Ki ±  0%       ~ (p=0.556 n=6)
geomean               129.9Ki         129.9Ki        +0.00%

                    │   old.txt   │              new.txt              │
                    │  allocs/op  │  allocs/op   vs base              │
LogPanelView-4         714.0 ± 0%    714.0 ± 0%       ~ (p=1.000 n=6)
SearchOverlayView-4    926.0 ± 0%    926.0 ± 0%       ~ (p=0.879 n=6)
InboxConstruction-4   3.478k ± 0%   3.478k ± 0%       ~ (p=1.000 n=6)
geomean               1.320k        1.320k       -0.00%

auto-generated by benchmarks.yml

@youdie006 youdie006 changed the title fix(tui): sync unread badge after delete fix(tui): sync unread badge on delete Jun 19, 2026
@floatpanebot floatpanebot dismissed their stale review June 19, 2026 06:56

Formatting issues have been resolved. Thank you!

@andrinoff

Copy link
Copy Markdown
Member

@youdie006 thank you for your contribution.

The issue was not about this badge, but rather the folder unread. Unlinking the issue, I'll check out the PR a bit later.

@floatpanebot floatpanebot added the os/macos macOS-specific label Jun 19, 2026
@andrinoff

Copy link
Copy Markdown
Member

/backport v1

@floatpanebot floatpanebot added the backport/v1 Merge to master and backport to release/v1 label Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/v1 Merge to master and backport to release/v1 bug Something isn't working os/macos macOS-specific size/M Diff: 51–200 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants