From af4f8d001e2b021d6669db00937ab77f35eca46f Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 30 May 2022 17:04:10 +0200 Subject: [PATCH 1/5] Fixes upgraded room duplication --- .../home/room/detail/upgrade/UpgradeRoomViewModelTask.kt | 2 -- .../app/features/spaces/explore/SpaceDirectoryController.kt | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt index 2f91b9a35a..1f0404d659 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/upgrade/UpgradeRoomViewModelTask.kt @@ -84,8 +84,6 @@ class UpgradeRoomViewModelTask @Inject constructor( // autoJoin = currentInfo.autoJoin ?: false, suggested = currentInfo.suggested ) - - parentSpace.removeChildren(params.roomId) } } } catch (failure: Throwable) { diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt index 3f3b66cbcc..0905d891b6 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt @@ -44,6 +44,7 @@ import org.matrix.android.sdk.api.failure.MatrixError.Companion.M_UNRECOGNIZED import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo +import org.matrix.android.sdk.api.session.room.model.VersioningState import org.matrix.android.sdk.api.util.toMatrixItem import javax.inject.Inject @@ -110,6 +111,7 @@ class SpaceDirectoryController @Inject constructor( ?.filter { it.parentRoomId == (data.hierarchyStack.lastOrNull() ?: data.spaceId) } + ?.filterNot { it.isUpgradedRoom(data) } ?: emptyList() if (flattenChildInfo.isEmpty()) { @@ -209,4 +211,7 @@ class SpaceDirectoryController @Inject constructor( } } } + + private fun SpaceChildInfo.isUpgradedRoom(data: SpaceDirectoryState) = + data.knownRoomSummaries.any { it.roomId == childRoomId && it.versioningState == VersioningState.UPGRADED_ROOM_JOINED } } From 8d930446cae54020acfb7cb817ad1729d24b9022 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 31 May 2022 12:53:02 +0200 Subject: [PATCH 2/5] Fixes room filter not including UPGRADE_ROOM_NOT_JOINED --- .../app/features/spaces/explore/SpaceDirectoryController.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt index 0905d891b6..25e69959c7 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt @@ -213,5 +213,5 @@ class SpaceDirectoryController @Inject constructor( } private fun SpaceChildInfo.isUpgradedRoom(data: SpaceDirectoryState) = - data.knownRoomSummaries.any { it.roomId == childRoomId && it.versioningState == VersioningState.UPGRADED_ROOM_JOINED } + data.knownRoomSummaries.any { it.roomId == childRoomId && it.versioningState != VersioningState.NONE } } From 01b7395c04a6d234bd37d725c37377eb576166fe Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Tue, 31 May 2022 12:53:28 +0200 Subject: [PATCH 3/5] Adds changelog file --- changelog.d/6200.bugfix | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelog.d/6200.bugfix diff --git a/changelog.d/6200.bugfix b/changelog.d/6200.bugfix new file mode 100644 index 0000000000..41b0088a03 --- /dev/null +++ b/changelog.d/6200.bugfix @@ -0,0 +1,2 @@ +Fixes room not being in space after upgrade + From f6b0e8d13c388482eb50774c8392f09adcd5b02e Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 3 Jun 2022 12:02:50 +0200 Subject: [PATCH 4/5] Adds isUpgraded method to VersioningState --- changelog.d/6200.bugfix | 1 - .../android/sdk/api/session/room/model/VersioningState.kt | 4 +++- .../app/features/spaces/explore/SpaceDirectoryController.kt | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/changelog.d/6200.bugfix b/changelog.d/6200.bugfix index 41b0088a03..ee204b4567 100644 --- a/changelog.d/6200.bugfix +++ b/changelog.d/6200.bugfix @@ -1,2 +1 @@ Fixes room not being in space after upgrade - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/VersioningState.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/VersioningState.kt index b4e7b10d44..6d15d1a007 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/VersioningState.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/model/VersioningState.kt @@ -19,5 +19,7 @@ package org.matrix.android.sdk.api.session.room.model enum class VersioningState { NONE, UPGRADED_ROOM_NOT_JOINED, - UPGRADED_ROOM_JOINED + UPGRADED_ROOM_JOINED; + + fun isUpgraded() = this != NONE } diff --git a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt index 25e69959c7..5da5ae8510 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/explore/SpaceDirectoryController.kt @@ -44,7 +44,6 @@ import org.matrix.android.sdk.api.failure.MatrixError.Companion.M_UNRECOGNIZED import org.matrix.android.sdk.api.session.room.members.ChangeMembershipState import org.matrix.android.sdk.api.session.room.model.RoomType import org.matrix.android.sdk.api.session.room.model.SpaceChildInfo -import org.matrix.android.sdk.api.session.room.model.VersioningState import org.matrix.android.sdk.api.util.toMatrixItem import javax.inject.Inject @@ -213,5 +212,5 @@ class SpaceDirectoryController @Inject constructor( } private fun SpaceChildInfo.isUpgradedRoom(data: SpaceDirectoryState) = - data.knownRoomSummaries.any { it.roomId == childRoomId && it.versioningState != VersioningState.NONE } + data.knownRoomSummaries.any { it.roomId == childRoomId && it.versioningState.isUpgraded() } } From 654eede21bf91738f825ff6d2485fb9cf263784e Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Mon, 4 Jul 2022 10:06:00 +0100 Subject: [PATCH 5/5] Adds VersioningStateTest --- .../session/room/model/VersioningStateTest.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 vector/src/test/java/org/matrix/android/sdk/api/session/room/model/VersioningStateTest.kt diff --git a/vector/src/test/java/org/matrix/android/sdk/api/session/room/model/VersioningStateTest.kt b/vector/src/test/java/org/matrix/android/sdk/api/session/room/model/VersioningStateTest.kt new file mode 100644 index 0000000000..473918d179 --- /dev/null +++ b/vector/src/test/java/org/matrix/android/sdk/api/session/room/model/VersioningStateTest.kt @@ -0,0 +1,50 @@ +/* + * 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 org.matrix.android.sdk.api.session.room.model + +import org.amshove.kluent.shouldBe +import org.junit.Test + +internal class VersioningStateTest { + + @Test + fun `when VersioningState is NONE, then isUpgraded returns false`() { + val versioningState = VersioningState.NONE + + val isUpgraded = versioningState.isUpgraded() + + isUpgraded shouldBe false + } + + @Test + fun `when VersioningState is UPGRADED_ROOM_NOT_JOINED, then isUpgraded returns true`() { + val versioningState = VersioningState.UPGRADED_ROOM_NOT_JOINED + + val isUpgraded = versioningState.isUpgraded() + + isUpgraded shouldBe true + } + + @Test + fun `when VersioningState is UPGRADED_ROOM_JOINED, then isUpgraded returns true`() { + val versioningState = VersioningState.UPGRADED_ROOM_JOINED + + val isUpgraded = versioningState.isUpgraded() + + isUpgraded shouldBe true + } +}