From 411c8c90961d83a7e5bea10e5c055b6245ee7d92 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 1 Nov 2022 11:21:27 +0100 Subject: [PATCH 1/2] Fix duplicated pills when pills contain other spans Fixes following issues: - Duplicated pills if the mention contains an image: https://github.com/SchildiChat/SchildiChat-android/issues/148 - Duplicated pills if these contain underscores: https://github.com/SchildiChat/SchildiChat-android/issues/156 --- .../vector/app/features/html/PillsPostProcessor.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt b/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt index 85cfb76ff7..f6e10a6df9 100644 --- a/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt +++ b/vector/src/main/java/im/vector/app/features/html/PillsPostProcessor.kt @@ -83,6 +83,20 @@ class PillsPostProcessor @AssistedInject constructor( val pillSpan = linkSpan.createPillSpan(roomId) ?: return@forEach val startSpan = renderedText.getSpanStart(linkSpan) val endSpan = renderedText.getSpanEnd(linkSpan) + // GlideImagesPlugin causes duplicated pills if we have a nested spans in the pill span, + // such as images or italic text. + // Accordingly, it's better to remove all spans that are contained in this span before rendering. + renderedText.getSpans(startSpan, endSpan, Any::class.java).forEach remove@{ + if (it !is LinkSpan) { + // Make sure to only remove spans that are contained in this link, and not are bigger than this link, e.g. like reply-blocks + val start = renderedText.getSpanStart(it) + if (start < startSpan) return@remove + val end = renderedText.getSpanEnd(it) + if (end > endSpan) return@remove + + renderedText.removeSpan(it) + } + } addPillSpan(renderedText, pillSpan, startSpan, endSpan) } } From 99d510773269be972b9b8926b9584816d07a552b Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Tue, 1 Nov 2022 15:49:46 +0100 Subject: [PATCH 2/2] Changelog 7501 --- changelog.d/7501.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7501.bugfix diff --git a/changelog.d/7501.bugfix b/changelog.d/7501.bugfix new file mode 100644 index 0000000000..b86258d427 --- /dev/null +++ b/changelog.d/7501.bugfix @@ -0,0 +1 @@ +Fix duplicated mention pills in some cases