fix: Parse roles without a `highlighted` property (#467)

The `highlighted` property on a role may be absent. If it is this breaks
account parsing, including accounts in an /api/v2/instance response.
This, in turn, breaks determining server capabilities, including whether
or not translation is supported.

Set the default to `true`, which matches observed Mastodon behaviour.
This commit is contained in:
Nik Clayton 2024-02-22 21:17:34 +01:00 committed by GitHub
parent 415b182405
commit 51c64a74dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -108,7 +108,8 @@ class ServerRepository @Inject constructor(
mastodonApi.getInstanceV2().fold(
{ Server.from(nodeInfo.software, it).mapError(::Capabilities) },
{
{ throwable ->
Timber.e(throwable, "Couldn't process /api/v2/instance result")
mastodonApi.getInstanceV1().fold(
{ Server.from(nodeInfo.software, it).mapError(::Capabilities) },
{ Err(GetInstanceInfoV1(it)) },

View File

@ -91,6 +91,10 @@ data class Role(
val name: String,
/** Colour to use for the role badge, may be the empty string */
val color: String,
// Default value is true, since the property may be missing and the observed
// Mastodon behaviour when it is is to highlight the role. Also, this property
// being missing breaks InstanceV2 parsing.
// See https://github.com/mastodon/mastodon/issues/28327
/** True if the badge should be displayed on the account profile */
val highlighted: Boolean,
val highlighted: Boolean = true,
)