From 83e942a7bef9410b7e5c8f73b13add66a16d83da Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 10 Dec 2024 18:39:45 -0500 Subject: [PATCH] Fixes lack of notification when a new account is logged into the app and before the app restarts. --- .../amethyst/service/notifications/RegisterAccounts.kt | 2 -- .../amethyst/service/notifications/PushNotificationUtils.kt | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt index 34579cf64..498e00dc7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/RegisterAccounts.kt @@ -166,8 +166,6 @@ class RegisterAccounts( if (notificationToken.isNotEmpty()) { withContext(Dispatchers.IO) { signEventsToProveControlOfAccounts(accounts, notificationToken) { postRegistrationEvent(it) } - - PushNotificationUtils.hasInit = true } } } diff --git a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt index caccf4374..0c2726702 100644 --- a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt +++ b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt @@ -28,16 +28,18 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.tasks.await object PushNotificationUtils { - var hasInit: Boolean = false + var hasInit: List? = null suspend fun init(accounts: List) = with(Dispatchers.IO) { - if (hasInit) { + if (hasInit?.equals(accounts) == true) { return@with } // get user notification token provided by firebase try { RegisterAccounts(accounts).go(FirebaseMessaging.getInstance().token.await()) + + hasInit = accounts.toList() } catch (e: Exception) { if (e is CancellationException) throw e Log.e("Firebase token", "failed to get firebase token", e)