From 92fcd2e665b66e96a3265a9f29213d214e330117 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Mon, 13 Nov 2023 14:43:14 +0100 Subject: [PATCH] Make account conform to hashable (IOS-190) --- .../Entity/Mastodon+Entity+Account.swift | 60 ++++++++++++++++++- .../Entity/Mastodon+Entity+Emoji.swift | 2 +- .../Entity/Mastodon+Entity+Field.swift | 2 +- .../Entity/Mastodon+Entity+Source.swift | 4 +- .../Entity/Mastodon+Entity+Suggestion.swift | 2 +- 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift index eb2910bb9..0838ab793 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift @@ -18,7 +18,7 @@ extension Mastodon.Entity { /// # Reference /// [Document](https://docs.joinmastodon.org/entities/account/) public final class Account: Codable, Sendable { - + public typealias ID = String // Base @@ -84,6 +84,64 @@ extension Mastodon.Entity { } } +extension Mastodon.Entity.Account: Hashable { + public func hash(into hasher: inout Hasher) { + hasher.combine(id) + hasher.combine(username) + hasher.combine(acct) + hasher.combine(url) + hasher.combine(displayName) + hasher.combine(note) + hasher.combine(avatar) + hasher.combine(avatarStatic) + hasher.combine(header) + hasher.combine(headerStatic) + hasher.combine(locked) + hasher.combine(emojis) + hasher.combine(discoverable) + hasher.combine(createdAt) + hasher.combine(lastStatusAt) + hasher.combine(statusesCount) + hasher.combine(followersCount) + hasher.combine(followingCount) + hasher.combine(moved) + hasher.combine(fields) + hasher.combine(bot) + hasher.combine(source) + hasher.combine(suspended) + hasher.combine(muteExpiresAt) + } +} + +extension Mastodon.Entity.Account: Equatable { + public static func == (lhs: Mastodon.Entity.Account, rhs: Mastodon.Entity.Account) -> Bool { + return lhs.id == rhs.id && + lhs.username == rhs.username && + lhs.acct == rhs.acct && + lhs.url == rhs.url && + lhs.displayName == rhs.displayName && + lhs.note == rhs.note && + lhs.avatar == rhs.avatar && + lhs.avatarStatic == rhs.avatarStatic && + lhs.header == rhs.header && + lhs.headerStatic == rhs.headerStatic && + lhs.locked == rhs.locked && + lhs.emojis == rhs.emojis && + lhs.discoverable == rhs.discoverable && + lhs.createdAt == rhs.createdAt && + lhs.lastStatusAt == rhs.lastStatusAt && + lhs.statusesCount == rhs.statusesCount && + lhs.followersCount == rhs.followersCount && + lhs.followingCount == rhs.followingCount && + lhs.moved == rhs.moved && + lhs.fields == rhs.fields && + lhs.bot == rhs.bot && + lhs.source == rhs.source && + lhs.suspended == rhs.suspended && + lhs.muteExpiresAt == rhs.muteExpiresAt + } +} + extension Mastodon.Entity.Account { public func acctWithDomainIfMissing(_ localDomain: String) -> String { guard acct.contains("@") else { diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Emoji.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Emoji.swift index 284e505da..122938024 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Emoji.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Emoji.swift @@ -16,7 +16,7 @@ extension Mastodon.Entity { /// 2021/1/28 /// # Reference /// [Document](https://docs.joinmastodon.org/entities/emoji/) - public struct Emoji: Codable, Sendable { + public struct Emoji: Codable, Sendable, Hashable { public let shortcode: String public let url: String public let staticURL: String diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Field.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Field.swift index 9f9cf3e74..5886fb86b 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Field.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Field.swift @@ -16,7 +16,7 @@ extension Mastodon.Entity { /// 2021/1/28 /// # Reference /// [Document](https://docs.joinmastodon.org/entities/field/) - public struct Field: Codable, Sendable { + public struct Field: Codable, Sendable, Hashable { public let name: String public let value: String diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Source.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Source.swift index 8e8f94452..bc9c60f7a 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Source.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Source.swift @@ -16,7 +16,7 @@ extension Mastodon.Entity { /// 2021/2/3 /// # Reference /// [Document](https://docs.joinmastodon.org/entities/source/) - public struct Source: Codable, Sendable { + public struct Source: Codable, Sendable, Hashable { // Base public let note: String @@ -40,7 +40,7 @@ extension Mastodon.Entity { } extension Mastodon.Entity.Source { - public enum Privacy: RawRepresentable, Codable, Sendable { + public enum Privacy: RawRepresentable, Codable, Sendable, Hashable { case `public` case unlisted case `private` diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Suggestion.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Suggestion.swift index 7bec16990..b46cbaf15 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Suggestion.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Suggestion.swift @@ -9,7 +9,7 @@ import Foundation extension Mastodon.Entity.V2 { - public struct SuggestionAccount: Codable, Sendable { + public struct SuggestionAccount: Codable, Sendable, Hashable { public let source: String public let account: Mastodon.Entity.Account