Editing: default to MessageContent.body when no formattedBody is present (#7592)

* Editing: default to `MessageContent.body` when no `formattedBody` is present

* Update docs
This commit is contained in:
Jorge Martin Espinosa 2022-11-16 13:13:07 +01:00 committed by GitHub
parent 54fcdcdb6d
commit 10775ab2f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

1
changelog.d/7574.sdk Normal file
View file

@ -0,0 +1 @@
If message content has no `formattedBody`, default to `body` when editing.

View file

@ -180,11 +180,13 @@ fun TimelineEvent.isRootThread(): Boolean {
/**
* Get the latest message body, after a possible edition, stripping the reply prefix if necessary.
* @param formatted Indicates whether the formatted HTML body of the message should be retrieved of the plain text one.
* @return If [formatted] is `true`, the HTML body of the message will be retrieved if available. Otherwise, the plain text/markdown version will be returned.
*/
fun TimelineEvent.getTextEditableContent(formatted: Boolean): String {
val lastMessageContent = getLastMessageContent()
val lastContentBody = if (formatted && lastMessageContent is MessageContentWithFormattedBody) {
lastMessageContent.formattedBody
lastMessageContent.formattedBody ?: lastMessageContent.body
} else {
lastMessageContent?.body
} ?: return ""