Fixes lack of notification when a new account is logged into the app and before the app restarts.

This commit is contained in:
Vitor Pamplona
2024-12-10 18:39:45 -05:00
parent 8b80ac13db
commit 83e942a7be
2 changed files with 4 additions and 4 deletions
@@ -166,8 +166,6 @@ class RegisterAccounts(
if (notificationToken.isNotEmpty()) { if (notificationToken.isNotEmpty()) {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
signEventsToProveControlOfAccounts(accounts, notificationToken) { postRegistrationEvent(it) } signEventsToProveControlOfAccounts(accounts, notificationToken) { postRegistrationEvent(it) }
PushNotificationUtils.hasInit = true
} }
} }
} }
@@ -28,16 +28,18 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.tasks.await import kotlinx.coroutines.tasks.await
object PushNotificationUtils { object PushNotificationUtils {
var hasInit: Boolean = false var hasInit: List<AccountInfo>? = null
suspend fun init(accounts: List<AccountInfo>) = suspend fun init(accounts: List<AccountInfo>) =
with(Dispatchers.IO) { with(Dispatchers.IO) {
if (hasInit) { if (hasInit?.equals(accounts) == true) {
return@with return@with
} }
// get user notification token provided by firebase // get user notification token provided by firebase
try { try {
RegisterAccounts(accounts).go(FirebaseMessaging.getInstance().token.await()) RegisterAccounts(accounts).go(FirebaseMessaging.getInstance().token.await())
hasInit = accounts.toList()
} catch (e: Exception) { } catch (e: Exception) {
if (e is CancellationException) throw e if (e is CancellationException) throw e
Log.e("Firebase token", "failed to get firebase token", e) Log.e("Firebase token", "failed to get firebase token", e)