Render formatted_body for m.notice and m.emote (Fixes #1196)

This commit is contained in:
Benoit Marty 2020-05-21 01:47:17 +02:00
parent b75b299847
commit 330a33a0e8
3 changed files with 24 additions and 13 deletions

View File

@ -8,6 +8,7 @@ Features ✨:
Improvements 🙌:
- Better connectivity lost indicator when airplane mode is on
- Add a setting to hide redacted events (#951)
- Render formatted_body for m.notice and m.emote (#1196)
Bugfix 🐛:
- After jump to unread, newer messages are never loaded (#1008)

View File

@ -28,8 +28,8 @@ interface MessageContentWithFormattedBody : MessageContent {
val formattedBody: String?
/**
* Get the formattedBody, only if the format is equal to "org.matrix.custom.html"
* Get the formattedBody, only if not blank and if the format is equal to "org.matrix.custom.html"
*/
val matrixFormattedBody: String?
get() = formattedBody?.takeIf { format == MessageFormat.FORMAT_MATRIX_HTML }
get() = formattedBody?.takeIf { it.isNotBlank() && format == MessageFormat.FORMAT_MATRIX_HTML }
}

View File

@ -29,6 +29,7 @@ import im.vector.matrix.android.api.session.events.model.RelationType
import im.vector.matrix.android.api.session.events.model.toModel
import im.vector.matrix.android.api.session.room.model.message.MessageAudioContent
import im.vector.matrix.android.api.session.room.model.message.MessageContent
import im.vector.matrix.android.api.session.room.model.message.MessageContentWithFormattedBody
import im.vector.matrix.android.api.session.room.model.message.MessageEmoteContent
import im.vector.matrix.android.api.session.room.model.message.MessageFileContent
import im.vector.matrix.android.api.session.room.model.message.MessageImageInfoContent
@ -462,14 +463,14 @@ class MessageItemFactory @Inject constructor(
highlight: Boolean,
callback: TimelineEventController.Callback?,
attributes: AbsMessageItem.Attributes): MessageTextItem? {
val message = messageContent.body.let {
val formattedBody = span {
text = it
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
textStyle = "italic"
}
formattedBody.linkify(callback)
val formattedBody = span {
text = messageContent.getHtmlBody()
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
textStyle = "italic"
}
val message = formattedBody.linkify(callback)
return MessageTextItem_()
.leftGuideline(avatarSizeProvider.leftGuideline)
.attributes(attributes)
@ -483,10 +484,12 @@ class MessageItemFactory @Inject constructor(
highlight: Boolean,
callback: TimelineEventController.Callback?,
attributes: AbsMessageItem.Attributes): MessageTextItem? {
val message = messageContent.body.let {
val formattedBody = "* ${informationData.memberName} $it"
formattedBody.linkify(callback)
}
val formattedBody = SpannableStringBuilder()
formattedBody.append("* ${informationData.memberName} ")
formattedBody.append(messageContent.getHtmlBody())
val message = formattedBody.linkify(callback)
return MessageTextItem_()
.apply {
if (informationData.hasBeenEdited) {
@ -502,6 +505,13 @@ class MessageItemFactory @Inject constructor(
.movementMethod(createLinkMovementMethod(callback))
}
private fun MessageContentWithFormattedBody.getHtmlBody(): CharSequence {
return matrixFormattedBody
?.let { htmlCompressor.compress(it) }
?.let { htmlRenderer.get().render(it) }
?: body
}
private fun buildRedactedItem(attributes: AbsMessageItem.Attributes,
highlight: Boolean): RedactedMessageItem? {
return RedactedMessageItem_()