fix: Show diffs for content that doesn't start with a block element (#446)

Content that doesn't start with a block element generates a parse error.
This isn't normally seen from Mastodon servers but is seen from content
from other servers (e.g,. Akkoma), which can generate:

```
<a href="..."> some text
```

instead of:

```
<p><a href="..."> some text</p>
```

Work around this by ensuring that content-to-be-diffed is wrapped in a
`div`.
This commit is contained in:
Nik Clayton 2024-02-15 14:16:50 +01:00 committed by GitHub
parent b8ac1f3944
commit c7895cf2db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,7 +84,15 @@ class ViewEditsViewModel @Inject constructor(private val api: MastodonApi) : Vie
// This can be CPU intensive depending on the number of edits and the size
// of each, so don't run this on Dispatchers.Main.
viewModelScope.launch(Dispatchers.Default) {
val sortedEdits = edits.sortedBy { it.createdAt }
val sortedEdits = edits
// The XMLLoader expects the outermost content to be enclosed
// in block elements. Multiple block elements without a single
// root are ok ("<p>...</p> <p>...</p>"), but content without
// a block element ("<a ...> some text") is not. Guard against
// this be wrapping everything in a div.
// https://github.com/tuskyapp/Tusky/issues/4253
.map { it.copy(content = "<div>${it.content}</div>") }
.sortedBy { it.createdAt }
.reversed()
.toMutableList()