From 88f52201d152814edd2ae5663091cbd4f314b412 Mon Sep 17 00:00:00 2001 From: sanasol Date: Wed, 4 Mar 2026 21:25:54 +0100 Subject: [PATCH] fix: show notification permission rationale in release builds The notification permission prompt was gated behind BuildConfig.DEBUG, so release users were never prompted. Also adds: - Auto-register FCM token when permissions are already granted - Google Play Services availability check before FCM registration - Error handling around subscribePush Signed-off-by: sanasol --- .../chat/stoat/screens/chat/ChatRouterScreen.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/chat/stoat/screens/chat/ChatRouterScreen.kt b/app/src/main/java/chat/stoat/screens/chat/ChatRouterScreen.kt index 474c5f31..b715d652 100644 --- a/app/src/main/java/chat/stoat/screens/chat/ChatRouterScreen.kt +++ b/app/src/main/java/chat/stoat/screens/chat/ChatRouterScreen.kt @@ -193,9 +193,11 @@ class ChatRouterViewModel @Inject constructor( val hasNotificationPermission = NotificationManagerCompat.from(context).areNotificationsEnabled() - // right now we only show this in debug builds so Chucker can show its notification - if (!hasNotificationPermission && BuildConfig.DEBUG) { + if (!hasNotificationPermission) { showNotificationRationale = true + } else { + // Already have permission, register FCM token automatically + setRegisterForNotifications() } } } @@ -217,6 +219,11 @@ class ChatRouterViewModel @Inject constructor( fun setRegisterForNotifications() { showNotificationRationale = false + val gmsAvailability = com.google.android.gms.common.GoogleApiAvailability.getInstance() + if (gmsAvailability.isGooglePlayServicesAvailable(context) != com.google.android.gms.common.ConnectionResult.SUCCESS) { + Log.w("FCM", "Google Play Services not available, skipping push registration") + return + } FirebaseMessaging.getInstance().token.addOnCompleteListener( OnCompleteListener { task -> if (!task.isSuccessful) { @@ -228,7 +235,11 @@ class ChatRouterViewModel @Inject constructor( val token = task.result viewModelScope.launch { kvStorage.set("fcmToken", token) - subscribePush(auth = token) + try { + subscribePush(auth = token) + } catch (e: Exception) { + Log.e("FCM", "Failed to subscribe push", e) + } } } )