Avoid crash when getting flow for non-existent account

This commit is contained in:
cketti 2021-09-29 23:47:34 +02:00
parent 3caaa4f470
commit 84eca27d4f

View file

@ -115,8 +115,13 @@ class Preferences internal constructor(
@OptIn(ExperimentalCoroutinesApi::class)
override fun getAccountFlow(accountUuid: String): Flow<Account> {
return callbackFlow<Account> {
val initialAccount = getAccount(accountUuid) ?: return@callbackFlow
return callbackFlow {
val initialAccount = getAccount(accountUuid)
if (initialAccount == null) {
close()
return@callbackFlow
}
send(initialAccount)
val listener = AccountsChangeListener {
@ -124,7 +129,7 @@ class Preferences internal constructor(
if (account != null) {
sendBlockingSilently(account)
} else {
channel.close()
close()
}
}
addOnAccountsChangeListener(listener)