Fixes lack of notification when a new account is logged into the app and before the app restarts.
This commit is contained in:
-2
@@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user