Code review: improve API.

This commit is contained in:
Benoit Marty 2023-10-05 15:28:38 +02:00
parent 0610306f9a
commit 3559b2ed4b
2 changed files with 4 additions and 4 deletions

View file

@ -52,7 +52,7 @@ class TimelineItemContentMessageFactory @Inject constructor(
return when (val messageType = content.type ?: UnknownMessageType) { return when (val messageType = content.type ?: UnknownMessageType) {
is EmoteMessageType -> TimelineItemEmoteContent( is EmoteMessageType -> TimelineItemEmoteContent(
body = "* $senderDisplayName ${messageType.body}", body = "* $senderDisplayName ${messageType.body}",
htmlDocument = messageType.formatted?.toHtmlDocument(senderDisplayName), htmlDocument = messageType.formatted?.toHtmlDocument(prefix = "* senderDisplayName"),
isEdited = content.isEdited, isEdited = content.isEdited,
) )
is ImageMessageType -> { is ImageMessageType -> {

View file

@ -21,10 +21,10 @@ import io.element.android.libraries.matrix.api.timeline.item.event.MessageFormat
import org.jsoup.Jsoup import org.jsoup.Jsoup
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
fun FormattedBody.toHtmlDocument(senderDisplayNamePrefix: String? = null): Document? { fun FormattedBody.toHtmlDocument(prefix: String? = null): Document? {
return takeIf { it.format == MessageFormat.HTML }?.body?.let { formattedBody -> return takeIf { it.format == MessageFormat.HTML }?.body?.let { formattedBody ->
if (senderDisplayNamePrefix != null) { if (prefix != null) {
Jsoup.parse("* $senderDisplayNamePrefix $formattedBody") Jsoup.parse("$prefix $formattedBody")
} else { } else {
Jsoup.parse(formattedBody) Jsoup.parse(formattedBody)
} }