Sort room members by display names
This commit is contained in:
parent
d7feb6dd5c
commit
57a13fa30d
|
@ -8,6 +8,7 @@ Features ✨:
|
||||||
Improvements 🙌:
|
Improvements 🙌:
|
||||||
- Sharing things to RiotX: sort list by recent room first (#771)
|
- Sharing things to RiotX: sort list by recent room first (#771)
|
||||||
- Hide the algorithm when turning on e2e (#897)
|
- Hide the algorithm when turning on e2e (#897)
|
||||||
|
- Sort room members by display names
|
||||||
|
|
||||||
Other changes:
|
Other changes:
|
||||||
- Add support for /rainbow and /rainbowme commands (#879)
|
- Add support for /rainbow and /rainbowme commands (#879)
|
||||||
|
|
|
@ -40,6 +40,7 @@ import io.reactivex.Observable
|
||||||
import io.reactivex.functions.BiFunction
|
import io.reactivex.functions.BiFunction
|
||||||
|
|
||||||
class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState,
|
class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState: RoomMemberListViewState,
|
||||||
|
private val roomMemberSummaryComparator: RoomMemberSummaryComparator,
|
||||||
private val session: Session)
|
private val session: Session)
|
||||||
: VectorViewModel<RoomMemberListViewState, RoomMemberListAction, EmptyViewEvents>(initialState) {
|
: VectorViewModel<RoomMemberListViewState, RoomMemberListAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
|
@ -113,11 +114,11 @@ class RoomMemberListViewModel @AssistedInject constructor(@Assisted initialState
|
||||||
}
|
}
|
||||||
|
|
||||||
return listOf(
|
return listOf(
|
||||||
PowerLevelCategory.ADMIN to admins,
|
PowerLevelCategory.ADMIN to admins.sortedWith(roomMemberSummaryComparator),
|
||||||
PowerLevelCategory.MODERATOR to moderators,
|
PowerLevelCategory.MODERATOR to moderators.sortedWith(roomMemberSummaryComparator),
|
||||||
PowerLevelCategory.CUSTOM to customs,
|
PowerLevelCategory.CUSTOM to customs.sortedWith(roomMemberSummaryComparator),
|
||||||
PowerLevelCategory.INVITE to invites,
|
PowerLevelCategory.INVITE to invites.sortedWith(roomMemberSummaryComparator),
|
||||||
PowerLevelCategory.USER to users
|
PowerLevelCategory.USER to users.sortedWith(roomMemberSummaryComparator)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.riotx.features.roomprofile.members
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.room.model.RoomMemberSummary
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class RoomMemberSummaryComparator @Inject constructor() : Comparator<RoomMemberSummary> {
|
||||||
|
|
||||||
|
override fun compare(leftRoomMemberSummary: RoomMemberSummary?, rightRoomMemberSummary: RoomMemberSummary?): Int {
|
||||||
|
return when (leftRoomMemberSummary) {
|
||||||
|
null ->
|
||||||
|
when (rightRoomMemberSummary) {
|
||||||
|
null -> 0
|
||||||
|
else -> 1
|
||||||
|
}
|
||||||
|
else ->
|
||||||
|
when (rightRoomMemberSummary) {
|
||||||
|
null -> -1
|
||||||
|
else ->
|
||||||
|
when {
|
||||||
|
leftRoomMemberSummary.displayName.isNullOrBlank() ->
|
||||||
|
when {
|
||||||
|
rightRoomMemberSummary.displayName.isNullOrBlank() -> {
|
||||||
|
// No display names, compare ids
|
||||||
|
leftRoomMemberSummary.userId.compareTo(rightRoomMemberSummary.userId)
|
||||||
|
}
|
||||||
|
else -> 1
|
||||||
|
}
|
||||||
|
else ->
|
||||||
|
when {
|
||||||
|
rightRoomMemberSummary.displayName.isNullOrBlank() -> -1
|
||||||
|
else -> {
|
||||||
|
when (leftRoomMemberSummary.displayName) {
|
||||||
|
rightRoomMemberSummary.displayName ->
|
||||||
|
// Same display name, compare id
|
||||||
|
leftRoomMemberSummary.userId.compareTo(rightRoomMemberSummary.userId)
|
||||||
|
else ->
|
||||||
|
leftRoomMemberSummary.displayName!!.compareTo(rightRoomMemberSummary.displayName!!, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue