Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

[Android] Handle and track more internal exceptions #846

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ internal class EditorViewModel(

val update = runCatching {
composer?.select(newStart, newEnd)
}
.onFailure(::onComposerFailure)
.getOrNull()
}.onFailure(
::onComposerFailure
).getOrNull()

handleComposerUpdates(update)

Expand Down Expand Up @@ -160,32 +160,51 @@ internal class EditorViewModel(
}
}

fun getContentAsMessageHtml(): String {
return composer?.getContentAsMessageHtml().orEmpty()
}
fun getContentAsMessageHtml(): String =
runCatching {
composer?.getContentAsMessageHtml().orEmpty()
}.onFailure {
rustErrorCollector?.onRustError(it)
}.getOrElse {
recoveryContentPlainText
}

fun getMarkdown(): String =
fun getMarkdown(): String = runCatching {
composer?.getContentAsMarkdown().orEmpty()
}.onFailure(
::onComposerFailure
).getOrElse {
recoveryContentPlainText
}

fun getCurrentFormattedText(): CharSequence {
return stringToSpans(getContentAsMessageHtml())
return stringToSpans(getInternalHtml())
}

/**
* Get the Rust model's internal representation of it's content.
*
* Note that this should not be used for messages; instead [getContentAsMessageHtml] should be used.
*/
fun getInternalHtml(): String {
return composer?.getContentAsHtml().orEmpty()
fun getInternalHtml(): String = runCatching {
composer?.getContentAsHtml().orEmpty()
}.onFailure(
::onComposerFailure
).getOrElse {
recoveryContentPlainText
}

fun actionStates(): Map<ComposerAction, ActionState>? {
return composer?.actionStates()
}
fun actionStates(): Map<ComposerAction, ActionState>? = runCatching {
composer?.actionStates()
}.onFailure(
::onComposerFailure
).getOrNull()

fun getLinkAction(): LinkAction? =
fun getLinkAction(): LinkAction? = runCatching {
composer?.getLinkAction()?.toApiModel()
}.onFailure(
::onComposerFailure
).getOrNull()

fun rerender(): CharSequence =
stringToSpans(getInternalHtml())
Expand Down Expand Up @@ -218,23 +237,31 @@ internal class EditorViewModel(
?.suggestionPattern
?: return null

return composer?.insertMentionAtSuggestion(
url = url,
text = text,
suggestion = suggestion,
attributes = emptyList()
)
return runCatching {
composer?.insertMentionAtSuggestion(
url = url,
text = text,
suggestion = suggestion,
attributes = emptyList()
)
}.onFailure(
::onComposerFailure
).getOrNull()
}

private fun replaceTextSuggestion(action: EditorInputAction.ReplaceTextSuggestion): ComposerUpdate? {
val suggestion = (curMenuAction as? MenuAction.Suggestion)
?.suggestionPattern
?: return null

return composer?.replaceTextSuggestion(
suggestion = suggestion,
newText = action.value,
)
return runCatching {
composer?.replaceTextSuggestion(
suggestion = suggestion,
newText = action.value,
)
}.onFailure(
::onComposerFailure
).getOrNull()
}

@VisibleForTesting
Expand Down
Loading