Hide empty URL previews

Change-Id: I10a2f78e7efa96249adb7cd4849e54150a08001a
This commit is contained in:
SpiritCroc 2020-12-22 14:26:20 +01:00
parent 9e99fcb7ff
commit 12eb1ea68d
2 changed files with 10 additions and 1 deletions

View File

@ -48,4 +48,11 @@ data class PreviewUrlData(
val description: String?, val description: String?,
// Value of field "og:image" // Value of field "og:image"
val mxcUrl: String? val mxcUrl: String?
) ) {
fun isPreviewable(): Boolean {
return siteName?.isNotEmpty() == true ||
title?.isNotEmpty() == true ||
description?.isNotEmpty() == true ||
mxcUrl?.isNotEmpty() == true
}
}

View File

@ -65,6 +65,8 @@ class PreviewUrlRetriever(session: Session) {
// Blocked after the request has been sent? // Blocked after the request has been sent?
if (urlToRetrieve in blockedUrl) { if (urlToRetrieve in blockedUrl) {
updateState(eventId, PreviewUrlUiState.NoUrl) updateState(eventId, PreviewUrlUiState.NoUrl)
} else if (!it.isPreviewable()) { // Nothing to show
updateState(eventId, PreviewUrlUiState.NoUrl)
} else { } else {
updateState(eventId, PreviewUrlUiState.Data(eventId, urlToRetrieve, it)) updateState(eventId, PreviewUrlUiState.Data(eventId, urlToRetrieve, it))
} }