mirror of
https://github.com/bitwarden/android.git
synced 2026-08-01 18:53:39 -05:00
Update UserStateJson with avatarColor and securityStamp from sync (#265)
This commit is contained in:
committed by
Álison Fernandes
parent
58eb4d4107
commit
feba8595b3
+33
@@ -0,0 +1,33 @@
|
||||
package com.x8bit.bitwarden.data.auth.repository.util
|
||||
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.SyncResponseJson
|
||||
|
||||
/**
|
||||
* Updates the given [UserStateJson] with the data from the [syncResponse] to return a new
|
||||
* [UserStateJson]. The original will be returned if the sync response does not match any accounts
|
||||
* in the [UserStateJson].
|
||||
*/
|
||||
@Suppress("ReturnCount")
|
||||
fun UserStateJson.toUpdatedUserStateJson(
|
||||
syncResponse: SyncResponseJson,
|
||||
): UserStateJson {
|
||||
val userId = syncResponse.profile?.id ?: return this
|
||||
val account = this.accounts[userId] ?: return this
|
||||
val profile = account.profile
|
||||
// TODO: Update additional missing UserStateJson properties (BIT-916)
|
||||
val updatedProfile = profile
|
||||
.copy(
|
||||
avatarColorHex = syncResponse.profile.avatarColor,
|
||||
stamp = syncResponse.profile.securityStamp,
|
||||
)
|
||||
val updatedAccount = account.copy(profile = updatedProfile)
|
||||
return this
|
||||
.copy(
|
||||
accounts = accounts
|
||||
.toMutableMap()
|
||||
.apply {
|
||||
replace(userId, updatedAccount)
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.bitwarden.core.FolderView
|
||||
import com.bitwarden.core.InitCryptoRequest
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.toSdkParams
|
||||
import com.x8bit.bitwarden.data.auth.repository.util.toUpdatedUserStateJson
|
||||
import com.x8bit.bitwarden.data.platform.datasource.network.util.isNoConnectionError
|
||||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
@@ -85,6 +86,13 @@ class VaultRepositoryImpl constructor(
|
||||
.sync()
|
||||
.fold(
|
||||
onSuccess = { syncResponse ->
|
||||
// Update user information with additional information from sync response
|
||||
authDiskSource.userState = authDiskSource
|
||||
.userState
|
||||
?.toUpdatedUserStateJson(
|
||||
syncResponse = syncResponse,
|
||||
)
|
||||
|
||||
storeUserKeyAndPrivateKey(
|
||||
userKey = syncResponse.profile?.key,
|
||||
privateKey = syncResponse.profile?.privateKey,
|
||||
|
||||
Reference in New Issue
Block a user