Clean code
This commit is contained in:
parent
794b89c041
commit
20c7d80bb1
@ -353,17 +353,23 @@ class MessageItemFactory @Inject constructor(
|
|||||||
codeVisitor.visit(localFormattedBody)
|
codeVisitor.visit(localFormattedBody)
|
||||||
when (codeVisitor.codeKind) {
|
when (codeVisitor.codeKind) {
|
||||||
CodeVisitor.Kind.BLOCK -> {
|
CodeVisitor.Kind.BLOCK -> {
|
||||||
val codeFormattedBlock = htmlRenderer.get().render(localFormattedBody) ?: messageContent.formattedBody!!
|
val codeFormattedBlock = htmlRenderer.get().render(localFormattedBody)
|
||||||
buildCodeBlockItem(codeFormattedBlock, informationData, highlight, callback, attributes)
|
if (codeFormattedBlock == null) {
|
||||||
|
buildFormattedTextItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
|
} else {
|
||||||
|
buildCodeBlockItem(codeFormattedBlock, informationData, highlight, callback, attributes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CodeVisitor.Kind.INLINE -> {
|
CodeVisitor.Kind.INLINE -> {
|
||||||
val codeFormatted = htmlRenderer.get().render(localFormattedBody)?: messageContent.formattedBody!!
|
val codeFormatted = htmlRenderer.get().render(localFormattedBody)
|
||||||
buildMessageTextItem(codeFormatted, false, informationData, highlight, callback, attributes)
|
if (codeFormatted == null) {
|
||||||
|
buildFormattedTextItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
|
} else {
|
||||||
|
buildMessageTextItem(codeFormatted, false, informationData, highlight, callback, attributes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
CodeVisitor.Kind.NONE -> {
|
CodeVisitor.Kind.NONE -> {
|
||||||
val compressed = htmlCompressor.compress(messageContent.formattedBody!!)
|
buildFormattedTextItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
val formattedBody = htmlRenderer.get().render(compressed)
|
|
||||||
buildMessageTextItem(formattedBody, true, informationData, highlight, callback, attributes)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -371,6 +377,16 @@ class MessageItemFactory @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildFormattedTextItem(messageContent: MessageTextContent,
|
||||||
|
informationData: MessageInformationData,
|
||||||
|
highlight: Boolean,
|
||||||
|
callback: TimelineEventController.Callback?,
|
||||||
|
attributes: AbsMessageItem.Attributes): MessageTextItem? {
|
||||||
|
val compressed = htmlCompressor.compress(messageContent.formattedBody!!)
|
||||||
|
val formattedBody = htmlRenderer.get().render(compressed)
|
||||||
|
return buildMessageTextItem(formattedBody, true, informationData, highlight, callback, attributes)
|
||||||
|
}
|
||||||
|
|
||||||
private fun buildMessageTextItem(body: CharSequence,
|
private fun buildMessageTextItem(body: CharSequence,
|
||||||
isFormatted: Boolean,
|
isFormatted: Boolean,
|
||||||
informationData: MessageInformationData,
|
informationData: MessageInformationData,
|
||||||
|
@ -44,7 +44,7 @@ class EventHtmlRenderer @Inject constructor(context: Context,
|
|||||||
fun render(text: String): CharSequence {
|
fun render(text: String): CharSequence {
|
||||||
return try {
|
return try {
|
||||||
markwon.toMarkdown(text)
|
markwon.toMarkdown(text)
|
||||||
}catch (failure: Throwable){
|
} catch (failure: Throwable) {
|
||||||
Timber.v("Fail to render $text to html")
|
Timber.v("Fail to render $text to html")
|
||||||
text
|
text
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ class EventHtmlRenderer @Inject constructor(context: Context,
|
|||||||
fun render(node: Node): CharSequence? {
|
fun render(node: Node): CharSequence? {
|
||||||
return try {
|
return try {
|
||||||
markwon.render(node)
|
markwon.render(node)
|
||||||
}catch (failure: Throwable){
|
} catch (failure: Throwable) {
|
||||||
Timber.v("Fail to render $node to html")
|
Timber.v("Fail to render $node to html")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user