From 37169d96c57ef1529a7aea00b6fdb01cd4358303 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Wed, 13 Nov 2024 14:51:03 +0100 Subject: [PATCH] fix: Don't crash on relationship severance events (#1092) Previous code was missing the JSON name of the event, so it wasn't present when it should have been, resulting in a crash. Also, the Mastodon documentation is incorrect about the relationship count, which is instead represented as two properties, one for followers and one for following. So model that, and display them separately in the UI. Fixes #1086 --- .../SeveredRelationshipsViewHolder.kt | 14 +++++++---- .../res/layout/item_severed_relationships.xml | 23 +++++++++++++++---- app/src/main/res/values-es/strings.xml | 5 ---- app/src/main/res/values-fi/strings.xml | 4 ---- app/src/main/res/values-gl/strings.xml | 4 ---- app/src/main/res/values-nb-rNO/strings.xml | 4 ---- app/src/main/res/values/strings.xml | 10 +++++--- .../pachli/core/network/model/Notification.kt | 1 + .../model/RelationshipSeveranceEvent.kt | 14 ++++++++--- 9 files changed, 48 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/app/pachli/components/notifications/SeveredRelationshipsViewHolder.kt b/app/src/main/java/app/pachli/components/notifications/SeveredRelationshipsViewHolder.kt index abe027ae8..566498648 100644 --- a/app/src/main/java/app/pachli/components/notifications/SeveredRelationshipsViewHolder.kt +++ b/app/src/main/java/app/pachli/components/notifications/SeveredRelationshipsViewHolder.kt @@ -48,10 +48,16 @@ class SeveredRelationshipsViewHolder( binding.datetime.text = getRelativeTimeSpanString(itemView.context, event.createdAt.time, System.currentTimeMillis()) - binding.notificationSummary.text = itemView.context.resources.getQuantityString( - R.plurals.notification_severed_relationships_summary_report_fmt, - event.relationshipsCount, - event.relationshipsCount, + binding.notificationFollowersCount.text = itemView.context.resources.getQuantityString( + R.plurals.notification_severed_relationships_summary_followers_fmt, + event.followersCount, + event.followersCount, + ) + + binding.notificationFollowingCount.text = itemView.context.resources.getQuantityString( + R.plurals.notification_severed_relationships_summary_following_fmt, + event.followingCount, + event.followingCount, ) val resourceId = when (event.type) { diff --git a/app/src/main/res/layout/item_severed_relationships.xml b/app/src/main/res/layout/item_severed_relationships.xml index ee41a1aea..dae17db4f 100644 --- a/app/src/main/res/layout/item_severed_relationships.xml +++ b/app/src/main/res/layout/item_severed_relationships.xml @@ -63,7 +63,7 @@ tools:ignore="SelectableText" /> + + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 15a34255c..bc984f062 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -625,11 +625,6 @@ Un moderador suspendió la cuenta Motivo desconocido Se rompió la relación con %1$s - - Se rompió %1$d relación - Se rompieron %1$d relaciones - Se rompieron %1$d relaciones - Relaciones rotas Notificaciones de relaciones rotas Mostrar votos diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 5db9b42c8..4232583db 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -613,10 +613,6 @@ Estit verkkotunnuksen Moderaattori esti tilin Tuntematon syy - - %1$d yhteys katkaistu - %1$d yhteyttä katkaistu - Tarvitaan vähintään yksi avainsana tai lauseke Tarvitaan vähintään yksi suodatettava asia Otsikko vaaditaan diff --git a/app/src/main/res/values-gl/strings.xml b/app/src/main/res/values-gl/strings.xml index 9bd711e2a..c8afd6248 100644 --- a/app/src/main/res/values-gl/strings.xml +++ b/app/src/main/res/values-gl/strings.xml @@ -604,10 +604,6 @@ %1$s Non avisarme para esta versión Traducindo… - - %1$d relación perdida - %1$d relacións perdidas - %1$s %2$s Cargar as publicacións máis recentes Nunca diff --git a/app/src/main/res/values-nb-rNO/strings.xml b/app/src/main/res/values-nb-rNO/strings.xml index 961f0564a..11aa17cef 100644 --- a/app/src/main/res/values-nb-rNO/strings.xml +++ b/app/src/main/res/values-nb-rNO/strings.xml @@ -607,10 +607,6 @@ Innlegg Brøt forholdet med %1$s Ukjent årsak - - %1$d forhold brøt - %1$d forhold brøt - Bild Skriftfamilie Brutte forhold diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 720748622..d7926c4d9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -92,9 +92,13 @@ You blocked the domain A moderator suspended the account Unknown reason - - %1$d relationship severed - %1$d relationships severed + + %1$s follower removed + %1$s followers removed + + + %1$s account you follow removed + %1$s accounts you follow removed %s reported %s %s · %d posts attached diff --git a/core/network/src/main/kotlin/app/pachli/core/network/model/Notification.kt b/core/network/src/main/kotlin/app/pachli/core/network/model/Notification.kt index 10e2bbf44..6f8c43769 100644 --- a/core/network/src/main/kotlin/app/pachli/core/network/model/Notification.kt +++ b/core/network/src/main/kotlin/app/pachli/core/network/model/Notification.kt @@ -31,6 +31,7 @@ data class Notification( val account: TimelineAccount, val status: Status?, val report: Report?, + @Json(name = "event") val relationshipSeveranceEvent: RelationshipSeveranceEvent? = null, ) { diff --git a/core/network/src/main/kotlin/app/pachli/core/network/model/RelationshipSeveranceEvent.kt b/core/network/src/main/kotlin/app/pachli/core/network/model/RelationshipSeveranceEvent.kt index 223cf7f83..5278baeac 100644 --- a/core/network/src/main/kotlin/app/pachli/core/network/model/RelationshipSeveranceEvent.kt +++ b/core/network/src/main/kotlin/app/pachli/core/network/model/RelationshipSeveranceEvent.kt @@ -41,9 +41,17 @@ data class RelationshipSeveranceEvent( */ @Json(name = "target_name") val targetName: String, - /** Number of follow relationships (in either direction) that were severed. */ - @Json(name = "relationships_count") - val relationshipsCount: Int = 0, + + // Documentation is wrong: https://github.com/mastodon/documentation/issues/1556 + /** Number of follower accounts removed. */ + @Json(name = "followers_count") + val followersCount: Int = 0, + + // Documentation is wrong: https://github.com/mastodon/documentation/issues/1556 + /** Number of followed accounts removed. */ + @Json(name = "following_count") + val followingCount: Int = 0, + /** When the event took place. */ @Json(name = "created_at") val createdAt: Date,