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)
|
accountDao.insertOrReplace(it)
|
||||||
}
|
}
|
||||||
// check if this is a relogin with an existing account, if yes update it, otherwise create a new one
|
// 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
|
domain == account.domain && newAccount.id == account.accountId
|
||||||
}?.copy(
|
}
|
||||||
|
val newAccountEntity = if (existingAccountIndex != -1) {
|
||||||
|
accounts[existingAccountIndex].copy(
|
||||||
accessToken = accessToken,
|
accessToken = accessToken,
|
||||||
clientId = clientId,
|
clientId = clientId,
|
||||||
clientSecret = clientSecret,
|
clientSecret = clientSecret,
|
||||||
oauthScopes = oauthScopes
|
oauthScopes = oauthScopes,
|
||||||
) ?: run {
|
isActive = true
|
||||||
|
).also { accounts[existingAccountIndex] = it }
|
||||||
|
} else {
|
||||||
val maxAccountId = accounts.maxByOrNull { it.id }?.id ?: 0
|
val maxAccountId = accounts.maxByOrNull { it.id }?.id ?: 0
|
||||||
val newAccountId = maxAccountId + 1
|
val newAccountId = maxAccountId + 1
|
||||||
AccountEntity(
|
AccountEntity(
|
||||||
|
|
Loading…
Reference in a new issue