Disable URL preview for some domains (#2995)
This commit is contained in:
parent
43fd9910e3
commit
fa37070884
|
@ -13,6 +13,7 @@ Improvements 🙌:
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- Fix bad theme change for the MainActivity
|
- Fix bad theme change for the MainActivity
|
||||||
- Handle encrypted reactions (#2509)
|
- Handle encrypted reactions (#2509)
|
||||||
|
- Disable URL preview for some domains (#2995)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
|
|
@ -52,7 +52,7 @@ class PreviewUrlRetriever(session: Session,
|
||||||
// The event is not known or it has been edited
|
// The event is not known or it has been edited
|
||||||
// Keep only the first URL for the moment
|
// Keep only the first URL for the moment
|
||||||
val url = mediaService.extractUrls(event)
|
val url = mediaService.extractUrls(event)
|
||||||
.firstOrNull()
|
.firstOrNull { canShowUrlPreview(it) }
|
||||||
?.takeIf { it !in blockedUrl }
|
?.takeIf { it !in blockedUrl }
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
updateState(eventId, latestEventId, PreviewUrlUiState.NoUrl)
|
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) {
|
fun doNotShowPreviewUrlFor(eventId: String, url: String) {
|
||||||
blockedUrl.add(url)
|
blockedUrl.add(url)
|
||||||
|
|
||||||
|
@ -143,5 +147,12 @@ class PreviewUrlRetriever(session: Session,
|
||||||
companion object {
|
companion object {
|
||||||
// One week in millis
|
// One week in millis
|
||||||
private const val CACHE_VALIDITY: Long = 7 * 24 * 3_600 * 1_000
|
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 New Issue