Fix rendering pills when markdown nests some spans inside

Fixes https://github.com/SchildiChat/SchildiChat-android/issues/156

Also improves the fix for https://github.com/SchildiChat/SchildiChat-android/issues/148,
since pills are rendered again and the content is discarded, as per
https://spec.matrix.org/v1.3/client-server-api/#user-and-room-mentions :
"Clients should display mentions differently from other elements"

Change-Id: I9d05fba4110737aacdd9939480b6f78d23bd4298
This commit is contained in:
SpiritCroc 2022-10-21 09:33:02 +02:00
parent b531fb523c
commit 23a96329d6

View file

@ -85,9 +85,12 @@ class PillsPostProcessor @AssistedInject constructor(
val startSpan = renderedText.getSpanStart(linkSpan)
val endSpan = renderedText.getSpanEnd(linkSpan)
// GlideImagesPlugin causes duplicated pills if we have a nested image: https://github.com/SchildiChat/SchildiChat-android/issues/148
// -> do not add pills if we have a nested image
if (renderedText.getSpans(startSpan, endSpan, AsyncDrawableSpan::class.java).isNotEmpty()) {
return@forEach
// Same can happen for other spans: https://github.com/SchildiChat/SchildiChat-android/issues/156
// -> Remove all spans from pill content before rendering
renderedText.getSpans(startSpan, endSpan, Any::class.java).forEach {
if (it !is LinkSpan) {
renderedText.removeSpan(it)
}
}
addPillSpan(renderedText, pillSpan, startSpan, endSpan)
}