URL preview on reply fallback (#2756)

This commit is contained in:
Benoit Marty 2021-02-07 15:21:07 +01:00 committed by Benoit Marty
parent ed99b503f5
commit 07220d7a59
3 changed files with 13 additions and 4 deletions

View File

@ -11,6 +11,7 @@ Bugfix 🐛:
- Duplicate thumbs | Mobile reactions for 👍 and 👎 are not the same as web (#2776)
- Join room by alias other federation error (#2778)
- HTML unescaping for URL preview (#2766)
- URL preview on reply fallback (#2756)
Translations 🗣:
-

View File

@ -20,7 +20,7 @@ object ContentUtils {
val lines = repliedBody.lines()
var wellFormed = repliedBody.startsWith(">")
var endOfPreviousFound = false
val usefullines = ArrayList<String>()
val usefulLines = ArrayList<String>()
lines.forEach {
if (it == "") {
endOfPreviousFound = true
@ -29,10 +29,10 @@ object ContentUtils {
if (!endOfPreviousFound) {
wellFormed = wellFormed && it.startsWith(">")
} else {
usefullines.add(it)
usefulLines.add(it)
}
}
return usefullines.joinToString("\n").takeIf { wellFormed } ?: repliedBody
return usefulLines.joinToString("\n").takeIf { wellFormed } ?: repliedBody
}
fun extractUsefulTextFromHtmlReply(repliedBody: String): String {

View File

@ -21,6 +21,7 @@ import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
import org.matrix.android.sdk.api.util.ContentUtils
import javax.inject.Inject
internal class UrlsExtractor @Inject constructor() {
@ -35,7 +36,14 @@ internal class UrlsExtractor @Inject constructor() {
|| it.msgType == MessageType.MSGTYPE_NOTICE
|| it.msgType == MessageType.MSGTYPE_EMOTE
}
?.body
?.let { messageContent ->
if (messageContent.relatesTo?.inReplyTo?.eventId != null) {
// This is a reply, strip the reply fallback
ContentUtils.extractUsefulTextFromReply(messageContent.body)
} else {
messageContent.body
}
}
?.let { urlRegex.findAll(it) }
?.map { it.value }
?.filter { it.startsWith("https://") || it.startsWith("http://") }