mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
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:
commit
a8fedfff53
2 changed files with 13 additions and 1 deletions
|
@ -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 🗣:
|
||||
-
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue