diff --git a/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewModel.kt b/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewModel.kt index b93993bc53..b72a7db001 100644 --- a/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewModel.kt @@ -38,14 +38,6 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted fun create(initialState: CreateDirectRoomViewState): CreateDirectRoomViewModel } - init { - setState { - copy( - hsAdminHasDisabledE2E = !session.getHomeServerCapabilities().adminE2EByDefault - ) - } - } - companion object : MvRxViewModelFactory { @JvmStatic diff --git a/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewState.kt b/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewState.kt index ff2253cd66..8bb8c3ce58 100644 --- a/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewState.kt +++ b/vector/src/main/java/im/vector/riotx/features/createdirect/CreateDirectRoomViewState.kt @@ -21,6 +21,5 @@ import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.Uninitialized data class CreateDirectRoomViewState( - val createAndInviteState: Async = Uninitialized, - val hsAdminHasDisabledE2E: Boolean = false + val createAndInviteState: Async = Uninitialized ) : MvRxState diff --git a/vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewModel.kt b/vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewModel.kt new file mode 100644 index 0000000000..43c1eac172 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewModel.kt @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 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.riotx.features.homeserver + +import com.airbnb.mvrx.MvRxViewModelFactory +import com.airbnb.mvrx.ViewModelContext +import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities +import im.vector.riotx.core.di.HasScreenInjector +import im.vector.riotx.core.platform.EmptyAction +import im.vector.riotx.core.platform.EmptyViewEvents +import im.vector.riotx.core.platform.VectorViewModel + +class HomeServerCapabilitiesViewModel(initialState: HomeServerCapabilitiesViewState) + : VectorViewModel(initialState) { + + companion object : MvRxViewModelFactory { + + override fun initialState(viewModelContext: ViewModelContext): HomeServerCapabilitiesViewState? { + val session = (viewModelContext.activity as HasScreenInjector).injector().activeSessionHolder().getSafeActiveSession() + return HomeServerCapabilitiesViewState( + capabilities = session?.getHomeServerCapabilities() ?: HomeServerCapabilities() + ) + } + } + + override fun handle(action: EmptyAction) {} +} diff --git a/vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewState.kt b/vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewState.kt new file mode 100644 index 0000000000..2b55569b10 --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewState.kt @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 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.riotx.features.homeserver + +import com.airbnb.mvrx.MvRxState +import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities + +data class HomeServerCapabilitiesViewState( + val capabilities: HomeServerCapabilities = HomeServerCapabilities() +) : MvRxState diff --git a/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt b/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt index 603b6e2b29..e4f08758b2 100644 --- a/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/userdirectory/KnownUsersFragment.kt @@ -25,6 +25,7 @@ import androidx.core.view.forEach import androidx.core.view.isVisible import com.airbnb.mvrx.activityViewModel import com.airbnb.mvrx.args +import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import com.google.android.material.chip.Chip import com.jakewharton.rxbinding3.widget.textChanges @@ -36,8 +37,7 @@ import im.vector.riotx.core.extensions.hideKeyboard import im.vector.riotx.core.extensions.setupAsSearch import im.vector.riotx.core.platform.VectorBaseFragment import im.vector.riotx.core.utils.DimensionConverter -import im.vector.riotx.features.createdirect.CreateDirectRoomViewModel -import im.vector.riotx.features.createdirect.CreateDirectRoomViewState +import im.vector.riotx.features.homeserver.HomeServerCapabilitiesViewModel import kotlinx.android.synthetic.main.fragment_known_users.* import javax.inject.Inject @@ -54,7 +54,7 @@ class KnownUsersFragment @Inject constructor( override fun getMenuRes() = args.menuResId private val viewModel: UserDirectoryViewModel by activityViewModel() - private val createDMViewModel: CreateDirectRoomViewModel by activityViewModel() + private val homeServerCapabilitiesViewModel: HomeServerCapabilitiesViewModel by fragmentViewModel() private lateinit var sharedActionViewModel: UserDirectorySharedActionViewModel @@ -70,8 +70,8 @@ class KnownUsersFragment @Inject constructor( setupAddFromPhoneBookView() setupCloseView() - createDMViewModel.selectSubscribe(this, CreateDirectRoomViewState::hsAdminHasDisabledE2E) { - knownUsersE2EbyDefaultDisabled.isVisible = it + homeServerCapabilitiesViewModel.subscribe { + knownUsersE2EbyDefaultDisabled.isVisible = !it.capabilities.adminE2EByDefault } viewModel.selectSubscribe(this, UserDirectoryViewState::pendingInvitees) {