Make account conform to hashable (IOS-190)

This commit is contained in:
Nathan Mattes 2023-11-13 14:43:14 +01:00
parent 1400b527dc
commit 92fcd2e665
5 changed files with 64 additions and 6 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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`

View File

@ -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