diff --git a/Mastodon/Service/APIService/APIService+Notification.swift b/Mastodon/Service/APIService/APIService+Notification.swift index a27aae2ae..6e8af70bc 100644 --- a/Mastodon/Service/APIService/APIService+Notification.swift +++ b/Mastodon/Service/APIService/APIService+Notification.swift @@ -28,15 +28,15 @@ extension APIService { ) .flatMap { response -> AnyPublisher, Error> in let log = OSLog.api - if query.maxID == nil { - let requestMastodonNotificationRequest = MastodonNotification.sortedFetchRequest - requestMastodonNotificationRequest.predicate = MastodonNotification.predicate(domain: domain, userID: userID) - let oldNotifications = self.backgroundManagedObjectContext.safeFetch(requestMastodonNotificationRequest) - oldNotifications.forEach { notification in - self.backgroundManagedObjectContext.delete(notification) - } - } return self.backgroundManagedObjectContext.performChanges { + if query.maxID == nil { + let requestMastodonNotificationRequest = MastodonNotification.sortedFetchRequest + requestMastodonNotificationRequest.predicate = MastodonNotification.predicate(domain: domain, userID: userID) + let oldNotifications = self.backgroundManagedObjectContext.safeFetch(requestMastodonNotificationRequest) + oldNotifications.forEach { notification in + self.backgroundManagedObjectContext.delete(notification) + } + } response.value.forEach { notification in let (mastodonUser, _) = APIService.CoreData.createOrMergeMastodonUser(into: self.backgroundManagedObjectContext, for: nil, in: domain, entity: notification.account, userCache: nil, networkDate: Date(), log: log) var status: Status? diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+FollowRequest.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+FollowRequest.swift index f08e888b5..004197143 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+FollowRequest.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Account+FollowRequest.swift @@ -11,13 +11,13 @@ import Combine // MARK: - Account credentials extension Mastodon.API.Account { - static func acceptFollowRequestEndpointURL(domain: String, userID: String) -> URL { + static func acceptFollowRequestEndpointURL(domain: String, userID: Mastodon.Entity.Account.ID) -> URL { return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("follow_requests") .appendingPathComponent(userID) .appendingPathComponent("authorize") } - static func rejectFollowRequestEndpointURL(domain: String, userID: String) -> URL { + static func rejectFollowRequestEndpointURL(domain: String, userID: Mastodon.Entity.Account.ID) -> URL { return Mastodon.API.endpointURL(domain: domain).appendingPathComponent("follow_requests") .appendingPathComponent(userID) .appendingPathComponent("reject") @@ -34,12 +34,12 @@ extension Mastodon.API.Account { /// - session: `URLSession` /// - domain: Mastodon instance domain. e.g. "example.com" /// - userID: ID of the account in the database - /// - authorization: App token + /// - authorization: User token /// - Returns: `AnyPublisher` contains `Relationship` nested in the response public static func acceptFollowRequest( session: URLSession, domain: String, - userID: String, + userID: Mastodon.Entity.Account.ID, authorization: Mastodon.API.OAuth.Authorization ) -> AnyPublisher, Error> { let request = Mastodon.API.post( @@ -66,12 +66,12 @@ extension Mastodon.API.Account { /// - session: `URLSession` /// - domain: Mastodon instance domain. e.g. "example.com" /// - userID: ID of the account in the database - /// - authorization: App token + /// - authorization: User token /// - Returns: `AnyPublisher` contains `Relationship` nested in the response public static func rejectFollowRequest( session: URLSession, domain: String, - userID: String, + userID: Mastodon.Entity.Account.ID, authorization: Mastodon.API.OAuth.Authorization ) -> AnyPublisher, Error> { let request = Mastodon.API.post(