Merge pull request #5376 from element-hq/feature/fix_room_membership_nav
fix (room navigation) : fix navigation when leaving room/space
This commit is contained in:
commit
a7fb213ff7
1 changed files with 22 additions and 25 deletions
|
|
@ -54,7 +54,6 @@ import kotlinx.coroutines.flow.SharingStarted
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.filter
|
import kotlinx.coroutines.flow.filter
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.shareIn
|
import kotlinx.coroutines.flow.shareIn
|
||||||
|
|
@ -111,7 +110,7 @@ class RoomFlowNode(
|
||||||
data class JoinedRoom(val roomId: RoomId) : NavTarget
|
data class JoinedRoom(val roomId: RoomId) : NavTarget
|
||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class Space(val spaceId: RoomId) : NavTarget
|
data class JoinedSpace(val spaceId: RoomId) : NavTarget
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBuilt() {
|
override fun onBuilt() {
|
||||||
|
|
@ -149,30 +148,28 @@ class RoomFlowNode(
|
||||||
.withPreviousValue()
|
.withPreviousValue()
|
||||||
combine(currentMembershipFlow, isSpaceFlow) { (previousMembership, membership), isSpace ->
|
combine(currentMembershipFlow, isSpaceFlow) { (previousMembership, membership), isSpace ->
|
||||||
Timber.d("Room membership: $membership")
|
Timber.d("Room membership: $membership")
|
||||||
when (membership) {
|
if (membership == CurrentUserMembership.JOINED) {
|
||||||
CurrentUserMembership.JOINED -> {
|
if (isSpace) {
|
||||||
if (isSpace) {
|
backstack.newRoot(NavTarget.JoinedSpace(spaceId = roomId))
|
||||||
backstack.newRoot(NavTarget.Space(spaceId = roomId))
|
} else {
|
||||||
} else {
|
backstack.newRoot(NavTarget.JoinedRoom(roomId))
|
||||||
backstack.newRoot(NavTarget.JoinedRoom(roomId))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else -> {
|
} else {
|
||||||
if (membership == CurrentUserMembership.LEFT && previousMembership == CurrentUserMembership.JOINED) {
|
val leavingFromCurrentDevice =
|
||||||
// The user left the room in this device, remove the room from the backstack
|
membership == CurrentUserMembership.LEFT &&
|
||||||
if (!membershipUpdateFlow.first().isUserInRoom) {
|
previousMembership == CurrentUserMembership.JOINED &&
|
||||||
navigateUp()
|
membershipUpdateFlow.replayCache.lastOrNull()?.isUserInRoom == false
|
||||||
}
|
|
||||||
} else {
|
if (leavingFromCurrentDevice) {
|
||||||
// Was invited or the room is not known, display the join room screen
|
navigateUp()
|
||||||
backstack.newRoot(
|
} else {
|
||||||
NavTarget.JoinRoom(
|
backstack.newRoot(
|
||||||
roomId = roomId,
|
NavTarget.JoinRoom(
|
||||||
serverNames = serverNames,
|
roomId = roomId,
|
||||||
trigger = inputs.trigger.getOrNull() ?: JoinedRoom.Trigger.Invite,
|
serverNames = serverNames,
|
||||||
)
|
trigger = inputs.trigger.getOrNull() ?: JoinedRoom.Trigger.Invite,
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.launchIn(lifecycleScope)
|
}.launchIn(lifecycleScope)
|
||||||
|
|
@ -214,7 +211,7 @@ class RoomFlowNode(
|
||||||
)
|
)
|
||||||
createNode<JoinedRoomFlowNode>(buildContext, plugins = listOf(inputs) + roomFlowNodeCallback)
|
createNode<JoinedRoomFlowNode>(buildContext, plugins = listOf(inputs) + roomFlowNodeCallback)
|
||||||
}
|
}
|
||||||
is NavTarget.Space -> {
|
is NavTarget.JoinedSpace -> {
|
||||||
val spaceCallback = plugins<SpaceEntryPoint.Callback>().single()
|
val spaceCallback = plugins<SpaceEntryPoint.Callback>().single()
|
||||||
spaceEntryPoint.nodeBuilder(this, buildContext)
|
spaceEntryPoint.nodeBuilder(this, buildContext)
|
||||||
.inputs(SpaceEntryPoint.Inputs(roomId = navTarget.spaceId))
|
.inputs(SpaceEntryPoint.Inputs(roomId = navTarget.spaceId))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue