From 15b3b18321211a0d03e90d90362b31ba0683d467 Mon Sep 17 00:00:00 2001 From: ThomasSession Date: Fri, 5 Jul 2024 10:48:51 +1000 Subject: [PATCH] Proper display of unresolved names in mentions (#1530) * Fix issue with span being the full length * Making sure a mention with a username without a resolved name still displayed with the appropriate style with the truncated is --- .../securesms/conversation/v2/utilities/MentionUtilities.kt | 3 ++- .../src/main/java/org/session/libsession/utilities/IdUtil.kt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt index 3edfcffc97..3a4bfd6816 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/MentionUtilities.kt @@ -18,6 +18,7 @@ import org.session.libsession.messaging.utilities.SodiumUtilities import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.ThemeUtil import org.session.libsession.utilities.getColorFromAttr +import org.session.libsession.utilities.truncateIdForDisplay import org.thoughtcrime.securesms.dependencies.DatabaseComponent import org.thoughtcrime.securesms.util.RoundedBackgroundSpan import org.thoughtcrime.securesms.util.getAccentColor @@ -67,7 +68,7 @@ object MentionUtilities { } else { val contact = DatabaseComponent.get(context).sessionContactDatabase().getContactWithSessionID(publicKey) @Suppress("NAME_SHADOWING") val context = if (openGroup != null) Contact.ContactContext.OPEN_GROUP else Contact.ContactContext.REGULAR - contact?.displayName(context) + contact?.displayName(context) ?: truncateIdForDisplay(publicKey) } if (userDisplayName != null) { val mention = "@$userDisplayName" diff --git a/libsession/src/main/java/org/session/libsession/utilities/IdUtil.kt b/libsession/src/main/java/org/session/libsession/utilities/IdUtil.kt index ccaa31c2f9..1902b6e0ab 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/IdUtil.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/IdUtil.kt @@ -1,4 +1,4 @@ package org.session.libsession.utilities fun truncateIdForDisplay(id: String): String = - id.takeIf { it.length > 8 }?.apply{ "${take(4)}…${takeLast(4)}" } ?: id + id.takeIf { it.length > 8 }?.run{ "${take(4)}…${takeLast(4)}" } ?: id