From 51c64a74dcd0925287894f7c05336db5d180003f Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Thu, 22 Feb 2024 21:17:34 +0100 Subject: [PATCH] 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. --- app/src/main/java/app/pachli/network/ServerRepository.kt | 3 ++- .../main/kotlin/app/pachli/core/network/model/Account.kt | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/pachli/network/ServerRepository.kt b/app/src/main/java/app/pachli/network/ServerRepository.kt index e70be6b05..2973b9057 100644 --- a/app/src/main/java/app/pachli/network/ServerRepository.kt +++ b/app/src/main/java/app/pachli/network/ServerRepository.kt @@ -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)) }, diff --git a/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt b/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt index a94241714..4fb787685 100644 --- a/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt +++ b/core/network/src/main/kotlin/app/pachli/core/network/model/Account.kt @@ -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, )