Ensure no invisible displayName will be used

This commit is contained in:
Benoit Marty 2021-02-07 12:00:33 +01:00
parent d47ba6bd11
commit 6ee6b0cad9
3 changed files with 14 additions and 4 deletions

View File

@ -16,6 +16,8 @@
package org.matrix.android.sdk.api.session.room.sender
import org.matrix.android.sdk.internal.util.replaceSpaceChars
data class SenderInfo(
val userId: String,
/**
@ -27,7 +29,8 @@ data class SenderInfo(
) {
val disambiguatedDisplayName: String
get() = when {
displayName.isNullOrBlank() -> userId
displayName == null -> userId
displayName.replaceSpaceChars().isBlank() -> "$displayName ($userId)"
isUniqueDisplayName -> displayName
else -> "$displayName ($userId)"
}

View File

@ -71,3 +71,10 @@ fun String.caseInsensitiveFind(subString: String): Boolean {
return false
}
internal val spaceChars = "[\u00A0\u2000-\u200B\u2800\u3000]".toRegex()
/**
* Strip all the UTF-8 chars which are actually spaces
*/
internal fun String.replaceSpaceChars() = replace(spaceChars, "")

View File

@ -83,7 +83,7 @@ abstract class BaseAttachmentProvider<Type>(
val dateString = dateFormatter.format(timelineEvent.root.originServerTs, DateFormatKind.DEFAULT_DATE_AND_TIME)
overlayView?.updateWith(
counter = stringProvider.getString(R.string.attachment_viewer_item_x_of_y, position + 1, getItemCount()),
senderInfo = "${timelineEvent.senderInfo.displayName} $dateString"
senderInfo = "${timelineEvent.senderInfo.disambiguatedDisplayName} $dateString"
)
overlayView?.views?.overlayVideoControlsGroup?.isVisible = timelineEvent.root.isVideoMessage()
} else {