Skip to content

fix(mobile): clear chat badge when app returns to foreground#2354

Merged
iscekic merged 1 commit intomainfrom
fix/mobile-badge-clear-on-foreground
Apr 13, 2026
Merged

fix(mobile): clear chat badge when app returns to foreground#2354
iscekic merged 1 commit intomainfrom
fix/mobile-badge-clear-on-foreground

Conversation

@iscekic
Copy link
Copy Markdown
Contributor

@iscekic iscekic commented Apr 13, 2026

Summary

Fixes a bug where the push-notification badge count stays stuck after the user receives a notification while the app is backgrounded on the chat screen.

Repro

  1. Open a chat.
  2. Send a message.
  3. Background the app.
  4. Agent replies → OS badge shows 1.
  5. Foreground the app (chat screen is still focused).
  6. Expected: badge clears to 0.
  7. Actual: badge stays at 1 until you navigate away and back.

Root cause

markChatRead only had two triggers:

  • useFocusEffect — fires on navigation focus change, not on app-state change.
  • addNotificationReceivedListener — fires only when a notification arrives while the app is foregrounded.

A notification received while backgrounded hits neither, and the subsequent foreground doesn't re-run useFocusEffect because navigation focus never changed. Both the server row and OS badge stay at 1.

Fix

Register an AppState listener inside useFocusEffect. On active transition it calls markChatRead for the focused chat. The listener is scoped to focus — it's added when the chat gains focus and removed on blur/unmount, so it only fires for the chat the user is actually on.

Test plan

  • Background app on chat screen → receive notification → foreground → badge clears to 0
  • Receive notification for a different chat while on this chat → badge reflects unread from other chat after foreground
  • Navigate away from chat → listener unregistered (no stray markChatRead calls)
  • pnpm format && pnpm typecheck && pnpm lint && pnpm check:unused all pass

useFocusEffect does not re-run when the app is backgrounded and then
foregrounded (focus is a navigation concept, not an app-state one), and
addNotificationReceivedListener does not fire for notifications that
arrived while the app was backgrounded. As a result, when a user received
a chat notification while backgrounded on the chat screen, foregrounding
the app displayed the new message but left the OS badge stuck at 1.

Register an AppState listener inside useFocusEffect that calls
markChatRead on transitions to 'active', scoped to the focused chat.
@iscekic iscekic self-assigned this Apr 13, 2026
@iscekic iscekic enabled auto-merge (squash) April 13, 2026 10:50
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 13, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (1 files)
  • apps/mobile/src/components/kiloclaw/chat.tsx

Reviewed by gpt-5.4-2026-03-05 · 149,617 tokens

@iscekic iscekic merged commit 0598530 into main Apr 13, 2026
19 checks passed
@iscekic iscekic deleted the fix/mobile-badge-clear-on-foreground branch April 13, 2026 10:54
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.

2 participants