From f51d5b7fe2061d290a8bf2438c3b775bc1164c5e Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Wed, 13 Dec 2023 16:42:35 +0100 Subject: [PATCH] Replace MastodonUser.ID with string (IOS-192) --- .../Provider/DataSourceFacade+Follow.swift | 2 +- .../Entity/Mastodon/MastodonUser.swift | 20 +++++++++---------- .../Entity/Mastodon/Status.swift | 8 ++++---- .../CoreDataStack/Entity/Transient/Acct.swift | 2 +- .../MastodonAuthenticationBox.swift | 4 ++-- .../CoreDataStack/Notification+Property.swift | 2 +- .../Service/API/APIService+Block.swift | 4 ++-- .../Service/API/APIService+Follow.swift | 4 ++-- .../Service/API/APIService+Mute.swift | 2 +- .../Service/API/APIService+Relationship.swift | 4 ++-- .../Service/AuthenticationService.swift | 2 +- 11 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift index c0b4cca77..84deba2ca 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Follow.swift @@ -56,7 +56,7 @@ extension DataSourceFacade { await selectionFeedbackGenerator.selectionChanged() let managedObjectContext = dependency.context.managedObjectContext - let _userID: MastodonUser.ID? = try await managedObjectContext.perform { + let _userID: String? = try await managedObjectContext.perform { return notification.account.id } diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift index 8e0ef8a47..7080ec3fd 100644 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift +++ b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/MastodonUser.swift @@ -11,15 +11,13 @@ import Foundation /// See also `CoreDataStack.MastodonUser`, this extension contains several @available(*, deprecated, message: "Replace with Mastodon.Entity.Account") final public class MastodonUser: NSManagedObject { - - public typealias ID = String - + // sourcery: autoGenerateProperty - @NSManaged public private(set) var identifier: ID + @NSManaged public private(set) var identifier: String // sourcery: autoGenerateProperty @NSManaged public private(set) var domain: String // sourcery: autoGenerateProperty - @NSManaged public private(set) var id: ID + @NSManaged public private(set) var id: String // sourcery: autoUpdatableObject, autoGenerateProperty @NSManaged public private(set) var acct: String @@ -206,11 +204,11 @@ extension MastodonUser { ]) } - public static func predicate(followingBy userID: MastodonUser.ID) -> NSPredicate { + public static func predicate(followingBy userID: String) -> NSPredicate { NSPredicate(format: "ANY %K.%K == %@", #keyPath(MastodonUser.followingBy), #keyPath(MastodonUser.id), userID) } - public static func predicate(followRequestedBy userID: MastodonUser.ID) -> NSPredicate { + public static func predicate(followRequestedBy userID: String) -> NSPredicate { NSPredicate(format: "ANY %K.%K == %@", #keyPath(MastodonUser.followRequestedBy), #keyPath(MastodonUser.id), userID) } @@ -223,9 +221,9 @@ extension MastodonUser: AutoGenerateProperty { // Generated using Sourcery // DO NOT EDIT public struct Property { - public let identifier: ID + public let identifier: String public let domain: String - public let id: ID + public let id: String public let acct: String public let username: String public let displayName: String @@ -247,9 +245,9 @@ extension MastodonUser: AutoGenerateProperty { public let fields: [MastodonField] public init( - identifier: ID, + identifier: String, domain: String, - id: ID, + id: String, acct: String, username: String, displayName: String, diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift index 1b457f085..8f6b95bf4 100644 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift +++ b/MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Status.swift @@ -64,7 +64,7 @@ public final class Status: NSManagedObject { // sourcery: autoUpdatableObject, autoGenerateProperty @NSManaged public private(set) var inReplyToID: Status.ID? // sourcery: autoUpdatableObject, autoGenerateProperty - @NSManaged public private(set) var inReplyToAccountID: MastodonUser.ID? + @NSManaged public private(set) var inReplyToAccountID: String? // sourcery: autoUpdatableObject, autoGenerateProperty @NSManaged public private(set) var language: String? // (ISO 639 Part 1 two-letter language code) @@ -270,7 +270,7 @@ extension Status: AutoGenerateProperty { public let repliesCount: Int64 public let url: String? public let inReplyToID: Status.ID? - public let inReplyToAccountID: MastodonUser.ID? + public let inReplyToAccountID: String? public let language: String? public let text: String? public let updatedAt: Date @@ -295,7 +295,7 @@ extension Status: AutoGenerateProperty { repliesCount: Int64, url: String?, inReplyToID: Status.ID?, - inReplyToAccountID: MastodonUser.ID?, + inReplyToAccountID: String?, language: String?, text: String?, updatedAt: Date, @@ -484,7 +484,7 @@ extension Status: AutoUpdatableObject { self.inReplyToID = inReplyToID } } - public func update(inReplyToAccountID: MastodonUser.ID?) { + public func update(inReplyToAccountID: String?) { if self.inReplyToAccountID != inReplyToAccountID { self.inReplyToAccountID = inReplyToAccountID } diff --git a/MastodonSDK/Sources/CoreDataStack/Entity/Transient/Acct.swift b/MastodonSDK/Sources/CoreDataStack/Entity/Transient/Acct.swift index fe59bb9d4..e7e071da0 100644 --- a/MastodonSDK/Sources/CoreDataStack/Entity/Transient/Acct.swift +++ b/MastodonSDK/Sources/CoreDataStack/Entity/Transient/Acct.swift @@ -11,7 +11,7 @@ import Foundation extension Feed { public enum Acct: RawRepresentable { case none - case mastodon(domain: String, userID: MastodonUser.ID) + case mastodon(domain: String, userID: String) public init?(rawValue: String) { let components = rawValue.split(separator: "@", maxSplits: 2) diff --git a/MastodonSDK/Sources/MastodonCore/Authentication/MastodonAuthenticationBox.swift b/MastodonSDK/Sources/MastodonCore/Authentication/MastodonAuthenticationBox.swift index 8db326dfe..0a62d99d2 100644 --- a/MastodonSDK/Sources/MastodonCore/Authentication/MastodonAuthenticationBox.swift +++ b/MastodonSDK/Sources/MastodonCore/Authentication/MastodonAuthenticationBox.swift @@ -12,7 +12,7 @@ import MastodonSDK public struct MastodonAuthenticationBox: UserIdentifier { public let authentication: MastodonAuthentication public let domain: String - public let userID: MastodonUser.ID + public let userID: String public let appAuthorization: Mastodon.API.OAuth.Authorization public let userAuthorization: Mastodon.API.OAuth.Authorization public let inMemoryCache: MastodonAccountInMemoryCache @@ -20,7 +20,7 @@ public struct MastodonAuthenticationBox: UserIdentifier { public init( authentication: MastodonAuthentication, domain: String, - userID: MastodonUser.ID, + userID: String, appAuthorization: Mastodon.API.OAuth.Authorization, userAuthorization: Mastodon.API.OAuth.Authorization, inMemoryCache: MastodonAccountInMemoryCache diff --git a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Notification+Property.swift b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Notification+Property.swift index 4d125bd52..30d95a810 100644 --- a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Notification+Property.swift +++ b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Notification+Property.swift @@ -14,7 +14,7 @@ extension Notification.Property { public init( entity: Mastodon.Entity.Notification, domain: String, - userID: MastodonUser.ID, + userID: String, networkDate: Date ) { self.init( diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift index c1650e9b5..428ef6eec 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift @@ -14,8 +14,8 @@ import MastodonSDK extension APIService { private struct MastodonBlockContext { - let sourceUserID: MastodonUser.ID - let targetUserID: MastodonUser.ID + let sourceUserID: String + let targetUserID: String let targetUsername: String let isBlocking: Bool let isFollowing: Bool diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Follow.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Follow.swift index dadb34e29..398eaf2ee 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Follow.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Follow.swift @@ -14,8 +14,8 @@ import MastodonSDK extension APIService { private struct MastodonFollowContext { - let sourceUserID: MastodonUser.ID - let targetUserID: MastodonUser.ID + let sourceUserID: String + let targetUserID: String let isFollowing: Bool let isPending: Bool let needsUnfollow: Bool diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift index d45b33e2e..b97e405b9 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift @@ -14,7 +14,7 @@ import MastodonSDK extension APIService { private struct MastodonMuteContext { - let targetUserID: MastodonUser.ID + let targetUserID: String let targetUsername: String let isMuting: Bool } diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift index 2df898977..b6c5ebcd4 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Relationship.swift @@ -20,7 +20,7 @@ extension APIService { let managedObjectContext = backgroundManagedObjectContext let _query: Mastodon.API.Account.RelationshipQuery? = try? await managedObjectContext.perform { - var ids: [MastodonUser.ID] = [] + var ids: [String] = [] for record in records { guard let user = record.object(in: managedObjectContext) else { continue } guard user.id != authenticationBox.userID else { continue } @@ -71,7 +71,7 @@ extension APIService { authenticationBox: MastodonAuthenticationBox ) async throws -> Mastodon.Response.Content<[Mastodon.Entity.Relationship]> { - let ids: [MastodonUser.ID] = accounts.compactMap { $0.id } + let ids: [String] = accounts.compactMap { $0.id } guard ids.isEmpty == false else { throw APIError.implicit(.badRequest) } diff --git a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift index e43b812c9..d2a0b2ed1 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/AuthenticationService.swift @@ -125,7 +125,7 @@ public final class AuthenticationService: NSObject { extension AuthenticationService { - public func activeMastodonUser(domain: String, userID: MastodonUser.ID) async throws -> Bool { + public func activeMastodonUser(domain: String, userID: String) async throws -> Bool { var isActive = false AuthenticationServiceProvider.shared.activateAuthentication(in: domain, for: userID)