Merge pull request #5707 from k9mail/fix_account_flow

Avoid crash when getting Flow for non-existent account
This commit is contained in:
cketti 2021-09-30 14:11:59 +02:00 committed by GitHub
commit cbd8ab5ded
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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)