Merge pull request #3021 from vector-im/feature/bma/filter_some_url_preview

Disable URL preview for some domains (#2995)
This commit is contained in:
Benoit Marty 2021-03-22 15:41:22 +01:00 committed by GitHub
commit a8fedfff53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -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 🗣:
-

View file

@ -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"
)
}
}