Skip to content

Commit 87ec7a9

Browse files
committed
Replace unnecessary isSanitized boolean with two different enum types
1 parent 00ef7c4 commit 87ec7a9

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

app/src/main/java/com/infomaniak/mail/ui/newMessage/BodyContentPayload.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ package com.infomaniak.mail.ui.newMessage
2121
/**
2222
* @param content The string representation of the body in either html or plain text format.
2323
* @param type The type of representation of [content]. Each type will lead to different processing of the content.
24-
* @param isSanitized Is only required and cannot be omitted when [type] is [BodyContentType.HTML]. This describes whether or not
25-
* the HTML can skip sanitization when we know it's already been sanitized earlier.
2624
*/
27-
data class BodyContentPayload(val content: String, val type: BodyContentType, val isSanitized: Boolean? = null) {
25+
data class BodyContentPayload(val content: String, val type: BodyContentType) {
2826
companion object {
2927
fun emptyBody(): BodyContentPayload {
3028
return BodyContentPayload("", BodyContentType.TEXT_PLAIN_WITHOUT_HTML)
3129
}
3230
}
3331
}
3432

35-
enum class BodyContentType { HTML, TEXT_PLAIN_WITH_HTML, TEXT_PLAIN_WITHOUT_HTML }
33+
enum class BodyContentType { HTML_SANITIZED, HTML_UNSANITIZED, TEXT_PLAIN_WITH_HTML, TEXT_PLAIN_WITHOUT_HTML }

app/src/main/java/com/infomaniak/mail/ui/newMessage/EditorContentManager.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ class EditorContentManager @Inject constructor() {
3030

3131
fun setContent(editor: RichHtmlEditorWebView, bodyContentPayload: BodyContentPayload) = with(editor) {
3232
when (bodyContentPayload.type) {
33-
BodyContentType.HTML -> setHtml(bodyContentPayload.content, bodyContentPayload.isSanitized!!)
33+
BodyContentType.HTML_SANITIZED -> setSanitizedHtml(bodyContentPayload.content)
34+
BodyContentType.HTML_UNSANITIZED -> setUnsanitizedHtml(bodyContentPayload.content)
3435
BodyContentType.TEXT_PLAIN_WITH_HTML -> setPlainTextAndInterpretHtml(bodyContentPayload.content)
3536
BodyContentType.TEXT_PLAIN_WITHOUT_HTML -> setPlainTextAndEscapeHtml(bodyContentPayload.content)
3637
}
3738
}
3839

39-
private fun RichHtmlEditorWebView.setHtml(html: String, isSanitized: Boolean) {
40-
val sanitizedHtml = if (isSanitized) html else html.sanitize()
41-
setSanitizedHtml(sanitizedHtml)
42-
}
40+
private fun RichHtmlEditorWebView.setUnsanitizedHtml(html: String) = setSanitizedHtml(html.sanitize())
4341

4442
private fun RichHtmlEditorWebView.setPlainTextAndInterpretHtml(text: String) {
4543
setSanitizedHtml(text.replaceNewLines().sanitize())

app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageAiManager.kt

+1-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ class NewMessageAiManager @Inject constructor(
9898
fun observeAiOutput() = with(binding) {
9999
aiViewModel.aiOutputToInsert.observe(viewLifecycleOwner) { (subject, content) ->
100100
subject?.let(subjectTextField::setText)
101-
editorContentManager.setContent(
102-
editor,
103-
BodyContentPayload(content, BodyContentType.TEXT_PLAIN_WITH_HTML, isSanitized = false)
104-
)
101+
editorContentManager.setContent(editor, BodyContentPayload(content, BodyContentType.TEXT_PLAIN_WITH_HTML))
105102
}
106103
}
107104

app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageFragment.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class NewMessageFragment : Fragment() {
245245

246246
override fun onDestroyView() {
247247
binding.editor.exportHtml { html ->
248-
newMessageViewModel.editorBodyLoader.postValue(BodyContentPayload(html, BodyContentType.HTML, isSanitized = true))
248+
newMessageViewModel.editorBodyLoader.postValue(BodyContentPayload(html, BodyContentType.HTML_SANITIZED))
249249
}
250250

251251
addressListPopupWindow = null

app/src/main/java/com/infomaniak/mail/ui/newMessage/NewMessageViewModel.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class NewMessageViewModel @Inject constructor(
323323
doc.split(MessageBodyUtils.INFOMANIAK_FORWARD_QUOTE_HTML_CLASS_NAME, bodyWithQuote)
324324
}
325325

326-
return Triple(BodyContentPayload(body, BodyContentType.HTML, isSanitized = false), signature, quote)
326+
return Triple(BodyContentPayload(body, BodyContentType.HTML_UNSANITIZED), signature, quote)
327327
}
328328

329329
private fun populateWithExternalMailDataIfNeeded(draft: Draft, intent: Intent) {

0 commit comments

Comments
 (0)