From 759022ec92cb879fdae8020a61737b6256006563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Fri, 22 Mar 2024 10:13:51 +0100 Subject: [PATCH 1/3] Update member list after changing member roles Also do it when the user enters the room member list screen. --- .../roomdetails/impl/members/RoomMemberListPresenter.kt | 5 +++++ .../rolesandpermissions/changeroles/ChangeRolesPresenter.kt | 2 ++ 2 files changed, 7 insertions(+) diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt index d67f80d3c2..c05388bfc7 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListPresenter.kt @@ -84,6 +84,11 @@ class RoomMemberListPresenter @AssistedInject constructor( remember { roomMembersModerationPresenter.dummyState() } } + // Ensure we load the latest data when entering this screen + LaunchedEffect(Unit) { + room.updateMembers() + } + LaunchedEffect(membersState) { if (membersState is MatrixRoomMembersState.Unknown) { return@LaunchedEffect diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/rolesandpermissions/changeroles/ChangeRolesPresenter.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/rolesandpermissions/changeroles/ChangeRolesPresenter.kt index edc11f1f5f..dc1c2ef70e 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/rolesandpermissions/changeroles/ChangeRolesPresenter.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/rolesandpermissions/changeroles/ChangeRolesPresenter.kt @@ -216,6 +216,8 @@ class ChangeRolesPresenter @AssistedInject constructor( } .onSuccess { saveState.value = AsyncAction.Success(Unit) + // Asynchronously reload the room members + launch { room.updateMembers() } } } } From 9f2726ec4f919e74438356172cd13379d252bfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Fri, 22 Mar 2024 10:14:22 +0100 Subject: [PATCH 2/3] Only retrieve active users in `RoomMemberListDataSource` --- .../roomdetails/impl/members/RoomMemberListDataSource.kt | 8 +++++--- .../android/libraries/matrix/api/room/RoomMember.kt | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt index faf1f9fc78..e475497865 100644 --- a/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt +++ b/features/roomdetails/impl/src/main/kotlin/io/element/android/features/roomdetails/impl/members/RoomMemberListDataSource.kt @@ -30,11 +30,13 @@ class RoomMemberListDataSource @Inject constructor( ) { suspend fun search(query: String): List = withContext(coroutineDispatchers.io) { val roomMembersState = room.membersStateFlow.value - val roomMembers = roomMembersState.roomMembers().orEmpty() + val activeRoomMembers = roomMembersState.roomMembers() + ?.filter { it.membership.isActive() } + .orEmpty() val filteredMembers = if (query.isBlank()) { - roomMembers + activeRoomMembers } else { - roomMembers.filter { member -> + activeRoomMembers.filter { member -> member.userId.value.contains(query, ignoreCase = true) || member.displayName?.contains(query, ignoreCase = true).orFalse() } diff --git a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/RoomMember.kt b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/RoomMember.kt index 60f4102234..f6609a2bce 100644 --- a/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/RoomMember.kt +++ b/libraries/matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/room/RoomMember.kt @@ -66,7 +66,9 @@ enum class RoomMembershipState { INVITE, JOIN, KNOCK, - LEAVE + LEAVE; + + fun isActive(): Boolean = this == JOIN || this == INVITE } /** From 5030257950fec4813d51650a11479d9b1b78c39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Fri, 22 Mar 2024 10:14:31 +0100 Subject: [PATCH 3/3] Add changelog --- changelog.d/2590.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/2590.bugfix diff --git a/changelog.d/2590.bugfix b/changelog.d/2590.bugfix new file mode 100644 index 0000000000..c6cfed9609 --- /dev/null +++ b/changelog.d/2590.bugfix @@ -0,0 +1 @@ +Update member list after changing member roles and when the room member list is opened.