Merge pull request #5707 from k9mail/fix_account_flow
Avoid crash when getting Flow for non-existent account
This commit is contained in:
commit
cbd8ab5ded
1 changed files with 8 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue