Display name disambiguation #2215.

Applied to:
- timeline message
- detail of timeline message
- reply preview of timeline message
- rendering of state Event
Not applied to:
- room last message
- room member list (we display the MatrixId here)
- room member detail page
This commit is contained in:
Benoit Marty 2024-01-12 15:56:47 +01:00 committed by Benoit Marty
parent f281c6c365
commit 14d5274d22
7 changed files with 101 additions and 5 deletions

View file

@ -17,6 +17,7 @@
package io.element.android.libraries.matrix.api.timeline.item.event
import androidx.compose.runtime.Immutable
import io.element.android.libraries.matrix.api.core.UserId
@Immutable
sealed interface ProfileTimelineDetails {
@ -34,3 +35,20 @@ sealed interface ProfileTimelineDetails {
val message: String
) : ProfileTimelineDetails
}
/**
* Returns a disambiguated display name for the user.
* If the display name is null, or profile is not Ready, the user ID is returned.
* If the display name is ambiguous, the user ID is appended in parentheses.
* Otherwise, the display name is returned.
*/
fun ProfileTimelineDetails.getDisambiguatedDisplayName(userId: UserId): String {
return when (this) {
is ProfileTimelineDetails.Ready -> when {
displayName == null -> userId.value
displayNameAmbiguous -> "$displayName ($userId)"
else -> displayName
}
else -> userId.value
}
}