[WIP] Add API-calls for accepting/rejecting notification requests (IOS-241)
This commit is contained in:
parent
94a8791c4b
commit
8b65421103
|
@ -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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue