Skip to content

Commit

Permalink
Merge pull request #8847 from element-hq/fix/jme/send-mentions-using-…
Browse files Browse the repository at this point in the history
…user-id-as-text

When sending user mentions, always send the user id as the fallback text
  • Loading branch information
jmartinesp authored Jun 21, 2024
2 parents 097d392 + f8345ab commit 4d27c84
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -56,12 +53,6 @@ class MarkdownParserTest : InstrumentedTest {
HtmlRenderer.builder().softbreak("<br />").build(),
TextPillsUtils(
MentionLinkSpecComparator(),
DisplayNameResolver(
MatrixConfiguration(
applicationFlavor = "TestFlavor",
roomDisplayNameFallbackProvider = TestRoomDisplayNameFallbackProvider()
)
),
TestPermalinkService()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
) {

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,14 +796,14 @@ class MessageComposerFragment : VectorBaseFragment<FragmentComposerBinding>(), 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(
Expand Down

0 comments on commit 4d27c84

Please sign in to comment.