fix(mobile): clear chat badge when app returns to foreground#2354
Merged
fix(mobile): clear chat badge when app returns to foreground#2354
Conversation
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.
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by gpt-5.4-2026-03-05 · 149,617 tokens |
eshurakov
approved these changes
Apr 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Root cause
markChatReadonly 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
useFocusEffectbecause navigation focus never changed. Both the server row and OS badge stay at 1.Fix
Register an
AppStatelistener insideuseFocusEffect. Onactivetransition it callsmarkChatReadfor 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
markChatReadcalls)pnpm format && pnpm typecheck && pnpm lint && pnpm check:unusedall pass