From 9fcf7263b567ae9b7489d33bbb5e021c2087789e Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sat, 19 Dec 2020 19:51:56 +0100 Subject: [PATCH] Properly hide preview URLs for messages that don't support previews Notices and formatted messages don't have imageContentRenderer and previewUrlRetriever set. Accordingly, when recycling messages that previously had an URL preview, we do not want to keep that preview, but actually hide it, instead of returning early (without rendering any update). --- CHANGES.md | 2 +- .../room/detail/timeline/item/MessageTextItem.kt | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0fb7d72c13..f5ee541793 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ Improvements 🙌: - Bugfix 🐛: - - + - Url previews sometimes attached to wrong message (#2561) Translations 🗣: - diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt index 66d9808d2b..659a3d5460 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt @@ -19,6 +19,7 @@ package im.vector.app.features.home.room.detail.timeline.item import android.text.method.MovementMethod import androidx.appcompat.widget.AppCompatTextView import androidx.core.text.PrecomputedTextCompat +import androidx.core.view.isVisible import androidx.core.widget.TextViewCompat import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass @@ -60,7 +61,12 @@ abstract class MessageTextItem : AbsMessageItem() { // Preview URL previewUrlViewUpdater.previewUrlView = holder.previewUrlView previewUrlViewUpdater.imageContentRenderer = imageContentRenderer - previewUrlRetriever?.addListener(attributes.informationData.eventId, previewUrlViewUpdater) + val safePreviewUrlRetriever = previewUrlRetriever + if (safePreviewUrlRetriever == null) { + holder.previewUrlView.isVisible = false + } else { + safePreviewUrlRetriever.addListener(attributes.informationData.eventId, previewUrlViewUpdater) + } holder.previewUrlView.delegate = previewUrlCallback if (useBigFont) { @@ -106,7 +112,11 @@ abstract class MessageTextItem : AbsMessageItem() { var imageContentRenderer: ImageContentRenderer? = null override fun onStateUpdated(state: PreviewUrlUiState) { - val safeImageContentRenderer = imageContentRenderer ?: return + val safeImageContentRenderer = imageContentRenderer + if (safeImageContentRenderer == null) { + previewUrlView?.isVisible = false + return + } previewUrlView?.render(state, safeImageContentRenderer) } }