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
1 changed files with 2 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageType
import javax.inject.Inject
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()
fun extract(event: Event): List<String> {
@ -35,6 +36,7 @@ internal class UrlsExtractor @Inject constructor() {
?.body
?.let { urlRegex.findAll(it) }
?.map { it.value }
?.filter { it.startsWith("https://") || it.startsWith("http://") }
?.distinct()
?.toList()
.orEmpty()