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 <benoitm+elementbot@element.io>
This commit is contained in:
parent
3e9ae00090
commit
b8b29d896a
1 changed files with 22 additions and 21 deletions
|
|
@ -47,16 +47,17 @@ import io.element.android.libraries.architecture.BaseFlowNode
|
||||||
import io.element.android.libraries.architecture.NodeInputs
|
import io.element.android.libraries.architecture.NodeInputs
|
||||||
import io.element.android.libraries.architecture.createNode
|
import io.element.android.libraries.architecture.createNode
|
||||||
import io.element.android.libraries.architecture.inputs
|
import io.element.android.libraries.architecture.inputs
|
||||||
|
import io.element.android.libraries.core.bool.orFalse
|
||||||
import io.element.android.libraries.di.SessionScope
|
import io.element.android.libraries.di.SessionScope
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
import io.element.android.libraries.matrix.api.core.RoomAlias
|
import io.element.android.libraries.matrix.api.core.RoomAlias
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
|
import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
|
||||||
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
@ -68,7 +69,6 @@ class RoomFlowNode @AssistedInject constructor(
|
||||||
@Assisted val buildContext: BuildContext,
|
@Assisted val buildContext: BuildContext,
|
||||||
@Assisted plugins: List<Plugin>,
|
@Assisted plugins: List<Plugin>,
|
||||||
private val client: MatrixClient,
|
private val client: MatrixClient,
|
||||||
private val roomMembershipObserver: RoomMembershipObserver,
|
|
||||||
private val joinRoomEntryPoint: JoinRoomEntryPoint,
|
private val joinRoomEntryPoint: JoinRoomEntryPoint,
|
||||||
private val roomAliasResolverEntryPoint: RoomAliasResolverEntryPoint,
|
private val roomAliasResolverEntryPoint: RoomAliasResolverEntryPoint,
|
||||||
private val networkMonitor: NetworkMonitor,
|
private val networkMonitor: NetworkMonitor,
|
||||||
|
|
@ -121,14 +121,17 @@ class RoomFlowNode @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun subscribeToRoomInfoFlow(roomId: RoomId) {
|
private fun subscribeToRoomInfoFlow(roomId: RoomId) {
|
||||||
client.getRoomInfoFlow(
|
val roomInfoFlow = client.getRoomInfoFlow(
|
||||||
roomId = roomId
|
roomId = roomId
|
||||||
)
|
).map { it.getOrNull() }
|
||||||
.onEach { roomInfo ->
|
|
||||||
Timber.d("Room membership: ${roomInfo.map { it.currentUserMembership }}")
|
val isSpaceFlow = roomInfoFlow.map { it?.isSpace.orFalse() }.distinctUntilChanged()
|
||||||
val info = roomInfo.getOrNull()
|
val currentMembershipFlow = roomInfoFlow.map { it?.currentUserMembership }.distinctUntilChanged()
|
||||||
if (info?.currentUserMembership == CurrentUserMembership.JOINED) {
|
combine(currentMembershipFlow, isSpaceFlow) { membership, isSpace ->
|
||||||
if (info.isSpace) {
|
Timber.d("Room membership: $membership")
|
||||||
|
when (membership) {
|
||||||
|
CurrentUserMembership.JOINED -> {
|
||||||
|
if (isSpace) {
|
||||||
// It should not happen, but probably due to an issue in the sliding sync,
|
// It should not happen, but probably due to an issue in the sliding sync,
|
||||||
// we can have a space here in case the space has just been joined.
|
// we can have a space here in case the space has just been joined.
|
||||||
// So navigate to the JoinRoom target for now, which will
|
// So navigate to the JoinRoom target for now, which will
|
||||||
|
|
@ -137,19 +140,17 @@ class RoomFlowNode @AssistedInject constructor(
|
||||||
} else {
|
} else {
|
||||||
backstack.newRoot(NavTarget.JoinedRoom(roomId))
|
backstack.newRoot(NavTarget.JoinedRoom(roomId))
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
CurrentUserMembership.LEFT -> {
|
||||||
|
// Left the room, navigate out of this flow
|
||||||
|
navigateUp()
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
// Was invited or the room is not known, display the join room screen
|
||||||
backstack.newRoot(NavTarget.JoinRoom(roomId))
|
backstack.newRoot(NavTarget.JoinRoom(roomId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.launchIn(lifecycleScope)
|
}.launchIn(lifecycleScope)
|
||||||
|
|
||||||
// When leaving the room from this session only, navigate up.
|
|
||||||
roomMembershipObserver.updates
|
|
||||||
.filter { update -> update.roomId == roomId && !update.isUserInRoom }
|
|
||||||
.onEach {
|
|
||||||
navigateUp()
|
|
||||||
}
|
|
||||||
.launchIn(lifecycleScope)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue