mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-25 02:18:31 +03:00
Sort room members strictly by power level, instead of "custom" category
Change-Id: I047aace63a0cd475ace85748b3b37326a599f8e6
This commit is contained in:
parent
62a5b216f5
commit
114fc70820
5 changed files with 65 additions and 13 deletions
|
@ -69,13 +69,15 @@ class RoomMemberListController @Inject constructor(
|
||||||
}
|
}
|
||||||
.orEmpty()
|
.orEmpty()
|
||||||
var threePidInvitesDone = filteredThreePidInvites.isEmpty()
|
var threePidInvitesDone = filteredThreePidInvites.isEmpty()
|
||||||
|
var isFirstSection = true
|
||||||
|
|
||||||
for ((powerLevelCategory, roomMemberList) in roomMembersByPowerLevel) {
|
for ((powerLevelCategory, roomMemberList) in roomMembersByPowerLevel) {
|
||||||
val filteredRoomMemberList = roomMemberList.filter { roomMemberSummaryFilter.test(it) }
|
val filteredRoomMemberList = roomMemberList.filter { roomMemberSummaryFilter.test(it.roomMemberSummary) }
|
||||||
if (filteredRoomMemberList.isEmpty()) {
|
if (filteredRoomMemberList.isEmpty()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (powerLevelCategory == RoomMemberListCategories.USER && !threePidInvitesDone) {
|
if (powerLevelCategory == RoomMemberListCategories.USER && !threePidInvitesDone) {
|
||||||
// If there is no regular invite, display threepid invite before the regular user
|
// If there is no regular invite, display threepid invite before the regular user
|
||||||
buildProfileSection(
|
buildProfileSection(
|
||||||
|
@ -85,18 +87,22 @@ class RoomMemberListController @Inject constructor(
|
||||||
buildThreePidInvites(filteredThreePidInvites, data.actionsPermissions.canRevokeThreePidInvite)
|
buildThreePidInvites(filteredThreePidInvites, data.actionsPermissions.canRevokeThreePidInvite)
|
||||||
threePidInvitesDone = true
|
threePidInvitesDone = true
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (powerLevelCategory != RoomMemberListCategories.MEMBER || !isFirstSection) {
|
||||||
buildProfileSection(
|
buildProfileSection(
|
||||||
stringProvider.getString(powerLevelCategory.titleRes)
|
stringProvider.getString(powerLevelCategory.titleRes)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
isFirstSection = false
|
||||||
|
|
||||||
filteredRoomMemberList.join(
|
filteredRoomMemberList.join(
|
||||||
each = { _, roomMember ->
|
each = { _, roomMember ->
|
||||||
buildRoomMember(roomMember, powerLevelCategory, host, data)
|
buildRoomMember(roomMember.roomMemberSummary, roomMember.powerLevelCategory, host, data)
|
||||||
},
|
},
|
||||||
between = { _, roomMemberBefore ->
|
between = { _, roomMemberBefore ->
|
||||||
dividerItem {
|
dividerItem {
|
||||||
id("divider_${roomMemberBefore.userId}")
|
id("divider_${roomMemberBefore.roomMemberSummary.userId}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -52,7 +52,8 @@ import org.matrix.android.sdk.flow.unwrap
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
|
||||||
class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState,
|
class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState,
|
||||||
private val roomMemberSummaryComparator: RoomMemberSummaryComparator,
|
//private val roomMemberSummaryComparator: RoomMemberSummaryComparator,
|
||||||
|
private val roomMemberSummaryWithPowerComparator: RoomMemberSummaryWithPowerComparator,
|
||||||
private val session: Session) :
|
private val session: Session) :
|
||||||
VectorViewModel<RoomMemberListViewState, RoomMemberListAction, EmptyViewEvents>(initialState) {
|
VectorViewModel<RoomMemberListViewState, RoomMemberListAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
|
@ -149,7 +150,11 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildRoomMemberSummaries(powerLevelsContent: PowerLevelsContent, roomMembers: List<RoomMemberSummary>): RoomMemberSummaries {
|
private fun List<RoomMemberSummary>.toPoweredMemberList(listCategory: RoomMemberListCategories, powerLevelsHelper: PowerLevelsHelper): List<RoomMemberSummaryWithPower> {
|
||||||
|
return map { RoomMemberSummaryWithPower(it, listCategory, powerLevelsHelper.getUserPowerLevelValue(it.userId)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildRoomMemberSummaries(powerLevelsContent: PowerLevelsContent, roomMembers: List<RoomMemberSummary>): RoomMemberSummariesWithPower {
|
||||||
val admins = ArrayList<RoomMemberSummary>()
|
val admins = ArrayList<RoomMemberSummary>()
|
||||||
val moderators = ArrayList<RoomMemberSummary>()
|
val moderators = ArrayList<RoomMemberSummary>()
|
||||||
val users = ArrayList<RoomMemberSummary>(roomMembers.size)
|
val users = ArrayList<RoomMemberSummary>(roomMembers.size)
|
||||||
|
@ -168,6 +173,7 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
return listOf(
|
return listOf(
|
||||||
RoomMemberListCategories.ADMIN to admins.sortedWith(roomMemberSummaryComparator),
|
RoomMemberListCategories.ADMIN to admins.sortedWith(roomMemberSummaryComparator),
|
||||||
RoomMemberListCategories.MODERATOR to moderators.sortedWith(roomMemberSummaryComparator),
|
RoomMemberListCategories.MODERATOR to moderators.sortedWith(roomMemberSummaryComparator),
|
||||||
|
@ -175,6 +181,16 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
RoomMemberListCategories.INVITE to invites.sortedWith(roomMemberSummaryComparator),
|
RoomMemberListCategories.INVITE to invites.sortedWith(roomMemberSummaryComparator),
|
||||||
RoomMemberListCategories.USER to users.sortedWith(roomMemberSummaryComparator)
|
RoomMemberListCategories.USER to users.sortedWith(roomMemberSummaryComparator)
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
|
val invitesWithPower = invites.toPoweredMemberList(RoomMemberListCategories.INVITE, powerLevelsHelper)
|
||||||
|
val membersWithPower = admins.toPoweredMemberList(RoomMemberListCategories.SG_ADMIN, powerLevelsHelper) +
|
||||||
|
moderators.toPoweredMemberList(RoomMemberListCategories.SG_MODERATOR, powerLevelsHelper) +
|
||||||
|
users.toPoweredMemberList(RoomMemberListCategories.SG_USER, powerLevelsHelper) +
|
||||||
|
customs.toPoweredMemberList(RoomMemberListCategories.SG_CUSTOM, powerLevelsHelper)
|
||||||
|
return listOf(
|
||||||
|
RoomMemberListCategories.INVITE to invitesWithPower.sortedWith(roomMemberSummaryWithPowerComparator),
|
||||||
|
RoomMemberListCategories.MEMBER to membersWithPower.sortedWith(roomMemberSummaryWithPowerComparator)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handle(action: RoomMemberListAction) {
|
override fun handle(action: RoomMemberListAction) {
|
||||||
|
@ -201,4 +217,10 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class RoomMemberSummaryWithPower constructor(
|
||||||
|
val roomMemberSummary: RoomMemberSummary,
|
||||||
|
val powerLevelCategory: RoomMemberListCategories,
|
||||||
|
val powerLevel: Int
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
|
||||||
data class RoomMemberListViewState(
|
data class RoomMemberListViewState(
|
||||||
val roomId: String,
|
val roomId: String,
|
||||||
val roomSummary: Async<RoomSummary> = Uninitialized,
|
val roomSummary: Async<RoomSummary> = Uninitialized,
|
||||||
val roomMemberSummaries: Async<RoomMemberSummaries> = Uninitialized,
|
val roomMemberSummaries: Async<RoomMemberSummariesWithPower> = Uninitialized,
|
||||||
val filter: String = "",
|
val filter: String = "",
|
||||||
val threePidInvites: Async<List<Event>> = Uninitialized,
|
val threePidInvites: Async<List<Event>> = Uninitialized,
|
||||||
val trustLevelMap: Async<Map<String, RoomEncryptionTrustLevel?>> = Uninitialized,
|
val trustLevelMap: Async<Map<String, RoomEncryptionTrustLevel?>> = Uninitialized,
|
||||||
|
@ -49,11 +49,20 @@ data class ActionPermissions(
|
||||||
)
|
)
|
||||||
|
|
||||||
typealias RoomMemberSummaries = List<Pair<RoomMemberListCategories, List<RoomMemberSummary>>>
|
typealias RoomMemberSummaries = List<Pair<RoomMemberListCategories, List<RoomMemberSummary>>>
|
||||||
|
typealias RoomMemberSummariesWithPower = List<Pair<RoomMemberListCategories, List<RoomMemberListViewModel.RoomMemberSummaryWithPower>>>
|
||||||
|
|
||||||
enum class RoomMemberListCategories(@StringRes val titleRes: Int) {
|
enum class RoomMemberListCategories(@StringRes val titleRes: Int) {
|
||||||
ADMIN(R.string.room_member_power_level_admins),
|
ADMIN(R.string.room_member_power_level_admins),
|
||||||
MODERATOR(R.string.room_member_power_level_moderators),
|
MODERATOR(R.string.room_member_power_level_moderators),
|
||||||
CUSTOM(R.string.room_member_power_level_custom),
|
CUSTOM(R.string.room_member_power_level_custom),
|
||||||
INVITE(R.string.room_member_power_level_invites),
|
INVITE(R.string.room_member_power_level_invites),
|
||||||
USER(R.string.room_member_power_level_users)
|
USER(R.string.room_member_power_level_users),
|
||||||
|
|
||||||
|
// Singular variants
|
||||||
|
SG_ADMIN(R.string.power_level_admin),
|
||||||
|
SG_MODERATOR(R.string.power_level_moderator),
|
||||||
|
SG_CUSTOM(R.string.power_level_custom_no_value),
|
||||||
|
SG_USER(R.string.power_level_default),
|
||||||
|
// Header for unified members
|
||||||
|
MEMBER(R.string.room_member_power_level_users)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package im.vector.app.features.roomprofile.members
|
||||||
|
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class RoomMemberSummaryWithPowerComparator @Inject constructor(private val roomMemberSummaryComparator: RoomMemberSummaryComparator) : Comparator<RoomMemberListViewModel.RoomMemberSummaryWithPower> {
|
||||||
|
|
||||||
|
override fun compare(leftRoomMemberSummary: RoomMemberListViewModel.RoomMemberSummaryWithPower?, rightRoomMemberSummary: RoomMemberListViewModel.RoomMemberSummaryWithPower?): Int {
|
||||||
|
return if (leftRoomMemberSummary == null || rightRoomMemberSummary == null || leftRoomMemberSummary.powerLevel == rightRoomMemberSummary.powerLevel) {
|
||||||
|
roomMemberSummaryComparator.compare(leftRoomMemberSummary?.roomMemberSummary, rightRoomMemberSummary?.roomMemberSummary)
|
||||||
|
} else {
|
||||||
|
rightRoomMemberSummary.powerLevel - leftRoomMemberSummary.powerLevel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,7 +66,7 @@ class SpacePeopleListController @Inject constructor(
|
||||||
memberSummaries.forEach { memberEntry ->
|
memberSummaries.forEach { memberEntry ->
|
||||||
|
|
||||||
val filtered = memberEntry.second
|
val filtered = memberEntry.second
|
||||||
.filter { roomMemberSummaryFilter.test(it) }
|
.filter { roomMemberSummaryFilter.test(it.roomMemberSummary) }
|
||||||
if (filtered.isNotEmpty()) {
|
if (filtered.isNotEmpty()) {
|
||||||
dividerItem {
|
dividerItem {
|
||||||
id("divider_type_${memberEntry.first.titleRes}")
|
id("divider_type_${memberEntry.first.titleRes}")
|
||||||
|
@ -75,7 +75,8 @@ class SpacePeopleListController @Inject constructor(
|
||||||
foundCount += filtered.size
|
foundCount += filtered.size
|
||||||
filtered
|
filtered
|
||||||
.join(
|
.join(
|
||||||
each = { _, roomMember ->
|
each = { _, roomMemberWrapper ->
|
||||||
|
val roomMember = roomMemberWrapper.roomMemberSummary
|
||||||
profileMatrixItemWithPowerLevel {
|
profileMatrixItemWithPowerLevel {
|
||||||
id(roomMember.userId)
|
id(roomMember.userId)
|
||||||
matrixItem(roomMember.toMatrixItem())
|
matrixItem(roomMember.toMatrixItem())
|
||||||
|
@ -118,7 +119,7 @@ class SpacePeopleListController @Inject constructor(
|
||||||
},
|
},
|
||||||
between = { _, roomMemberBefore ->
|
between = { _, roomMemberBefore ->
|
||||||
dividerItem {
|
dividerItem {
|
||||||
id("divider_${roomMemberBefore.userId}")
|
id("divider_${roomMemberBefore.roomMemberSummary.userId}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue