Update notice rendering depending on layout

For SC bubbles: use exact same mechanism as rendering normal text
messages if possible
-> Closes https://github.com/SchildiChat/SchildiChat-android/issues/45

For non-SC-bubbles: use upstream implementation again, so it's possible
to tell apart notices in these as well.

Change-Id: I60c614266d2ae4afdf1e87c649ff484551f961b4
This commit is contained in:
SpiritCroc 2022-05-11 21:29:52 +02:00
parent a96d27cb81
commit 347af40ec0
1 changed files with 33 additions and 27 deletions

View File

@ -71,6 +71,7 @@ import im.vector.app.features.home.room.detail.timeline.item.RedactedMessageItem
import im.vector.app.features.home.room.detail.timeline.item.VerificationRequestItem
import im.vector.app.features.home.room.detail.timeline.item.VerificationRequestItem_
import im.vector.app.features.home.room.detail.timeline.render.EventTextRenderer
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout
import im.vector.app.features.home.room.detail.timeline.tools.createLinkMovementMethod
import im.vector.app.features.home.room.detail.timeline.tools.linkify
import im.vector.app.features.html.EventHtmlRenderer
@ -100,6 +101,7 @@ import org.matrix.android.sdk.api.session.crypto.attachments.toElementToDecrypt
import org.matrix.android.sdk.api.session.events.model.RelationType
import org.matrix.android.sdk.api.session.events.model.content.EncryptedEventContent
import org.matrix.android.sdk.api.session.events.model.isThread
import org.matrix.android.sdk.api.session.events.model.toContent
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.message.MessageAudioContent
import org.matrix.android.sdk.api.session.room.model.message.MessageBeaconInfoContent
@ -122,6 +124,7 @@ import org.matrix.android.sdk.api.session.room.model.message.getThumbnailUrl
import org.matrix.android.sdk.api.session.room.timeline.getLastMessageContent
import org.matrix.android.sdk.api.settings.LightweightSettingsStorage
import org.matrix.android.sdk.api.util.MimeTypes
import timber.log.Timber
import javax.inject.Inject
class MessageItemFactory @Inject constructor(
@ -707,12 +710,13 @@ class MessageItemFactory @Inject constructor(
): VectorEpoxyModel<*>? {
val attributes = attrs.copy(isNotice = true)
// We might want to use the normal text rendering in the future as following (but need to
// ensure that notices are easily told apart also from code, ... formatted messages).
// Maybe, instead of text coloring, we can come up with some other indicator that catches all cases automatically?
/*
val formattedBody: CharSequence
val htmlBody = messageContent.getHtmlBody()
if (attributes.informationData.messageLayout is TimelineMessageLayout.ScBubble) {
// Just use normal text rendering for notices
val noticeAsTextContent = messageContent.toContent().toModel<MessageTextContent>()
if (noticeAsTextContent != null && false) {
if (noticeAsTextContent != null) {
return buildItemForTextContent(
noticeAsTextContent,
informationData,
@ -722,18 +726,20 @@ class MessageItemFactory @Inject constructor(
)
}
Timber.w("Could not parse notice as text item, using legacy fallback")
*/
val htmlBody = messageContent.getHtmlBody()
// SchildiChat likes to not overwrite message formatting for notices, compared to upstream
val formattedBody = htmlBody
/*
val formattedBody = span {
// SchildiChat likes to not overwrite message formatting for notices, as opposed to upstream
formattedBody = htmlBody
} else {
// Upstream impl for non-SC-bubbles
formattedBody = span {
text = htmlBody
textColor = colorProvider.getColorFromAttribute(R.attr.vctr_content_secondary)
textStyle = "italic"
}
*/
}
val bindingOptions = spanUtils.getBindingOptions(htmlBody)
val message = formattedBody.linkify(callback)