diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift index 2497a64ea..9a8a8b0cd 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Notification.swift @@ -125,4 +125,20 @@ extension APIService { return response } + + public func acceptNotificationRequests(authenticationBox: MastodonAuthenticationBox, id: String) async throws -> Mastodon.Response.Content<[String: String]> { + let domain = authenticationBox.domain + let authorization = authenticationBox.userAuthorization + + let response = try await Mastodon.API.Notifications.acceptNotificationRequest(id: id, session: session, domain: domain, authorization: authorization) + return response + } + + public func rejectNotificationRequests(authenticationBox: MastodonAuthenticationBox, id: String) async throws -> Mastodon.Response.Content<[String: String]> { + let domain = authenticationBox.domain + let authorization = authenticationBox.userAuthorization + + let response = try await Mastodon.API.Notifications.dismissNotificationRequest(id: id, session: session, domain: domain, authorization: authorization) + return response + } } diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift index d309e6cf5..91f327184 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API+Notifications.swift @@ -202,6 +202,18 @@ extension Mastodon.API.Notifications { notificationsEndpointURL(domain: domain).appendingPathComponent("requests") } + internal static func notificationRequestEndpointURL(domain: String, id: String) -> URL { + notificationRequestsEndpointURL(domain: domain).appendingPathComponent(id) + } + + internal static func acceptNotificationRequestEndpointURL(domain: String, id: String) -> URL { + notificationRequestEndpointURL(domain: domain, id: id).appendingPathExtension("accept") + } + + internal static func dismissNotificationRequestEndpointURL(domain: String, id: String) -> URL { + notificationRequestEndpointURL(domain: domain, id: id).appendingPathExtension("dismiss") + } + public static func getNotificationRequests( session: URLSession, domain: String, @@ -217,4 +229,40 @@ extension Mastodon.API.Notifications { let value = try Mastodon.API.decode(type: [Mastodon.Entity.NotificationRequest].self, from: data, response: response) return Mastodon.Response.Content(value: value, response: response) } + + public static func acceptNotificationRequest( + id: String, + session: URLSession, + domain: String, + authorization: Mastodon.API.OAuth.Authorization + ) async throws -> Mastodon.Response.Content<[String: String]> { + let request = Mastodon.API.post( + url: acceptNotificationRequestEndpointURL(domain: domain, id: id), + authorization: authorization + ) + + let (data, response) = try await session.data(for: request) + + // we expect an empty dictionary + let value = try Mastodon.API.decode(type: [String: String].self, from: data, response: response) + return Mastodon.Response.Content(value: value, response: response) + } + + public static func dismissNotificationRequest( + id: String, + session: URLSession, + domain: String, + authorization: Mastodon.API.OAuth.Authorization + ) async throws -> Mastodon.Response.Content<[String: String]> { + let request = Mastodon.API.post( + url: dismissNotificationRequestEndpointURL(domain: domain, id: id), + authorization: authorization + ) + + let (data, response) = try await session.data(for: request) + + // we expect an empty dictionary + let value = try Mastodon.API.decode(type: [String: String].self, from: data, response: response) + return Mastodon.Response.Content(value: value, response: response) + } } diff --git a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift index 110332287..a733a0705 100644 --- a/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift +++ b/MastodonSDK/Sources/MastodonSDK/API/Mastodon+API.swift @@ -149,7 +149,7 @@ extension Mastodon.API { static func post( url: URL, - query: PostQuery?, + query: PostQuery? = nil, authorization: OAuth.Authorization? = nil ) -> URLRequest { return buildRequest(url: url, method: .POST, query: query, authorization: authorization)