Display threePid invite along with the other invite (code is a bit dirty)

This commit is contained in:
Benoit Marty 2020-07-10 10:14:02 +02:00
parent 4ba1a34f38
commit a58bb776f3
3 changed files with 61 additions and 29 deletions
vector/src/main
java/im/vector/riotx
core/extensions
features/roomprofile/members
res/values

View file

@ -38,13 +38,13 @@ inline fun <T, R : Comparable<R>> Iterable<T>.lastMinBy(selector: (T) -> R): T?
/** /**
* Call each for each item, and between between each items * Call each for each item, and between between each items
*/ */
inline fun <T> Collection<T>.join(each: (T) -> Unit, between: (T) -> Unit) { inline fun <T> Collection<T>.join(each: (Int, T) -> Unit, between: (Int, T) -> Unit) {
val lastIndex = size - 1 val lastIndex = size - 1
forEachIndexed { idx, t -> forEachIndexed { idx, t ->
each(t) each(idx, t)
if (idx != lastIndex) { if (idx != lastIndex) {
between(t) between(idx, t)
} }
} }
} }

View file

@ -54,15 +54,29 @@ class RoomMemberListController @Inject constructor(
override fun buildModels(data: RoomMemberListViewState?) { override fun buildModels(data: RoomMemberListViewState?) {
val roomMembersByPowerLevel = data?.roomMemberSummaries?.invoke() ?: return val roomMembersByPowerLevel = data?.roomMemberSummaries?.invoke() ?: return
val threePidInvites = data.threePidInvites().orEmpty()
var threePidInvitesDone = threePidInvites.isEmpty()
for ((powerLevelCategory, roomMemberList) in roomMembersByPowerLevel) { for ((powerLevelCategory, roomMemberList) in roomMembersByPowerLevel) {
if (roomMemberList.isEmpty()) { if (roomMemberList.isEmpty()) {
continue continue
} }
if (powerLevelCategory == RoomMemberListCategories.USER && !threePidInvitesDone) {
// If there is not regular invite, display threepid invite before the regular user
buildProfileSection(
stringProvider.getString(RoomMemberListCategories.INVITE.titleRes)
)
buildThreePidInvites(data)
threePidInvitesDone = true
}
buildProfileSection( buildProfileSection(
stringProvider.getString(powerLevelCategory.titleRes) stringProvider.getString(powerLevelCategory.titleRes)
) )
roomMemberList.join( roomMemberList.join(
each = { roomMember -> each = { _, roomMember ->
profileMatrixItem { profileMatrixItem {
id(roomMember.userId) id(roomMember.userId)
matrixItem(roomMember.toMatrixItem()) matrixItem(roomMember.toMatrixItem())
@ -73,40 +87,59 @@ class RoomMemberListController @Inject constructor(
} }
} }
}, },
between = { roomMemberBefore -> between = { _, roomMemberBefore ->
dividerItem { dividerItem {
id("divider_${roomMemberBefore.userId}") id("divider_${roomMemberBefore.userId}")
color(dividerColor) color(dividerColor)
} }
} }
) )
if (powerLevelCategory == RoomMemberListCategories.INVITE) {
// Display the threepid invite after the regular invite
dividerItem {
id("divider_threepidinvites")
color(dividerColor)
}
buildThreePidInvites(data)
threePidInvitesDone = true
}
}
if (!threePidInvitesDone) {
// If there is not regular invite and no regular user, finally display threepid invite here
buildProfileSection(
stringProvider.getString(RoomMemberListCategories.INVITE.titleRes)
)
buildThreePidInvites(data)
} }
buildThreePidInvites(data)
} }
private fun buildThreePidInvites(data: RoomMemberListViewState) { private fun buildThreePidInvites(data: RoomMemberListViewState) {
if (data.threePidInvites().isNullOrEmpty()) { data.threePidInvites()
return ?.filter { it.content.toModel<RoomThirdPartyInviteContent>() != null }
} ?.join(
each = { idx, event ->
buildProfileSection( event.content.toModel<RoomThirdPartyInviteContent>()
stringProvider.getString(R.string.room_member_power_level_three_pid_invites) ?.let { content ->
) profileMatrixItem {
id("3pid_$idx")
data.threePidInvites()?.forEachIndexed { idx, event -> matrixItem(content.toMatrixItem())
val content = event.content.toModel<RoomThirdPartyInviteContent>() ?: return@forEachIndexed avatarRenderer(avatarRenderer)
editable(data.actionsPermissions.canRevokeThreePidInvite)
profileMatrixItem { clickListener { _ ->
id("3pid_$idx") callback?.onThreePidInvites(event)
matrixItem(content.toMatrixItem()) }
avatarRenderer(avatarRenderer) }
editable(data.actionsPermissions.canRevokeThreePidInvite) }
clickListener { _ -> },
callback?.onThreePidInvites(event) between = { idx, _ ->
} dividerItem {
} id("divider3_$idx")
color(dividerColor)
} }
}
)
} }
private fun RoomThirdPartyInviteContent.toMatrixItem(): MatrixItem { private fun RoomThirdPartyInviteContent.toMatrixItem(): MatrixItem {

View file

@ -2148,7 +2148,6 @@ Not all features in Riot are implemented in RiotX yet. Main missing (and coming
<string name="room_member_power_level_custom">Custom</string> <string name="room_member_power_level_custom">Custom</string>
<string name="room_member_power_level_invites">Invites</string> <string name="room_member_power_level_invites">Invites</string>
<string name="room_member_power_level_users">Users</string> <string name="room_member_power_level_users">Users</string>
<string name="room_member_power_level_three_pid_invites">Other invites</string>
<string name="room_member_power_level_admin_in">Admin in %1$s</string> <string name="room_member_power_level_admin_in">Admin in %1$s</string>
<string name="room_member_power_level_moderator_in">Moderator in %1$s</string> <string name="room_member_power_level_moderator_in">Moderator in %1$s</string>