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) {
is EmoteMessageType -> TimelineItemEmoteContent(
body = "* $senderDisplayName ${messageType.body}",
htmlDocument = messageType.formatted?.toHtmlDocument(senderDisplayName),
htmlDocument = messageType.formatted?.toHtmlDocument(prefix = "* senderDisplayName"),
isEdited = content.isEdited,
)
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.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 ->
if (senderDisplayNamePrefix != null) {
Jsoup.parse("* $senderDisplayNamePrefix $formattedBody")
if (prefix != null) {
Jsoup.parse("$prefix $formattedBody")
} else {
Jsoup.parse(formattedBody)
}