From 281092351961b564204b3a3a99ae9343060c62cf Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 3 Aug 2020 12:00:08 +0200 Subject: [PATCH 1/2] FIx / Crash when opening Invite User screen --- .../createdirect/CreateDirectRoomViewModel.kt | 8 ---- .../createdirect/CreateDirectRoomViewState.kt | 3 +- .../HomeServerCapabilitiesViewModel.kt | 41 +++++++++++++++++++ .../HomeServerCapabilitiesViewState.kt | 24 +++++++++++ .../userdirectory/KnownUsersFragment.kt | 10 ++--- 5 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewModel.kt create mode 100644 vector/src/main/java/im/vector/riotx/features/homeserver/HomeServerCapabilitiesViewState.kt 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) { From db6045778e6f8ed6127792592f06f09e1ed3c18c Mon Sep 17 00:00:00 2001 From: Valere Date: Mon, 3 Aug 2020 12:11:50 +0200 Subject: [PATCH 2/2] Update change log --- CHANGES.md | 6 ++++++ vector/build.gradle | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 76f2067632..f4f631decd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +Changes in Element 1.0.4 (2020-08-03) +=================================================== + +Bugfix 🐛: + - Fix Crash when opening invite to room user screen + Changes in Element 1.0.3 (2020-07-31) =================================================== diff --git a/vector/build.gradle b/vector/build.gradle index 68ba94c574..dd78e7e87c 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -17,7 +17,7 @@ androidExtensions { // Note: 2 digits max for each value ext.versionMajor = 1 ext.versionMinor = 0 -ext.versionPatch = 3 +ext.versionPatch = 4 static def getGitTimestamp() { def cmd = 'git show -s --format=%ct'