diff --git a/MastodonSDK/Package.swift b/MastodonSDK/Package.swift index a6ac785e7..00773dfe9 100644 --- a/MastodonSDK/Package.swift +++ b/MastodonSDK/Package.swift @@ -107,6 +107,7 @@ let package = Package( name: "MastodonSDK", dependencies: [ .product(name: "NIOHTTP1", package: "swift-nio"), + "MastodonCommon" ] ), .target( diff --git a/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Account.swift b/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Account.swift index 059f09420..56c00e31d 100644 --- a/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Account.swift +++ b/MastodonSDK/Sources/MastodonCore/Extension/MastodonSDK/Mastodon+Entity+Account.swift @@ -9,33 +9,6 @@ import Foundation import MastodonSDK import MastodonMeta -extension Mastodon.Entity.Account: Hashable { - public func hash(into hasher: inout Hasher) { - hasher.combine(id) - } - - public static func == (lhs: Mastodon.Entity.Account, rhs: Mastodon.Entity.Account) -> Bool { - return lhs.id == rhs.id - } -} - -extension Mastodon.Entity.Account { - public func avatarImageURL() -> URL? { - let string = UserDefaults.shared.preferredStaticAvatar ? avatarStatic ?? avatar : avatar - return URL(string: string) - } - - public func avatarImageURLWithFallback(domain: String) -> URL { - return avatarImageURL() ?? URL(string: "https://\(domain)/avatars/original/missing.png")! - } -} - -extension Mastodon.Entity.Account { - public var displayNameWithFallback: String { - return !displayName.isEmpty ? displayName : username - } -} - extension Mastodon.Entity.Account { public var emojiMeta: MastodonContent.Emojis { let isAnimated = !UserDefaults.shared.preferredStaticEmoji diff --git a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift index 0838ab793..9e37770f9 100644 --- a/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift +++ b/MastodonSDK/Sources/MastodonSDK/Entity/Mastodon+Entity+Account.swift @@ -6,6 +6,7 @@ // import Foundation +import MastodonCommon extension Mastodon.Entity { @@ -84,64 +85,24 @@ extension Mastodon.Entity { } } +//MARK: - Hashable extension Mastodon.Entity.Account: Hashable { public func hash(into hasher: inout Hasher) { - hasher.combine(id) - hasher.combine(username) - hasher.combine(acct) + // The URL seems to be the only thing that doesn't change across instances. 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) } + } +//MARK: - Equatable 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 + // The URL seems to be the only thing that doesn't change across instances. + return lhs.url == rhs.url } } +//MARK: - Convenience extension Mastodon.Entity.Account { public func acctWithDomainIfMissing(_ localDomain: String) -> String { guard acct.contains("@") else { @@ -160,4 +121,18 @@ extension Mastodon.Entity.Account { return components.host } + + public func avatarImageURL() -> URL? { + let string = UserDefaults.shared.preferredStaticAvatar ? avatarStatic ?? avatar : avatar + return URL(string: string) + } + + public func avatarImageURLWithFallback(domain: String) -> URL { + return avatarImageURL() ?? URL(string: "https://\(domain)/avatars/original/missing.png")! + } + + public var displayNameWithFallback: String { + return !displayName.isEmpty ? displayName : username + + } }