From 15c51cad1788ca3939d98f87dc9db9ff284c6188 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 7 Apr 2021 15:17:02 +0200 Subject: [PATCH 1/3] Improve interface, name are not nullable --- .../sdk/common/TestRoomDisplayNameFallbackProvider.kt | 8 ++++---- .../android/sdk/api/RoomDisplayNameFallbackProvider.kt | 8 ++++---- .../session/room/membership/RoomDisplayNameResolver.kt | 5 ++--- .../room/VectorRoomDisplayNameFallbackProvider.kt | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt index c98bca42b9..3f440a7d7b 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt @@ -26,15 +26,15 @@ class TestRoomDisplayNameFallbackProvider : RoomDisplayNameFallbackProvider { override fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List) = "Empty room" - override fun getNameFor2members(name1: String?, name2: String?) = + override fun getNameFor2members(name1: String, name2: String) = "$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" - 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" - 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" } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt index b16d29c997..6028bc837d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt @@ -19,8 +19,8 @@ package org.matrix.android.sdk.api interface RoomDisplayNameFallbackProvider { fun getNameForRoomInvite(): String fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List): String - fun getNameFor2members(name1: String?, name2: String?): String - fun getNameFor3members(name1: String?, name2: String?, name3: String?): String - fun getNameFor4members(name1: String?, name2: String?, name3: String?, name4: String?): String - fun getNameFor4membersAndMore(name1: String?, name2: String?, name3: String?, remainingCount: Int): String + fun getNameFor2members(name1: String, name2: String): String + fun getNameFor3members(name1: String, name2: String, name3: String): String + fun getNameFor4members(name1: String, name2: String, name3: String, name4: String): String + fun getNameFor4membersAndMore(name1: String, name2: String, name3: String, remainingCount: Int): String } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt index 194134f45d..219ef694a4 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt @@ -149,9 +149,8 @@ internal class RoomDisplayNameResolver @Inject constructor( } /** See [org.matrix.android.sdk.api.session.room.sender.SenderInfo.disambiguatedDisplayName] */ - private fun resolveRoomMemberName(roomMemberSummary: RoomMemberSummaryEntity?, - roomMemberHelper: RoomMemberHelper): String? { - if (roomMemberSummary == null) return null + private fun resolveRoomMemberName(roomMemberSummary: RoomMemberSummaryEntity, + roomMemberHelper: RoomMemberHelper): String { val isUnique = roomMemberHelper.isUniqueDisplayName(roomMemberSummary.displayName) return if (isUnique) { roomMemberSummary.getBestName() diff --git a/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt b/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt index fe1d4e0f2f..57257dd597 100644 --- a/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt +++ b/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt @@ -36,19 +36,19 @@ class VectorRoomDisplayNameFallbackProvider( } } - override fun getNameFor2members(name1: String?, name2: String?): String { + override fun getNameFor2members(name1: String, name2: String): String { 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) } - 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) } - 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( R.plurals.room_displayname_four_and_more_members, remainingCount, From 923715aeb313edfdd075640a593a87b4853e8584 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 7 Apr 2021 15:19:33 +0200 Subject: [PATCH 2/3] Add method for name fallback when there is only one member --- .../sdk/common/TestRoomDisplayNameFallbackProvider.kt | 3 +++ .../android/sdk/api/RoomDisplayNameFallbackProvider.kt | 1 + .../session/room/membership/RoomDisplayNameResolver.kt | 6 +++++- .../features/room/VectorRoomDisplayNameFallbackProvider.kt | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt index 3f440a7d7b..af2d57f9ce 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/common/TestRoomDisplayNameFallbackProvider.kt @@ -26,6 +26,9 @@ class TestRoomDisplayNameFallbackProvider : RoomDisplayNameFallbackProvider { override fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List) = "Empty room" + override fun getNameFor1member(name: String) = + name + override fun getNameFor2members(name1: String, name2: String) = "$name1 and $name2" diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt index 6028bc837d..a34dbcc196 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/RoomDisplayNameFallbackProvider.kt @@ -19,6 +19,7 @@ package org.matrix.android.sdk.api interface RoomDisplayNameFallbackProvider { fun getNameForRoomInvite(): String fun getNameForEmptyRoom(isDirect: Boolean, leftMemberNames: List): String + fun getNameFor1member(name: String): String fun getNameFor2members(name1: String, name2: String): String fun getNameFor3members(name1: String, name2: String, name3: String): String fun getNameFor4members(name1: String, name2: String, name3: String, name4: String): String diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt index 219ef694a4..3aa812d93d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/membership/RoomDisplayNameResolver.kt @@ -112,7 +112,11 @@ internal class RoomDisplayNameResolver @Inject constructor( .map { it.getBestName() } roomDisplayNameFallbackProvider.getNameForEmptyRoom(roomSummary?.isDirect.orFalse(), leftMembersNames) } - 1 -> resolveRoomMemberName(otherMembersSubset[0], roomMembers) + 1 -> { + roomDisplayNameFallbackProvider.getNameFor1member( + resolveRoomMemberName(otherMembersSubset[0], roomMembers) + ) + } 2 -> { roomDisplayNameFallbackProvider.getNameFor2members( resolveRoomMemberName(otherMembersSubset[0], roomMembers), diff --git a/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt b/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt index 57257dd597..a5f1ff58d6 100644 --- a/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt +++ b/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt @@ -36,6 +36,8 @@ class VectorRoomDisplayNameFallbackProvider( } } + 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) } From e811c53c44d9b108e0a062c3498b952677a79427 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 7 Apr 2021 15:24:00 +0200 Subject: [PATCH 3/3] Improve "was" fallback for Empty rooms. --- .../room/VectorRoomDisplayNameFallbackProvider.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt b/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt index a5f1ff58d6..33e63434ce 100644 --- a/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt +++ b/vector/src/main/java/im/vector/app/features/room/VectorRoomDisplayNameFallbackProvider.kt @@ -32,7 +32,14 @@ class VectorRoomDisplayNameFallbackProvider( return if (leftMemberNames.isEmpty()) { context.getString(R.string.room_displayname_empty_room) } 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) } }