Verification of another session
This commit is contained in:
parent
c16e1ca291
commit
a6cb25d0c3
|
@ -62,6 +62,7 @@ class SessionInfoView @JvmOverloads constructor(
|
|||
sessionInfoViewState.deviceFullInfo.roomEncryptionTrustLevel,
|
||||
sessionInfoViewState.isCurrentSession,
|
||||
sessionInfoViewState.isLearnMoreLinkVisible,
|
||||
sessionInfoViewState.isVerifyButtonVisible,
|
||||
)
|
||||
renderDeviceLastSeenDetails(
|
||||
sessionInfoViewState.deviceFullInfo.isInactive,
|
||||
|
@ -78,12 +79,13 @@ class SessionInfoView @JvmOverloads constructor(
|
|||
encryptionTrustLevel: RoomEncryptionTrustLevel,
|
||||
isCurrentSession: Boolean,
|
||||
hasLearnMoreLink: Boolean,
|
||||
isVerifyButtonVisible: Boolean,
|
||||
) {
|
||||
views.sessionInfoVerificationStatusImageView.render(encryptionTrustLevel)
|
||||
if (encryptionTrustLevel == RoomEncryptionTrustLevel.Trusted) {
|
||||
renderCrossSigningVerified(isCurrentSession)
|
||||
} else {
|
||||
renderCrossSigningUnverified(isCurrentSession)
|
||||
renderCrossSigningUnverified(isCurrentSession, isVerifyButtonVisible)
|
||||
}
|
||||
if (hasLearnMoreLink) {
|
||||
appendLearnMoreToVerificationStatus()
|
||||
|
@ -120,7 +122,7 @@ class SessionInfoView @JvmOverloads constructor(
|
|||
views.sessionInfoVerifySessionButton.isVisible = false
|
||||
}
|
||||
|
||||
private fun renderCrossSigningUnverified(isCurrentSession: Boolean) {
|
||||
private fun renderCrossSigningUnverified(isCurrentSession: Boolean, isVerifyButtonVisible: Boolean) {
|
||||
views.sessionInfoVerificationStatusTextView.text = context.getString(R.string.device_manager_verification_status_unverified)
|
||||
views.sessionInfoVerificationStatusTextView.setTextColor(ThemeUtils.getColor(context, R.attr.colorError))
|
||||
val statusResId = if (isCurrentSession) {
|
||||
|
@ -129,7 +131,7 @@ class SessionInfoView @JvmOverloads constructor(
|
|||
R.string.device_manager_verification_status_detail_other_session_unverified
|
||||
}
|
||||
views.sessionInfoVerificationStatusDetailTextView.text = context.getString(statusResId)
|
||||
views.sessionInfoVerifySessionButton.isVisible = true
|
||||
views.sessionInfoVerifySessionButton.isVisible = isVerifyButtonVisible
|
||||
}
|
||||
|
||||
// TODO. We don't have this info yet. Update later accordingly.
|
||||
|
|
|
@ -21,6 +21,7 @@ import im.vector.app.features.settings.devices.v2.DeviceFullInfo
|
|||
data class SessionInfoViewState(
|
||||
val isCurrentSession: Boolean,
|
||||
val deviceFullInfo: DeviceFullInfo,
|
||||
val isVerifyButtonVisible: Boolean = true,
|
||||
val isDetailsButtonVisible: Boolean = true,
|
||||
val isLearnMoreLinkVisible: Boolean = false,
|
||||
val isLastSeenDetailsVisible: Boolean = false,
|
||||
|
|
|
@ -82,9 +82,12 @@ class SessionOverviewFragment :
|
|||
private fun observeViewEvents() {
|
||||
viewModel.observeViewEvents {
|
||||
when (it) {
|
||||
is SessionOverviewViewEvent.SelfVerification -> {
|
||||
is SessionOverviewViewEvent.ShowVerifyCurrentSession -> {
|
||||
navigator.requestSelfSessionVerification(requireActivity())
|
||||
}
|
||||
is SessionOverviewViewEvent.ShowVerifyOtherSession -> {
|
||||
navigator.requestSessionVerification(requireActivity(), it.deviceId)
|
||||
}
|
||||
is SessionOverviewViewEvent.PromptResetSecrets -> {
|
||||
navigator.open4SSetup(requireActivity(), SetupMode.PASSPHRASE_AND_NEEDED_SECRETS_RESET)
|
||||
}
|
||||
|
@ -105,7 +108,7 @@ class SessionOverviewFragment :
|
|||
updateToolbar(state.isCurrentSession)
|
||||
updateEntryDetails(state.deviceId)
|
||||
if (state.deviceInfo is Success) {
|
||||
renderSessionInfo(state.isCurrentSession, state.deviceInfo.invoke())
|
||||
renderSessionInfo(state.isCurrentSession, state.deviceInfo.invoke(), state.isCurrentSessionTrusted)
|
||||
} else {
|
||||
hideSessionInfo()
|
||||
}
|
||||
|
@ -124,11 +127,16 @@ class SessionOverviewFragment :
|
|||
}
|
||||
}
|
||||
|
||||
private fun renderSessionInfo(isCurrentSession: Boolean, deviceFullInfo: DeviceFullInfo) {
|
||||
private fun renderSessionInfo(
|
||||
isCurrentSession: Boolean,
|
||||
deviceFullInfo: DeviceFullInfo,
|
||||
isCurrentSessionTrusted: Boolean,
|
||||
) {
|
||||
views.sessionOverviewInfo.isVisible = true
|
||||
val viewState = SessionInfoViewState(
|
||||
isCurrentSession = isCurrentSession,
|
||||
deviceFullInfo = deviceFullInfo,
|
||||
isVerifyButtonVisible = isCurrentSession || isCurrentSessionTrusted,
|
||||
isDetailsButtonVisible = false,
|
||||
isLearnMoreLinkVisible = true,
|
||||
isLastSeenDetailsVisible = true,
|
||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.app.features.settings.devices.v2.overview
|
|||
import im.vector.app.core.platform.VectorViewEvents
|
||||
|
||||
sealed class SessionOverviewViewEvent : VectorViewEvents {
|
||||
object SelfVerification : SessionOverviewViewEvent()
|
||||
object ShowVerifyCurrentSession : SessionOverviewViewEvent()
|
||||
data class ShowVerifyOtherSession(val deviceId: String) : SessionOverviewViewEvent()
|
||||
object PromptResetSecrets : SessionOverviewViewEvent()
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
init {
|
||||
// TODO check if current session is trusted
|
||||
setState {
|
||||
copy(isCurrentSession = isCurrentSession(deviceId))
|
||||
}
|
||||
|
@ -70,6 +71,8 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
|||
private fun handleVerifySessionAction() = withState { viewState ->
|
||||
if (isCurrentSession(viewState.deviceId)) {
|
||||
handleVerifyCurrentSession()
|
||||
} else {
|
||||
handleVerifyOtherSession(verifySession.deviceId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,10 +80,14 @@ class SessionOverviewViewModel @AssistedInject constructor(
|
|||
viewModelScope.launch {
|
||||
val currentSessionCanBeVerified = checkIfCurrentSessionCanBeVerifiedUseCase.execute()
|
||||
if (currentSessionCanBeVerified) {
|
||||
_viewEvents.post(SessionOverviewViewEvent.SelfVerification)
|
||||
_viewEvents.post(SessionOverviewViewEvent.ShowVerifyCurrentSession)
|
||||
} else {
|
||||
_viewEvents.post(SessionOverviewViewEvent.PromptResetSecrets)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleVerifyOtherSession(deviceId: String) {
|
||||
_viewEvents.post(SessionOverviewViewEvent.ShowVerifyOtherSession(deviceId))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import im.vector.app.features.settings.devices.v2.DeviceFullInfo
|
|||
data class SessionOverviewViewState(
|
||||
val deviceId: String,
|
||||
val isCurrentSession: Boolean = false,
|
||||
val isCurrentSessionTrusted: Boolean = false,
|
||||
val deviceInfo: Async<DeviceFullInfo> = Uninitialized,
|
||||
) : MavericksState {
|
||||
constructor(args: SessionOverviewArgs) : this(
|
||||
|
|
|
@ -95,7 +95,7 @@ class SessionOverviewViewModelTest {
|
|||
|
||||
// Then
|
||||
viewModelTest
|
||||
.assertEvent { it is SessionOverviewViewEvent.SelfVerification }
|
||||
.assertEvent { it is SessionOverviewViewEvent.ShowVerifyCurrentSession }
|
||||
.finish()
|
||||
coVerify {
|
||||
checkIfCurrentSessionCanBeVerifiedUseCase.execute()
|
||||
|
@ -124,4 +124,23 @@ class SessionOverviewViewModelTest {
|
|||
checkIfCurrentSessionCanBeVerifiedUseCase.execute()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `given another session when handling verify session action then verify session event is posted`() {
|
||||
// Given
|
||||
val deviceFullInfo = mockk<DeviceFullInfo>()
|
||||
every { getDeviceFullInfoUseCase.execute(A_SESSION_ID) } returns flowOf(deviceFullInfo)
|
||||
every { isCurrentSessionUseCase.execute(any()) } returns false
|
||||
val verifySessionAction = SessionOverviewAction.VerifySession(A_SESSION_ID)
|
||||
|
||||
// When
|
||||
val viewModel = createViewModel()
|
||||
val viewModelTest = viewModel.test()
|
||||
viewModel.handle(verifySessionAction)
|
||||
|
||||
// Then
|
||||
viewModelTest
|
||||
.assertEvent { it is SessionOverviewViewEvent.ShowVerifyOtherSession }
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue