diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/IsCurrentSessionUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/IsCurrentSessionUseCase.kt deleted file mode 100644 index 885908120a..0000000000 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/IsCurrentSessionUseCase.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.app.features.settings.devices.v2 - -import im.vector.app.core.di.ActiveSessionHolder -import javax.inject.Inject - -class IsCurrentSessionUseCase @Inject constructor( - private val activeSessionHolder: ActiveSessionHolder, -) { - - fun execute(deviceId: String): Boolean { - val currentDeviceId = activeSessionHolder.getSafeActiveSession()?.sessionParams?.deviceId.orEmpty() - return deviceId.isNotEmpty() && deviceId == currentDeviceId - } -} diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt index eed7c1fead..3bd128ae42 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewFragment.kt @@ -136,17 +136,20 @@ class SessionOverviewFragment : } override fun invalidate() = withState(viewModel) { state -> - updateToolbar(state.isCurrentSession) + updateToolbar(state) updateEntryDetails(state.deviceId) updateSessionInfo(state) updateLoading(state.isLoading) } - private fun updateToolbar(isCurrentSession: Boolean) { - val titleResId = if (isCurrentSession) R.string.device_manager_current_session_title else R.string.device_manager_session_title - (activity as? AppCompatActivity) - ?.supportActionBar - ?.setTitle(titleResId) + private fun updateToolbar(viewState: SessionOverviewViewState) { + if (viewState.deviceInfo is Success) { + val titleResId = + if (viewState.deviceInfo.invoke().isCurrentDevice) R.string.device_manager_current_session_title else R.string.device_manager_session_title + (activity as? AppCompatActivity) + ?.supportActionBar + ?.setTitle(titleResId) + } } private fun updateEntryDetails(deviceId: String) { @@ -158,10 +161,11 @@ class SessionOverviewFragment : private fun updateSessionInfo(viewState: SessionOverviewViewState) { if (viewState.deviceInfo is Success) { views.sessionOverviewInfo.isVisible = true - val isCurrentSession = viewState.isCurrentSession + val deviceInfo = viewState.deviceInfo.invoke() + val isCurrentSession = deviceInfo.isCurrentDevice val infoViewState = SessionInfoViewState( isCurrentSession = isCurrentSession, - deviceFullInfo = viewState.deviceInfo.invoke(), + deviceFullInfo = deviceInfo, isVerifyButtonVisible = isCurrentSession || viewState.isCurrentSessionTrusted, isDetailsButtonVisible = false, isLearnMoreLinkVisible = true, diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt index 1eacb61bbc..aaf5c9d2a7 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewModel.kt @@ -27,7 +27,6 @@ import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.resources.StringProvider import im.vector.app.features.auth.PendingAuthHandler -import im.vector.app.features.settings.devices.v2.IsCurrentSessionUseCase import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase @@ -42,6 +41,7 @@ import kotlinx.coroutines.launch import org.matrix.android.sdk.api.auth.UIABaseAuth import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse +import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel import org.matrix.android.sdk.api.session.uia.DefaultBaseAuth @@ -51,7 +51,6 @@ import kotlin.coroutines.Continuation class SessionOverviewViewModel @AssistedInject constructor( @Assisted val initialState: SessionOverviewViewState, - private val isCurrentSessionUseCase: IsCurrentSessionUseCase, private val stringProvider: StringProvider, private val getDeviceFullInfoUseCase: GetDeviceFullInfoUseCase, private val checkIfCurrentSessionCanBeVerifiedUseCase: CheckIfCurrentSessionCanBeVerifiedUseCase, @@ -72,17 +71,10 @@ class SessionOverviewViewModel @AssistedInject constructor( } init { - setState { - copy(isCurrentSession = isCurrentSession(deviceId)) - } observeSessionInfo(initialState.deviceId) observeCurrentSessionInfo() } - private fun isCurrentSession(deviceId: String): Boolean { - return isCurrentSessionUseCase.execute(deviceId) - } - private fun observeSessionInfo(deviceId: String) { getDeviceFullInfoUseCase.execute(deviceId) .onEach { setState { copy(deviceInfo = Success(it)) } } @@ -114,7 +106,7 @@ class SessionOverviewViewModel @AssistedInject constructor( } private fun handleVerifySessionAction() = withState { viewState -> - if (viewState.isCurrentSession) { + if (viewState.deviceInfo.invoke()?.isCurrentDevice.orFalse()) { handleVerifyCurrentSession() } else { handleVerifyOtherSession(viewState.deviceId) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt index 8a0b41c55d..07423888b5 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewState.kt @@ -23,7 +23,6 @@ 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 = Uninitialized, val isLoading: Boolean = false, diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/IsCurrentSessionUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/IsCurrentSessionUseCaseTest.kt deleted file mode 100644 index 09a94ac08b..0000000000 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/IsCurrentSessionUseCaseTest.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2022 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.app.features.settings.devices.v2 - -import im.vector.app.test.fakes.FakeActiveSessionHolder -import io.mockk.verify -import org.amshove.kluent.shouldBe -import org.junit.Test -import org.matrix.android.sdk.api.auth.data.SessionParams - -private const val A_SESSION_ID_1 = "session-id-1" -private const val A_SESSION_ID_2 = "session-id-2" - -class IsCurrentSessionUseCaseTest { - - private val fakeActiveSessionHolder = FakeActiveSessionHolder() - - private val isCurrentSessionUseCase = IsCurrentSessionUseCase( - activeSessionHolder = fakeActiveSessionHolder.instance, - ) - - @Test - fun `given the session id of the current session when checking if id is current session then result is true`() { - // Given - val sessionParams = givenIdForCurrentSession(A_SESSION_ID_1) - - // When - val result = isCurrentSessionUseCase.execute(A_SESSION_ID_1) - - // Then - result shouldBe true - verify { sessionParams.deviceId } - } - - @Test - fun `given a session id different from the current session id when checking if id is current session then result is false`() { - // Given - val sessionParams = givenIdForCurrentSession(A_SESSION_ID_1) - - // When - val result = isCurrentSessionUseCase.execute(A_SESSION_ID_2) - - // Then - result shouldBe false - verify { sessionParams.deviceId } - } - - @Test - fun `given no current active session when checking if id is current session then result is false`() { - // Given - fakeActiveSessionHolder.givenGetSafeActiveSessionReturns(null) - - // When - val result = isCurrentSessionUseCase.execute(A_SESSION_ID_1) - - // Then - result shouldBe false - } - - private fun givenIdForCurrentSession(sessionId: String): SessionParams { - return fakeActiveSessionHolder.fakeSession.givenSessionId(sessionId) - } -}