mirror of
https://github.com/accelforce/Yuito
synced 2024-12-22 21:28:08 +01:00
parent
e91c750cb0
commit
a8a97b6834
@ -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(
|
||||
accessToken = accessToken,
|
||||
clientId = clientId,
|
||||
clientSecret = clientSecret,
|
||||
oauthScopes = oauthScopes
|
||||
) ?: run {
|
||||
}
|
||||
val newAccountEntity = if (existingAccountIndex != -1) {
|
||||
accounts[existingAccountIndex].copy(
|
||||
accessToken = accessToken,
|
||||
clientId = clientId,
|
||||
clientSecret = clientSecret,
|
||||
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 New Issue
Block a user