Merge pull request #3129 from vector-im/feature/bma/dn_iteration
Empty room name small iteration
This commit is contained in:
commit
eef6d92b89
|
@ -26,15 +26,18 @@ class TestRoomDisplayNameFallbackProvider : RoomDisplayNameFallbackProvider {
|
||||||
override fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List<String>) =
|
override fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List<String>) =
|
||||||
"Empty room"
|
"Empty room"
|
||||||
|
|
||||||
override fun getNameFor2members(name1: String?, name2: String?) =
|
override fun getNameFor1member(name: String) =
|
||||||
|
name
|
||||||
|
|
||||||
|
override fun getNameFor2members(name1: String, name2: String) =
|
||||||
"$name1 and $name2"
|
"$name1 and $name2"
|
||||||
|
|
||||||
override fun getNameFor3members(name1: String?, name2: String?, name3: String?) =
|
override fun getNameFor3members(name1: String, name2: String, name3: String) =
|
||||||
"$name1, $name2 and $name3"
|
"$name1, $name2 and $name3"
|
||||||
|
|
||||||
override fun getNameFor4members(name1: String?, name2: String?, name3: String?, name4: String?) =
|
override fun getNameFor4members(name1: String, name2: String, name3: String, name4: String) =
|
||||||
"$name1, $name2, $name3 and $name4"
|
"$name1, $name2, $name3 and $name4"
|
||||||
|
|
||||||
override fun getNameFor4membersAndMore(name1: String?, name2: String?, name3: String?, remainingCount: Int) =
|
override fun getNameFor4membersAndMore(name1: String, name2: String, name3: String, remainingCount: Int) =
|
||||||
"$name1, $name2, $name3 and $remainingCount others"
|
"$name1, $name2, $name3 and $remainingCount others"
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,9 @@ package org.matrix.android.sdk.api
|
||||||
interface RoomDisplayNameFallbackProvider {
|
interface RoomDisplayNameFallbackProvider {
|
||||||
fun getNameForRoomInvite(): String
|
fun getNameForRoomInvite(): String
|
||||||
fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List<String>): String
|
fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List<String>): String
|
||||||
fun getNameFor2members(name1: String?, name2: String?): String
|
fun getNameFor1member(name: String): String
|
||||||
fun getNameFor3members(name1: String?, name2: String?, name3: String?): String
|
fun getNameFor2members(name1: String, name2: String): String
|
||||||
fun getNameFor4members(name1: String?, name2: String?, name3: String?, name4: String?): String
|
fun getNameFor3members(name1: String, name2: String, name3: String): String
|
||||||
fun getNameFor4membersAndMore(name1: String?, name2: String?, name3: String?, remainingCount: Int): String
|
fun getNameFor4members(name1: String, name2: String, name3: String, name4: String): String
|
||||||
|
fun getNameFor4membersAndMore(name1: String, name2: String, name3: String, remainingCount: Int): String
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,11 @@ internal class RoomDisplayNameResolver @Inject constructor(
|
||||||
.map { it.getBestName() }
|
.map { it.getBestName() }
|
||||||
roomDisplayNameFallbackProvider.getNameForEmptyRoom(roomSummary?.isDirect.orFalse(), leftMembersNames)
|
roomDisplayNameFallbackProvider.getNameForEmptyRoom(roomSummary?.isDirect.orFalse(), leftMembersNames)
|
||||||
}
|
}
|
||||||
1 -> resolveRoomMemberName(otherMembersSubset[0], roomMembers)
|
1 -> {
|
||||||
|
roomDisplayNameFallbackProvider.getNameFor1member(
|
||||||
|
resolveRoomMemberName(otherMembersSubset[0], roomMembers)
|
||||||
|
)
|
||||||
|
}
|
||||||
2 -> {
|
2 -> {
|
||||||
roomDisplayNameFallbackProvider.getNameFor2members(
|
roomDisplayNameFallbackProvider.getNameFor2members(
|
||||||
resolveRoomMemberName(otherMembersSubset[0], roomMembers),
|
resolveRoomMemberName(otherMembersSubset[0], roomMembers),
|
||||||
|
@ -149,9 +153,8 @@ internal class RoomDisplayNameResolver @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
/** See [org.matrix.android.sdk.api.session.room.sender.SenderInfo.disambiguatedDisplayName] */
|
/** See [org.matrix.android.sdk.api.session.room.sender.SenderInfo.disambiguatedDisplayName] */
|
||||||
private fun resolveRoomMemberName(roomMemberSummary: RoomMemberSummaryEntity?,
|
private fun resolveRoomMemberName(roomMemberSummary: RoomMemberSummaryEntity,
|
||||||
roomMemberHelper: RoomMemberHelper): String? {
|
roomMemberHelper: RoomMemberHelper): String {
|
||||||
if (roomMemberSummary == null) return null
|
|
||||||
val isUnique = roomMemberHelper.isUniqueDisplayName(roomMemberSummary.displayName)
|
val isUnique = roomMemberHelper.isUniqueDisplayName(roomMemberSummary.displayName)
|
||||||
return if (isUnique) {
|
return if (isUnique) {
|
||||||
roomMemberSummary.getBestName()
|
roomMemberSummary.getBestName()
|
||||||
|
|
|
@ -32,23 +32,32 @@ class VectorRoomDisplayNameFallbackProvider(
|
||||||
return if (leftMemberNames.isEmpty()) {
|
return if (leftMemberNames.isEmpty()) {
|
||||||
context.getString(R.string.room_displayname_empty_room)
|
context.getString(R.string.room_displayname_empty_room)
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.room_displayname_empty_room_was, leftMemberNames.joinToString())
|
val was = when (val size = leftMemberNames.size) {
|
||||||
|
1 -> getNameFor1member(leftMemberNames[0])
|
||||||
|
2 -> getNameFor2members(leftMemberNames[0], leftMemberNames[1])
|
||||||
|
3 -> getNameFor3members(leftMemberNames[0], leftMemberNames[1], leftMemberNames[2])
|
||||||
|
4 -> getNameFor4members(leftMemberNames[0], leftMemberNames[1], leftMemberNames[2], leftMemberNames[3])
|
||||||
|
else -> getNameFor4membersAndMore(leftMemberNames[0], leftMemberNames[1], leftMemberNames[2], size - 3)
|
||||||
|
}
|
||||||
|
context.getString(R.string.room_displayname_empty_room_was, was)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNameFor2members(name1: String?, name2: String?): String {
|
override fun getNameFor1member(name: String) = name
|
||||||
|
|
||||||
|
override fun getNameFor2members(name1: String, name2: String): String {
|
||||||
return context.getString(R.string.room_displayname_two_members, name1, name2)
|
return context.getString(R.string.room_displayname_two_members, name1, name2)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNameFor3members(name1: String?, name2: String?, name3: String?): String {
|
override fun getNameFor3members(name1: String, name2: String, name3: String): String {
|
||||||
return context.getString(R.string.room_displayname_3_members, name1, name2, name3)
|
return context.getString(R.string.room_displayname_3_members, name1, name2, name3)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNameFor4members(name1: String?, name2: String?, name3: String?, name4: String?): String {
|
override fun getNameFor4members(name1: String, name2: String, name3: String, name4: String): String {
|
||||||
return context.getString(R.string.room_displayname_4_members, name1, name2, name3, name4)
|
return context.getString(R.string.room_displayname_4_members, name1, name2, name3, name4)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getNameFor4membersAndMore(name1: String?, name2: String?, name3: String?, remainingCount: Int): String {
|
override fun getNameFor4membersAndMore(name1: String, name2: String, name3: String, remainingCount: Int): String {
|
||||||
return context.resources.getQuantityString(
|
return context.resources.getQuantityString(
|
||||||
R.plurals.room_displayname_four_and_more_members,
|
R.plurals.room_displayname_four_and_more_members,
|
||||||
remainingCount,
|
remainingCount,
|
||||||
|
|
Loading…
Reference in New Issue