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(
|
}
|
||||||
accessToken = accessToken,
|
val newAccountEntity = if (existingAccountIndex != -1) {
|
||||||
clientId = clientId,
|
accounts[existingAccountIndex].copy(
|
||||||
clientSecret = clientSecret,
|
accessToken = accessToken,
|
||||||
oauthScopes = oauthScopes
|
clientId = clientId,
|
||||||
) ?: run {
|
clientSecret = clientSecret,
|
||||||
|
oauthScopes = oauthScopes,
|
||||||
|
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