[WIP] Add API-calls for accepting/rejecting notification requests (IOS-241)

This commit is contained in:
Nathan Mattes 2024-07-18 13:42:17 +02:00
parent 94a8791c4b
commit 8b65421103
3 changed files with 65 additions and 1 deletions

View File

@ -125,4 +125,20 @@ extension APIService {
return response 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
}
} }

View File

@ -202,6 +202,18 @@ extension Mastodon.API.Notifications {
notificationsEndpointURL(domain: domain).appendingPathComponent("requests") 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( public static func getNotificationRequests(
session: URLSession, session: URLSession,
domain: String, 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) let value = try Mastodon.API.decode(type: [Mastodon.Entity.NotificationRequest].self, from: data, response: response)
return Mastodon.Response.Content(value: value, 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)
}
} }

View File

@ -149,7 +149,7 @@ extension Mastodon.API {
static func post( static func post(
url: URL, url: URL,
query: PostQuery?, query: PostQuery? = nil,
authorization: OAuth.Authorization? = nil authorization: OAuth.Authorization? = nil
) -> URLRequest { ) -> URLRequest {
return buildRequest(url: url, method: .POST, query: query, authorization: authorization) return buildRequest(url: url, method: .POST, query: query, authorization: authorization)