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)
|
- Duplicate thumbs | Mobile reactions for 👍 and 👎 are not the same as web (#2776)
|
||||||
- Join room by alias other federation error (#2778)
|
- Join room by alias other federation error (#2778)
|
||||||
- HTML unescaping for URL preview (#2766)
|
- HTML unescaping for URL preview (#2766)
|
||||||
|
- URL preview on reply fallback (#2756)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
-
|
-
|
||||||
|
@ -20,7 +20,7 @@ object ContentUtils {
|
|||||||
val lines = repliedBody.lines()
|
val lines = repliedBody.lines()
|
||||||
var wellFormed = repliedBody.startsWith(">")
|
var wellFormed = repliedBody.startsWith(">")
|
||||||
var endOfPreviousFound = false
|
var endOfPreviousFound = false
|
||||||
val usefullines = ArrayList<String>()
|
val usefulLines = ArrayList<String>()
|
||||||
lines.forEach {
|
lines.forEach {
|
||||||
if (it == "") {
|
if (it == "") {
|
||||||
endOfPreviousFound = true
|
endOfPreviousFound = true
|
||||||
@ -29,10 +29,10 @@ object ContentUtils {
|
|||||||
if (!endOfPreviousFound) {
|
if (!endOfPreviousFound) {
|
||||||
wellFormed = wellFormed && it.startsWith(">")
|
wellFormed = wellFormed && it.startsWith(">")
|
||||||
} else {
|
} 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 {
|
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.model.message.MessageType
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
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.session.room.timeline.getLastMessageContent
|
||||||
|
import org.matrix.android.sdk.api.util.ContentUtils
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
internal class UrlsExtractor @Inject constructor() {
|
internal class UrlsExtractor @Inject constructor() {
|
||||||
@ -35,7 +36,14 @@ internal class UrlsExtractor @Inject constructor() {
|
|||||||
|| it.msgType == MessageType.MSGTYPE_NOTICE
|
|| it.msgType == MessageType.MSGTYPE_NOTICE
|
||||||
|| it.msgType == MessageType.MSGTYPE_EMOTE
|
|| 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) }
|
?.let { urlRegex.findAll(it) }
|
||||||
?.map { it.value }
|
?.map { it.value }
|
||||||
?.filter { it.startsWith("https://") || it.startsWith("http://") }
|
?.filter { it.startsWith("https://") || it.startsWith("http://") }
|
||||||
|
Loading…
Reference in New Issue
Block a user