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:
Jorge Martin Espinosa
2025-09-04 14:56:46 +02:00
committed by GitHub
parent b2d4985205
commit d4d57b1e21
6 changed files with 61 additions and 23 deletions
@@ -38,6 +38,7 @@ import kotlinx.collections.immutable.ImmutableMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toPersistentMap
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
@@ -66,11 +67,6 @@ class RoomMemberListPresenter @Inject constructor(
val syncUpdateFlow = room.syncUpdateFlow.collectAsState()
val canInvite by room.canInviteAsState(syncUpdateFlow.value)
val roomModerationState = roomMembersModerationPresenter.present()
val activeRoomMemberCount by produceState(0L) {
room.roomInfoFlow.map { it.activeMembersCount }
.distinctUntilChanged()
.collect { value = it }
}
val roomMemberIdentityStates by produceState(persistentMapOf<UserId, IdentityState>()) {
room.roomMemberIdentityStateChange(waitForEncryption = true)
@@ -81,8 +77,12 @@ class RoomMemberListPresenter @Inject constructor(
}
// Update the room members when the screen is loaded or the active member count changes
LaunchedEffect(activeRoomMemberCount) {
room.updateMembers()
LaunchedEffect(Unit) {
room.roomInfoFlow.map { it.activeMembersCount }
.distinctUntilChanged()
.collectLatest {
room.updateMembers()
}
}
LaunchedEffect(membersState, roomMemberIdentityStates) {
@@ -116,9 +116,6 @@ class RoomMemberListPresenterTest {
}
}
// Wait for the update to be processed
skipItems(1)
// Update the room members state as `Room.updateMembers()` would have done with the actual implementation
room.givenRoomMembersState(RoomMembersState.Ready(persistentListOf()))
// Wait for another update