Fix html messages not rendering at all on markwon exception

If render(): renderAndProcess(markwon.parse(text), _) fails,
the input text *string* is returned instead of a Spannable,
so we shouldn't cast without checking here.

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

Change-Id: I1824328e0b733de699a33376833b2fbc86b0e44f
This commit is contained in:
SpiritCroc 2023-08-02 20:04:06 +02:00
parent 16ccd7817f
commit ff67571dad
1 changed files with 3 additions and 2 deletions

View File

@ -679,8 +679,9 @@ class MessageItemFactory @Inject constructor(
?: matrixFormattedBody ?: matrixFormattedBody
*/ */
val compressed = htmlCompressor.compress(matrixFormattedBody) val compressed = htmlCompressor.compress(matrixFormattedBody)
val renderedFormattedBody = htmlRenderer.get().render(compressed, pillsPostProcessor) as Spanned val renderedFormattedBody = htmlRenderer.get().render(compressed, pillsPostProcessor) as? Spanned ?: compressed
val pseudoEmojiBody = htmlRenderer.get().render(customToPseudoEmoji(compressed), pillsPostProcessor) as Spanned val pseudoEmojiCompressed = customToPseudoEmoji(compressed)
val pseudoEmojiBody = htmlRenderer.get().render(pseudoEmojiCompressed, pillsPostProcessor) as? Spanned ?: pseudoEmojiCompressed
return buildMessageTextItem( return buildMessageTextItem(
renderedFormattedBody, renderedFormattedBody,
true, true,