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

View File

@ -166,8 +166,6 @@ class RegisterAccounts(
if (notificationToken.isNotEmpty()) {
withContext(Dispatchers.IO) {
signEventsToProveControlOfAccounts(accounts, notificationToken) { postRegistrationEvent(it) }
PushNotificationUtils.hasInit = true
}
}
}

View File

@ -28,16 +28,18 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.tasks.await
object PushNotificationUtils {
var hasInit: Boolean = false
var hasInit: List<AccountInfo>? = null
suspend fun init(accounts: List<AccountInfo>) =
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)