This commit is contained in:
valere 2023-03-14 12:07:39 +01:00
parent 5f069264d0
commit 065ee1d2f5
3 changed files with 39 additions and 27 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023 New Vector Ltd * Copyright (c) 2023 The Matrix.org Foundation C.I.C.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View file

@ -71,7 +71,7 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(
userId = userId, userId = userId,
allowDeviceAction = args.allowDeviceAction, allowDeviceAction = args.allowDeviceAction,
userItem = session.getUserOrDefault(userId).toMatrixItem(), userItem = session.getUserOrDefault(userId).toMatrixItem(),
myDeviceId = session.sessionParams.deviceId ?: "", myDeviceId = session.sessionParams.deviceId,
) )
} }
} }

View file

@ -69,9 +69,11 @@ import im.vector.app.features.pin.PinMode
import im.vector.app.features.raw.wellknown.getElementWellknown import im.vector.app.features.raw.wellknown.getElementWellknown
import im.vector.app.features.raw.wellknown.isE2EByDefault import im.vector.app.features.raw.wellknown.isE2EByDefault
import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.themes.ThemeUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.gujun.android.span.span import me.gujun.android.span.span
import org.matrix.android.sdk.api.extensions.getFingerprintHumanReadable import org.matrix.android.sdk.api.extensions.getFingerprintHumanReadable
import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.raw.RawService
@ -175,9 +177,6 @@ class VectorSettingsSecurityPrivacyFragment :
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
// My device name may have been updated
refreshMyDevice()
refreshXSigningStatus()
session.liveSecretSynchronisationInfo() session.liveSecretSynchronisationInfo()
.onEach { .onEach {
refresh4SSection(it) refresh4SSection(it)
@ -186,10 +185,10 @@ class VectorSettingsSecurityPrivacyFragment :
.launchIn(viewLifecycleOwner.lifecycleScope) .launchIn(viewLifecycleOwner.lifecycleScope)
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT)?.isVisible = findPreference<VectorPreference>(VectorPreferences.SETTINGS_CRYPTOGRAPHY_HS_ADMIN_DISABLED_E2E_DEFAULT)?.isVisible =
rawService rawService
.getElementWellknown(session.sessionParams) .getElementWellknown(session.sessionParams)
?.isE2EByDefault() == false ?.isE2EByDefault() == false
} }
} }
@ -288,7 +287,18 @@ class VectorSettingsSecurityPrivacyFragment :
true true
} }
refreshXSigningStatus() lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
refreshXSigningStatus()
}
}
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
// My device name may have been updated
refreshMyDevice()
}
}
secureBackupPreference.icon = activity?.let { secureBackupPreference.icon = activity?.let {
ThemeUtils.tintDrawable( ThemeUtils.tintDrawable(
@ -349,13 +359,13 @@ class VectorSettingsSecurityPrivacyFragment :
} }
// Todo this should be refactored and use same state as 4S section // Todo this should be refactored and use same state as 4S section
private fun refreshXSigningStatus() { private suspend fun refreshXSigningStatus() {
lifecycleScope.launchWhenResumed { val crossSigningKeys = session.cryptoService().crossSigningService().getMyCrossSigningKeys()
val crossSigningKeys = session.cryptoService().crossSigningService().getMyCrossSigningKeys() val xSigningIsEnableInAccount = crossSigningKeys != null
val xSigningIsEnableInAccount = crossSigningKeys != null val xSigningKeysAreTrusted = session.cryptoService().crossSigningService().checkUserTrust(session.myUserId).isVerified()
val xSigningKeysAreTrusted = session.cryptoService().crossSigningService().checkUserTrust(session.myUserId).isVerified() val xSigningKeyCanSign = session.cryptoService().crossSigningService().canCrossSign()
val xSigningKeyCanSign = session.cryptoService().crossSigningService().canCrossSign()
withContext(Dispatchers.Main) {
when { when {
xSigningKeyCanSign -> { xSigningKeyCanSign -> {
mCrossSigningStatePreference.setIcon(R.drawable.ic_shield_trusted) mCrossSigningStatePreference.setIcon(R.drawable.ic_shield_trusted)
@ -623,19 +633,21 @@ class VectorSettingsSecurityPrivacyFragment :
// devices list // devices list
// ============================================================================================================== // ==============================================================================================================
private fun refreshMyDevice() { private suspend fun refreshMyDevice() {
viewLifecycleOwner.lifecycleScope.launchWhenResumed { session.cryptoService().getUserDevices(session.myUserId).map {
session.cryptoService().getUserDevices(session.myUserId).map { DeviceInfo(
DeviceInfo( userId = session.myUserId,
userId = session.myUserId, deviceId = it.deviceId,
deviceId = it.deviceId, displayName = it.displayName()
displayName = it.displayName() )
) }.let {
}.let { withContext(Dispatchers.Main) {
refreshCryptographyPreference(it) refreshCryptographyPreference(it)
} }
// TODO Move to a ViewModel... }
val devicesList = session.cryptoService().fetchDevicesList() // TODO Move to a ViewModel...
val devicesList = session.cryptoService().fetchDevicesList()
withContext(Dispatchers.Main) {
refreshCryptographyPreference(devicesList) refreshCryptographyPreference(devicesList)
} }
} }