PreviewUrl: protocol is mandatory (exclude rstp://)

This commit is contained in:
Benoit Marty 2020-12-04 08:31:14 +01:00
parent fa7b0a24a7
commit 1161dcb299

View file

@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageType
import javax.inject.Inject import javax.inject.Inject
internal class UrlsExtractor @Inject constructor() { internal class UrlsExtractor @Inject constructor() {
// Sadly Patterns.WEB_URL_WITH_PROTOCOL is not public so filter the protocol later
private val urlRegex = Patterns.WEB_URL.toRegex() private val urlRegex = Patterns.WEB_URL.toRegex()
fun extract(event: Event): List<String> { fun extract(event: Event): List<String> {
@ -35,6 +36,7 @@ internal class UrlsExtractor @Inject constructor() {
?.body ?.body
?.let { urlRegex.findAll(it) } ?.let { urlRegex.findAll(it) }
?.map { it.value } ?.map { it.value }
?.filter { it.startsWith("https://") || it.startsWith("http://") }
?.distinct() ?.distinct()
?.toList() ?.toList()
.orEmpty() .orEmpty()