Fix a problem with filtering 3pid invite.

We were using the whole 3pid invite if they were not all filtered.
Also double filtering on RoomThirdPartyInviteContent type is not necessary
This commit is contained in:
Benoit Marty 2021-11-04 15:59:20 +01:00 committed by Benoit Marty
parent 345dac4a3b
commit 41ab117182
1 changed files with 9 additions and 10 deletions

View File

@ -61,7 +61,7 @@ class RoomMemberListController @Inject constructor(
roomMemberSummaryFilter.filter = data.filter roomMemberSummaryFilter.filter = data.filter
val roomMembersByPowerLevel = data.roomMemberSummaries.invoke() ?: return val roomMembersByPowerLevel = data.roomMemberSummaries.invoke() ?: return
val threePidInvites = data.threePidInvites() val filteredThreePidInvites = data.threePidInvites()
?.filter { event -> ?.filter { event ->
event.content.toModel<RoomThirdPartyInviteContent>() event.content.toModel<RoomThirdPartyInviteContent>()
?.takeIf { ?.takeIf {
@ -69,7 +69,7 @@ class RoomMemberListController @Inject constructor(
} != null } != null
} }
.orEmpty() .orEmpty()
var threePidInvitesDone = threePidInvites.isEmpty() var threePidInvitesDone = filteredThreePidInvites.isEmpty()
for ((powerLevelCategory, roomMemberList) in roomMembersByPowerLevel) { for ((powerLevelCategory, roomMemberList) in roomMembersByPowerLevel) {
val filteredRoomMemberList = roomMemberList.filter { roomMemberSummaryFilter.test(it) } val filteredRoomMemberList = roomMemberList.filter { roomMemberSummaryFilter.test(it) }
@ -83,7 +83,7 @@ class RoomMemberListController @Inject constructor(
stringProvider.getString(RoomMemberListCategories.INVITE.titleRes) stringProvider.getString(RoomMemberListCategories.INVITE.titleRes)
) )
buildThreePidInvites(data) buildThreePidInvites(filteredThreePidInvites, data.actionsPermissions.canRevokeThreePidInvite)
threePidInvitesDone = true threePidInvitesDone = true
} }
@ -107,7 +107,7 @@ class RoomMemberListController @Inject constructor(
id("divider_threepidinvites") id("divider_threepidinvites")
} }
buildThreePidInvites(data) buildThreePidInvites(filteredThreePidInvites, data.actionsPermissions.canRevokeThreePidInvite)
threePidInvitesDone = true threePidInvitesDone = true
} }
} }
@ -118,7 +118,7 @@ class RoomMemberListController @Inject constructor(
stringProvider.getString(RoomMemberListCategories.INVITE.titleRes) stringProvider.getString(RoomMemberListCategories.INVITE.titleRes)
) )
buildThreePidInvites(data) buildThreePidInvites(filteredThreePidInvites, data.actionsPermissions.canRevokeThreePidInvite)
} }
} }
@ -148,11 +148,10 @@ class RoomMemberListController @Inject constructor(
} }
} }
private fun buildThreePidInvites(data: RoomMemberListViewState) { private fun buildThreePidInvites(filteredThreePidInvites: List<Event>, canRevokeThreePidInvite: Boolean) {
val host = this val host = this
data.threePidInvites() filteredThreePidInvites
?.filter { it.content.toModel<RoomThirdPartyInviteContent>() != null } .join(
?.join(
each = { idx, event -> each = { idx, event ->
event.content.toModel<RoomThirdPartyInviteContent>() event.content.toModel<RoomThirdPartyInviteContent>()
?.let { content -> ?.let { content ->
@ -160,7 +159,7 @@ class RoomMemberListController @Inject constructor(
id("3pid_$idx") id("3pid_$idx")
matrixItem(MatrixItem.UserItem("@", displayName = content.displayName)) matrixItem(MatrixItem.UserItem("@", displayName = content.displayName))
avatarRenderer(host.avatarRenderer) avatarRenderer(host.avatarRenderer)
editable(data.actionsPermissions.canRevokeThreePidInvite) editable(canRevokeThreePidInvite)
clickListener { clickListener {
host.callback?.onThreePidInviteClicked(event) host.callback?.onThreePidInviteClicked(event)
} }