mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
URL preview on reply fallback (#2756)
This commit is contained in:
parent
ed99b503f5
commit
07220d7a59
@ -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 🗣:
|
||||
-
|
||||
|
@ -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 {
|
||||
|
@ -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://") }
|
||||
|
Loading…
Reference in New Issue
Block a user