fix : use RoomMembershipObserver to close room screen when leaving/declining invite/canceling knock request
This commit is contained in:
parent
86a6244d8e
commit
aa1a1514aa
8 changed files with 44 additions and 33 deletions
|
|
@ -48,9 +48,11 @@ import io.element.android.libraries.matrix.api.core.RoomIdOrAlias
|
|||
import io.element.android.libraries.matrix.api.core.toRoomIdOrAlias
|
||||
import io.element.android.libraries.matrix.api.getRoomInfoFlow
|
||||
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
||||
import io.element.android.libraries.matrix.api.room.alias.ResolvedRoomAlias
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -67,6 +69,7 @@ class RoomFlowNode @AssistedInject constructor(
|
|||
private val joinRoomEntryPoint: JoinRoomEntryPoint,
|
||||
private val roomAliasResolverEntryPoint: RoomAliasResolverEntryPoint,
|
||||
private val networkMonitor: NetworkMonitor,
|
||||
private val membershipObserver: RoomMembershipObserver,
|
||||
) : BaseFlowNode<RoomFlowNode.NavTarget>(
|
||||
backstack = BackStack(
|
||||
initialElement = NavTarget.Loading,
|
||||
|
|
@ -145,10 +148,6 @@ class RoomFlowNode @AssistedInject constructor(
|
|||
backstack.newRoot(NavTarget.JoinedRoom(roomId))
|
||||
}
|
||||
}
|
||||
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(
|
||||
|
|
@ -161,6 +160,15 @@ class RoomFlowNode @AssistedInject constructor(
|
|||
}
|
||||
}
|
||||
}.launchIn(lifecycleScope)
|
||||
|
||||
// If the user leaves the room from this client, close the room flow.
|
||||
lifecycleScope.launch {
|
||||
membershipObserver.updates
|
||||
.first { it.roomId == roomId && !it.isUserInRoom }
|
||||
.run {
|
||||
navigateUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolve(navTarget: NavTarget, buildContext: BuildContext): Node {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue