Add notification-policy-download (IOS-241)
This commit is contained in:
parent
cd4ef9f31c
commit
cf39ad6d68
|
@ -107,3 +107,14 @@ extension APIService {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
extension APIService {
|
||||
public func notificationPolicy(authenticationBox: MastodonAuthenticationBox) async throws -> Mastodon.Response.Content<Mastodon.Entity.NotificationPolicy> {
|
||||
let domain = authenticationBox.domain
|
||||
let authorization = authenticationBox.userAuthorization
|
||||
|
||||
let response = try await Mastodon.API.Notifications.getNotificationPolicy(session: session, domain: domain, authorization: authorization).singleOutput()
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,3 +134,28 @@ extension Mastodon.API.Notifications {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - Notification Policy
|
||||
|
||||
extension Mastodon.API.Notifications {
|
||||
internal static func notificationPolicyEndpointURL(domain: String) -> URL {
|
||||
notificationsEndpointURL(domain: domain).appendingPathComponent("policy")
|
||||
}
|
||||
|
||||
public static func getNotificationPolicy(
|
||||
session: URLSession,
|
||||
domain: String,
|
||||
authorization: Mastodon.API.OAuth.Authorization
|
||||
) -> AnyPublisher<Mastodon.Response.Content<Mastodon.Entity.NotificationPolicy>, Error> {
|
||||
let request = Mastodon.API.get(
|
||||
url: notificationPolicyEndpointURL(domain: domain),
|
||||
authorization: authorization
|
||||
)
|
||||
return session.dataTaskPublisher(for: request)
|
||||
.tryMap { data, response in
|
||||
let value = try Mastodon.API.decode(type: Mastodon.Entity.NotificationPolicy.self, from: data, response: response)
|
||||
return Mastodon.Response.Content(value: value, response: response)
|
||||
}
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright © 2024 Mastodon gGmbH. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Mastodon.Entity {
|
||||
public struct NotificationPolicy: Codable {
|
||||
let filterNotFollowing: Bool
|
||||
let filterNotFollowers: Bool
|
||||
let filterNewAccounts: Bool
|
||||
let filterPrivateMentions: Bool
|
||||
let summary: Summary
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case filterNotFollowing = "filter_not_following"
|
||||
case filterNotFollowers = "filter_not_followers"
|
||||
case filterNewAccounts = "filter_new_accounts"
|
||||
case filterPrivateMentions = "filter_private_mentions"
|
||||
case summary
|
||||
}
|
||||
|
||||
public struct Summary: Codable {
|
||||
let pendingRequestsCount: Int
|
||||
let pendingNotificationsCount: Int
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case pendingRequestsCount = "pending_requests_count"
|
||||
case pendingNotificationsCount = "pending_notifications_count"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue