Skip to content

Commit 6d924c3

Browse files
jmartinespElementBot
and
ElementBot
authored
Don't display 'join room' screen while leaving a room. (#2770)
* Don't display 'join room' screen while leaving a room. Centralise the navigation based on membership in a single point in `RoomFlowNode`. * Update screenshots --------- Co-authored-by: ElementBot <[email protected]>
1 parent 06a519e commit 6d924c3

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

appnav/src/main/kotlin/io/element/android/appnav/room/RoomFlowNode.kt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,17 @@ import io.element.android.libraries.architecture.BaseFlowNode
4747
import io.element.android.libraries.architecture.NodeInputs
4848
import io.element.android.libraries.architecture.createNode
4949
import io.element.android.libraries.architecture.inputs
50+
import io.element.android.libraries.core.bool.orFalse
5051
import io.element.android.libraries.di.SessionScope
5152
import io.element.android.libraries.matrix.api.MatrixClient
5253
import io.element.android.libraries.matrix.api.core.RoomAlias
5354
import io.element.android.libraries.matrix.api.core.RoomId
5455
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
5556
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
56-
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
57-
import kotlinx.coroutines.flow.filter
57+
import kotlinx.coroutines.flow.combine
58+
import kotlinx.coroutines.flow.distinctUntilChanged
5859
import kotlinx.coroutines.flow.launchIn
59-
import kotlinx.coroutines.flow.onEach
60+
import kotlinx.coroutines.flow.map
6061
import kotlinx.coroutines.launch
6162
import kotlinx.parcelize.Parcelize
6263
import timber.log.Timber
@@ -68,7 +69,6 @@ class RoomFlowNode @AssistedInject constructor(
6869
@Assisted val buildContext: BuildContext,
6970
@Assisted plugins: List<Plugin>,
7071
private val client: MatrixClient,
71-
private val roomMembershipObserver: RoomMembershipObserver,
7272
private val joinRoomEntryPoint: JoinRoomEntryPoint,
7373
private val roomAliasResolverEntryPoint: RoomAliasResolverEntryPoint,
7474
private val networkMonitor: NetworkMonitor,
@@ -121,14 +121,17 @@ class RoomFlowNode @AssistedInject constructor(
121121
}
122122

123123
private fun subscribeToRoomInfoFlow(roomId: RoomId) {
124-
client.getRoomInfoFlow(
124+
val roomInfoFlow = client.getRoomInfoFlow(
125125
roomId = roomId
126-
)
127-
.onEach { roomInfo ->
128-
Timber.d("Room membership: ${roomInfo.map { it.currentUserMembership }}")
129-
val info = roomInfo.getOrNull()
130-
if (info?.currentUserMembership == CurrentUserMembership.JOINED) {
131-
if (info.isSpace) {
126+
).map { it.getOrNull() }
127+
128+
val isSpaceFlow = roomInfoFlow.map { it?.isSpace.orFalse() }.distinctUntilChanged()
129+
val currentMembershipFlow = roomInfoFlow.map { it?.currentUserMembership }.distinctUntilChanged()
130+
combine(currentMembershipFlow, isSpaceFlow) { membership, isSpace ->
131+
Timber.d("Room membership: $membership")
132+
when (membership) {
133+
CurrentUserMembership.JOINED -> {
134+
if (isSpace) {
132135
// It should not happen, but probably due to an issue in the sliding sync,
133136
// we can have a space here in case the space has just been joined.
134137
// So navigate to the JoinRoom target for now, which will
@@ -137,19 +140,17 @@ class RoomFlowNode @AssistedInject constructor(
137140
} else {
138141
backstack.newRoot(NavTarget.JoinedRoom(roomId))
139142
}
140-
} else {
143+
}
144+
CurrentUserMembership.LEFT -> {
145+
// Left the room, navigate out of this flow
146+
navigateUp()
147+
}
148+
else -> {
149+
// Was invited or the room is not known, display the join room screen
141150
backstack.newRoot(NavTarget.JoinRoom(roomId))
142151
}
143152
}
144-
.launchIn(lifecycleScope)
145-
146-
// When leaving the room from this session only, navigate up.
147-
roomMembershipObserver.updates
148-
.filter { update -> update.roomId == roomId && !update.isUserInRoom }
149-
.onEach {
150-
navigateUp()
151-
}
152-
.launchIn(lifecycleScope)
153+
}.launchIn(lifecycleScope)
153154
}
154155

155156
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {

0 commit comments

Comments
 (0)