From f8345ab9efdd59f125b6b17444bc0f0c8cc05944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADn?= Date: Wed, 19 Jun 2024 16:56:47 +0200 Subject: [PATCH] When sending user mentions, always send the user id as the fallback text --- .../sdk/internal/session/room/send/MarkdownParserTest.kt | 9 --------- .../internal/session/room/send/pills/TextPillsUtils.kt | 4 +--- .../app/features/home/room/detail/AutoCompleter.kt | 4 ++-- .../home/room/detail/composer/MessageComposerFragment.kt | 4 ++-- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt index 0560cfec95..7fe8a75dc9 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/session/room/send/MarkdownParserTest.kt @@ -26,10 +26,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.MethodSorters import org.matrix.android.sdk.InstrumentedTest -import org.matrix.android.sdk.api.MatrixConfiguration import org.matrix.android.sdk.api.util.TextContent -import org.matrix.android.sdk.common.TestRoomDisplayNameFallbackProvider -import org.matrix.android.sdk.internal.session.displayname.DisplayNameResolver import org.matrix.android.sdk.internal.session.room.send.pills.MentionLinkSpecComparator import org.matrix.android.sdk.internal.session.room.send.pills.TextPillsUtils @@ -56,12 +53,6 @@ class MarkdownParserTest : InstrumentedTest { HtmlRenderer.builder().softbreak("
").build(), TextPillsUtils( MentionLinkSpecComparator(), - DisplayNameResolver( - MatrixConfiguration( - applicationFlavor = "TestFlavor", - roomDisplayNameFallbackProvider = TestRoomDisplayNameFallbackProvider() - ) - ), TestPermalinkService() ) ) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/pills/TextPillsUtils.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/pills/TextPillsUtils.kt index 38bddae951..4ac0b4d674 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/pills/TextPillsUtils.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/pills/TextPillsUtils.kt @@ -19,7 +19,6 @@ import android.text.SpannableString import org.matrix.android.sdk.api.session.permalinks.PermalinkService import org.matrix.android.sdk.api.session.room.send.MatrixItemSpan import org.matrix.android.sdk.api.util.MatrixItem -import org.matrix.android.sdk.internal.session.displayname.DisplayNameResolver import java.util.Collections import javax.inject.Inject @@ -29,7 +28,6 @@ import javax.inject.Inject */ internal class TextPillsUtils @Inject constructor( private val mentionLinkSpecComparator: MentionLinkSpecComparator, - private val displayNameResolver: DisplayNameResolver, private val permalinkService: PermalinkService ) { @@ -70,7 +68,7 @@ internal class TextPillsUtils @Inject constructor( // append text before pill append(text, currIndex, start) // append the pill - append(String.format(template, urlSpan.matrixItem.id, displayNameResolver.getBestName(urlSpan.matrixItem))) + append(String.format(template, urlSpan.matrixItem.id, urlSpan.matrixItem.id)) currIndex = end } // append text after the last pill diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt index daf401efc3..e78ce0d551 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/AutoCompleter.kt @@ -246,10 +246,10 @@ class AutoCompleter @AssistedInject constructor( val linkText = when (matrixItem) { is MatrixItem.RoomAliasItem, is MatrixItem.RoomItem, - is MatrixItem.SpaceItem -> + is MatrixItem.SpaceItem, + is MatrixItem.UserItem -> matrixItem.id is MatrixItem.EveryoneInRoomItem, - is MatrixItem.UserItem, is MatrixItem.EventItem -> matrixItem.getBestName() } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt index 038f009d22..53770aada9 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/MessageComposerFragment.kt @@ -796,14 +796,14 @@ class MessageComposerFragment : VectorBaseFragment(), A composer.editText.setSelection(Command.EMOTE.command.length + 1) } else { val roomMember = timelineViewModel.getMember(userId) - val displayName = sanitizeDisplayName(roomMember?.displayName ?: userId) if ((composer as? RichTextComposerLayout)?.isTextFormattingEnabled == true) { // Rich text editor is enabled so we need to use its APIs permalinkService.createPermalink(userId)?.let { url -> - (composer as RichTextComposerLayout).insertMention(url, displayName) + (composer as RichTextComposerLayout).insertMention(url, userId) composer.editText.append(" ") } } else { + val displayName = sanitizeDisplayName(roomMember?.displayName ?: userId) val pill = buildSpannedString { append(displayName) setSpan(