From b9fa20f0831dd0eeff916b484312fcc651de276a Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Sat, 29 Jun 2024 14:02:10 +0200 Subject: [PATCH] Adopt new authors-API-change and add publisher --- .../Entity/Mastodon+Entity+Card.swift | 16 +++++++++++++--- .../View/Content/StatusCardControl.swift | 7 ++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Card.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Card.swift index 47bab3f43..a8f1e511d 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Card.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Card.swift @@ -22,8 +22,10 @@ extension Mastodon.Entity { public let title: String public let description: String public let type: Type - + + @available(*, deprecated, message: "Use authors-array. Kept for compatibility") public let authorName: String? + @available(*, deprecated, message: "Use authors-array. Kept for compatibility") public let authorURL: String? public let providerName: String? public let providerURL: String? @@ -33,7 +35,7 @@ extension Mastodon.Entity { public let image: String? public let embedURL: String? public let blurhash: String? - public let authorAccount: Mastodon.Entity.Account? + public let authors: [Mastodon.Entity.Card.Author]? enum CodingKeys: String, CodingKey { case url @@ -50,11 +52,19 @@ extension Mastodon.Entity { case image case embedURL = "embed_url" case blurhash - case authorAccount = "author_account" + case authors } } } +extension Mastodon.Entity.Card { + public struct Author: Codable, Sendable { + public let name: String? + public let url: String? + public let account: Mastodon.Entity.Account? + } +} + extension Mastodon.Entity.Card { public enum `Type`: RawRepresentable, Codable, Sendable { case link diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift index c04046468..12ba3bcf6 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift @@ -184,12 +184,13 @@ public final class StatusCardControl: UIControl { accessibilityLabel = title } - if let authorAccount = card.authorAccount { - authorAccountButton.configuration?.title = authorAccount.displayName + + if let author = card.authors?.first { + authorAccountButton.configuration?.title = author.name ?? author.account?.displayName authorAccountButton.isHidden = false authorLabel.isHidden = true byLabel.isHidden = false - mastodonLogoImageView.isHidden = false + mastodonLogoImageView.isHidden = (author.account == nil) } else { if let authorName = card.authorName, authorName.isEmpty == false { authorLabel.text = "by \(authorName)"