Disable URL preview for some domains (#2995)

This commit is contained in:
Benoit Marty 2021-03-17 17:05:32 +01:00 committed by Benoit Marty
parent 43fd9910e3
commit fa37070884
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"
)
}
}