diff --git a/CHANGES.md b/CHANGES.md index d2ba5babec..55c7387379 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Improvements 🙌: Bugfix 🐛: - Fix bad theme change for the MainActivity - Handle encrypted reactions (#2509) + - Disable URL preview for some domains (#2995) Translations 🗣: - diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlRetriever.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlRetriever.kt index df75c0094b..4c018c8a99 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlRetriever.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/url/PreviewUrlRetriever.kt @@ -52,7 +52,7 @@ class PreviewUrlRetriever(session: Session, // The event is not known or it has been edited // Keep only the first URL for the moment val url = mediaService.extractUrls(event) - .firstOrNull() + .firstOrNull { canShowUrlPreview(it) } ?.takeIf { it !in blockedUrl } if (url == null) { updateState(eventId, latestEventId, PreviewUrlUiState.NoUrl) @@ -98,6 +98,10 @@ class PreviewUrlRetriever(session: Session, } } + private fun canShowUrlPreview(url: String): Boolean { + return blockedDomains.all { !url.startsWith(it) } + } + fun doNotShowPreviewUrlFor(eventId: String, url: String) { blockedUrl.add(url) @@ -143,5 +147,12 @@ class PreviewUrlRetriever(session: Session, companion object { // One week in millis private const val CACHE_VALIDITY: Long = 7 * 24 * 3_600 * 1_000 + + private val blockedDomains = listOf( + "https://matrix.to", + "https://app.element.io", + "https://staging.element.io", + "https://develop.element.io" + ) } }