Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes room not being in space after upgrade #6200

Merged
merged 7 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6200.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixes room not being in space after upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ enum class VersioningState {
/**
* The room has been upgraded, and the new room has been joined.
*/
UPGRADED_ROOM_JOINED,
UPGRADED_ROOM_JOINED;

fun isUpgraded() = this != NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class UpgradeRoomViewModelTask @Inject constructor(
// autoJoin = currentInfo.autoJoin ?: false,
suggested = currentInfo.suggested
)

parentSpace.removeChildren(params.roomId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know why this was originally added?

I would assume the room id is changed after upgrade and we're cleaning the legacy room 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would guess this was the first attempt at removing the duplication, and though it worked for that purpose, you would no longer see the pre-upgraded room in the space but you'd see it in Home

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be valuable for other cases, some counters could use spaces children number or some check (if space is empty or not), so absence of removal could cause some side effects.

@BillCarsonFr you added this line, maybe you could verify if removing it could cause any problems?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes in the original code when migrating a room, we were removing the old room from the space and then add the new one. The annoying side effect is that people that haven't yet migrated will then see the room as not being in the space anymore (it will probably jump back to home).
Now we want to keep both old & new as part of the migration process, and to have the UI smarter and detect duplicate rooms and only show the new one.
Like that new comers will only see the new room, and existing users will see the old one in the space with the CTA to join the migrated one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about some places, where we could get rooms without applying this filter, like getting space''s room count or something like that. 🤔

}
}
} catch (failure: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class SpaceDirectoryController @Inject constructor(
?.filter {
it.parentRoomId == (data.hierarchyStack.lastOrNull() ?: data.spaceId)
}
?.filterNot { it.isUpgradedRoom(data) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will filter out rooms with UPGRADED_ROOM_NOT_JOINED VersioningState, is it intentional? If room was upgraded, but user haven't joined upgraded room yet, what user will see? We change state from NONE to UPGRADED_ROOM_NOT_JOINED on TombStone event and so it could happen while user is on a background and doesn't interact with the app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional yeah, this only applies to the old version of upgraded rooms, so them not being active there's no use having them shown in Explore Rooms

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, we should filter out if the room is an old version of a room that is also in the space (we want to avoid apparant duplicates in the list).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, when room is upgraded, everyone in the room gets tombstone event and state is changed to UPGRADED_ROOM_NOT_JOINED until they will join new room. isUpgradedRoom will return true and so such users won't see room in a list. Shouldn't we hide it only after users will join new Room?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check what web is doing and do the same. What we don't want is for the user to see a duplicated room (for the user it's pretty much the same, after all room upgrade is just a technical thing).
I guess that in the case you mentionned, I would want as a user to see only one room and probably that I joined?
So that mean we show the old room? or the new one but with an indicator that I joined the old version?
anyhow we should align with web and amend later with better behavior if needed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a de-duplication mechanism for upgraded room in the room list. We need similar thing in the explore screen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see web doing this same as this PR. The pre-upgraded room is kept in the space

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you don't keep it, you filter out any room with UPGRADED_ROOM_NOT_JOINED, so it's different from web, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean keep in the sense that it's not deleted from the space in the db, it's just filtered out in the UI

?: emptyList()

if (flattenChildInfo.isEmpty()) {
Expand Down Expand Up @@ -209,4 +210,7 @@ class SpaceDirectoryController @Inject constructor(
}
}
}

private fun SpaceChildInfo.isUpgradedRoom(data: SpaceDirectoryState) =
data.knownRoomSummaries.any { it.roomId == childRoomId && it.versioningState.isUpgraded() }
}
Original file line number Diff line number Diff line change
@@ -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
}
}