Reload member list after moderation actions (#5268)
* Reload member list after moderation actions The previous `runActionAndWaitForMembershipChange` logic wasn't really doing anything, as the modified flow was never used. * Make sure we always set the value in the member list state flow, even if the underlying coroutine scope is no longer there. With `emit`, the `Ready` state was not emitted if the member list was loaded way too fast.
This commit is contained in:
parent
25da1cba83
commit
2eacce47c0
6 changed files with 61 additions and 23 deletions
|
|
@ -38,10 +38,12 @@ import kotlinx.collections.immutable.PersistentList
|
|||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.take
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
class RoomMemberModerationPresenter @Inject constructor(
|
||||
private val room: JoinedRoom,
|
||||
|
|
@ -82,6 +84,9 @@ class RoomMemberModerationPresenter @Inject constructor(
|
|||
)
|
||||
}
|
||||
is RoomMemberModerationEvents.ProcessAction -> {
|
||||
// First, hide any list of existing actions that could be displayed
|
||||
moderationActions.value = persistentListOf()
|
||||
|
||||
when (event.action) {
|
||||
is ModerationAction.DisplayProfile -> Unit
|
||||
is ModerationAction.KickUser -> {
|
||||
|
|
@ -118,6 +123,7 @@ class RoomMemberModerationPresenter @Inject constructor(
|
|||
}
|
||||
is InternalRoomMemberModerationEvents.Reset -> {
|
||||
selectedUser = null
|
||||
moderationActions.value = persistentListOf()
|
||||
kickUserAsyncAction.value = AsyncAction.Uninitialized
|
||||
banUserAsyncAction.value = AsyncAction.Uninitialized
|
||||
unbanUserAsyncAction.value = AsyncAction.Uninitialized
|
||||
|
|
@ -204,7 +210,15 @@ class RoomMemberModerationPresenter @Inject constructor(
|
|||
action.runUpdatingState {
|
||||
val result = block()
|
||||
if (result.isSuccess) {
|
||||
room.membersStateFlow.drop(1).take(1)
|
||||
// We wait a bit to ensure the server has processed the membership change
|
||||
delay(50.milliseconds)
|
||||
|
||||
// Update the members to ensure we have the latest state
|
||||
launch { room.updateMembers() }
|
||||
|
||||
// Wait for the membership change to be processed and returned
|
||||
// We drop the first emission as it's the current state
|
||||
room.membersStateFlow.drop(1).first()
|
||||
}
|
||||
result
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue