From f0e791001fa5b4120692bf8be36e27896bba4569 Mon Sep 17 00:00:00 2001 From: hayaksi1 <193020925+hayaksi1@users.noreply.github.com> Date: Sun, 9 Aug 2026 15:39:18 +0300 Subject: [PATCH] Drop the comments from the matrix URI pillification Review feedback: the regex name and the test names carry the meaning. --- .../messages/impl/utils/TextPillificationHelper.kt | 13 ------------- .../utils/DefaultTextPillificationHelperTest.kt | 1 - 2 files changed, 14 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/TextPillificationHelper.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/TextPillificationHelper.kt index dbdba43340..9faf42d3fd 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/TextPillificationHelper.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/TextPillificationHelper.kt @@ -28,9 +28,6 @@ import io.element.android.libraries.textcomposer.mentions.getMentionSpans import io.element.android.wysiwyg.view.spans.CodeBlockSpan import io.element.android.wysiwyg.view.spans.InlineCodeSpan -/** - * Matches a `matrix:` URI as defined by MSC2312, stopping before any trailing sentence punctuation. - */ private val MATRIX_URI_REGEX = Regex("""matrix:(?:u|user|r|room|roomid|e|event)/\S*[^\s.,;:!?)]""", RegexOption.IGNORE_CASE) interface TextPillificationHelper { @@ -92,8 +89,6 @@ class DefaultTextPillificationHelper( } private fun pillifyPermalinks(text: SpannableStringBuilder) { - // Before the web pass: Patterns.WEB_URL matches the bare domain inside a matrix: URI, and - // whichever pass runs first wins the range. pillifyMatrixUris(text) for (match in Patterns.WEB_URL.toRegex().findAll(text)) { val start = match.range.first @@ -107,11 +102,6 @@ class DefaultTextPillificationHelper( } } - /** - * `Patterns.WEB_URL` cannot match a `matrix:` URI, so those permalinks were left as plain text - * even though the parser understands them. See - * https://github.com/element-hq/element-x-android/issues/5319 - */ private fun pillifyMatrixUris(text: SpannableStringBuilder) { for (match in MATRIX_URI_REGEX.findAll(text)) { val start = match.range.first @@ -120,9 +110,6 @@ class DefaultTextPillificationHelper( val mentionSpan = mentionSpanProvider.getMentionSpanFor(match.value, match.value) if (mentionSpan != null) { text.setSpan(mentionSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) - // A `matrix:` URI gets no URLSpan from linkification, and the timeline only reports - // URLSpans as clicks, so the pill would otherwise be inert. Adding it here also makes - // LinkifyHelper drop the bogus web link it would otherwise find inside the URI. if (text.getSpans(start, end).isEmpty()) { text.setSpan(URLSpan(match.value), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) } diff --git a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/utils/DefaultTextPillificationHelperTest.kt b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/utils/DefaultTextPillificationHelperTest.kt index ae9f5f5715..2590c9fc5c 100644 --- a/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/utils/DefaultTextPillificationHelperTest.kt +++ b/features/messages/impl/src/test/kotlin/io/element/android/features/messages/impl/utils/DefaultTextPillificationHelperTest.kt @@ -50,7 +50,6 @@ class DefaultTextPillificationHelperTest : RobolectricTest() { val spanned = pillified as Spanned assertThat(spanned.getSpanStart(mentionSpans.first())).isEqualTo(text.indexOf("matrix:")) assertThat(spanned.getSpanEnd(mentionSpans.first())).isEqualTo(text.length) - // Without a URLSpan the pill would not be clickable in the timeline. val urlSpans = spanned.getSpans(0, spanned.length) assertThat(urlSpans).hasLength(1) assertThat(urlSpans.first().url).isEqualTo("matrix:u/someone:example.com")