parent
e91c750cb0
commit
a8a97b6834
1 changed files with 11 additions and 7 deletions
|
@ -72,14 +72,18 @@ class AccountManager @Inject constructor(db: AppDatabase) {
|
|||
accountDao.insertOrReplace(it)
|
||||
}
|
||||
// check if this is a relogin with an existing account, if yes update it, otherwise create a new one
|
||||
val newAccountEntity = accounts.find { account ->
|
||||
val existingAccountIndex = accounts.indexOfFirst { account ->
|
||||
domain == account.domain && newAccount.id == account.accountId
|
||||
}?.copy(
|
||||
}
|
||||
val newAccountEntity = if (existingAccountIndex != -1) {
|
||||
accounts[existingAccountIndex].copy(
|
||||
accessToken = accessToken,
|
||||
clientId = clientId,
|
||||
clientSecret = clientSecret,
|
||||
oauthScopes = oauthScopes
|
||||
) ?: run {
|
||||
oauthScopes = oauthScopes,
|
||||
isActive = true
|
||||
).also { accounts[existingAccountIndex] = it }
|
||||
} else {
|
||||
val maxAccountId = accounts.maxByOrNull { it.id }?.id ?: 0
|
||||
val newAccountId = maxAccountId + 1
|
||||
AccountEntity(
|
||||
|
|
Loading…
Reference in a new issue