Fix stale push notification replay after account switch

The native lastResponse cache is only cleared when handlePushNotificationEntry
consumes it on cold start. Foreground/background taps handled by the response
listener never cleared it, so a later getLastNotificationResponse call (fired
by onNavigationReady when the tree remounts on account switch) would replay
the stale payload and ping-pong the user back to the previous account.

Clear lastResponse from the response listener, and guard
handlePushNotificationEntry behind a once-per-runtime flag so remounts don't
re-consume a launching notification.
This commit is contained in:
vineyardbovines
2026-06-08 15:06:25 -04:00
parent 9b5fc19613
commit 5e604265b4
2 changed files with 22 additions and 0 deletions
+12
View File
@@ -380,6 +380,18 @@ export function useNotificationsHandler() {
handleNotification(payload)
Notifications.dismissAllNotificationsAsync()
// Also clear the native `lastResponse` cache. Otherwise a subsequent
// `getLastNotificationResponse()` (e.g. on an account-switch remount,
// which re-runs `handlePushNotificationEntry`) would replay this
// payload and ping-pong the user back to the previous account/chat.
try {
Notifications.clearLastNotificationResponse()
} catch (error) {
notyLogger.error(
`useNotificationsHandler: error clearing notification response`,
{error},
)
}
} else {
logger.error('useNotificationsHandler: received no payload', {
identifier: e.notification.request.identifier,