Skip to content

Commit a1181b5

Browse files
committed
Update lexicon models and methods
1 parent 2577099 commit a1181b5

6 files changed

Lines changed: 905 additions & 10 deletions
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//
2+
// ToolsOzoneModerationCancelScheduledActionsMethod.swift
3+
// ATProtoKit
4+
//
5+
// Created by Christopher Jr Riley on 2025-11-18.
6+
//
7+
8+
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
12+
13+
extension ATProtoAdmin {
14+
15+
/// Cancels any pending scheduled moderation actions for the specified user accounts.
16+
///
17+
/// - Note: According to the AT Protocol specifications: "Cancel all pending scheduled moderation actions for specified subjects"
18+
///
19+
/// - SeeAlso: This is based on the [`tools.ozone.moderation.cancelScheduledActions`][github] lexicon.
20+
///
21+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/cancelScheduledActions.json
22+
///
23+
/// - Parameters:
24+
/// - subjects: An array of decentralized identifiers (DIDs) for which the cancellations will
25+
/// occur on.
26+
/// - comment: A comment to attach to the cancellation. Optional.
27+
/// - Returns: Results of the cancelled pending actions.
28+
///
29+
/// /// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to
30+
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details.
31+
public func cancelScheduledActions(
32+
for dids: [String],
33+
comment: String
34+
) async throws -> ToolsOzoneLexicon.Moderation.CancelScheduledActions.CancellationResults {
35+
guard let session = try await self.getUserSession(),
36+
let keychain = sessionConfiguration?.keychainProtocol else {
37+
throw ATRequestPrepareError.missingActiveSession
38+
}
39+
40+
try await sessionConfiguration?.ensureValidToken()
41+
let accessToken = try await keychain.retrieveAccessToken()
42+
43+
guard let sessionURL = session.pdsURL,
44+
let requestURL = URL(string: "\(sessionURL)/xrpc/tools.ozone.moderation.cancelScheduledActions") else {
45+
throw ATRequestPrepareError.invalidRequestURL
46+
}
47+
48+
let requestBody = ToolsOzoneLexicon.Moderation.CancelScheduledActionsRequestBody(
49+
subjects: dids,
50+
comment: comment
51+
)
52+
53+
do {
54+
let request = apiClientService.createRequest(
55+
forRequest: requestURL,
56+
andMethod: .post,
57+
acceptValue: "application/json",
58+
contentTypeValue: "application/json",
59+
authorizationValue: "Bearer \(accessToken)"
60+
)
61+
let response = try await apiClientService.sendRequest(
62+
request,
63+
withEncodingBody: requestBody,
64+
decodeTo: ToolsOzoneLexicon.Moderation.CancelScheduledActions.CancellationResults.self
65+
)
66+
67+
return response
68+
} catch {
69+
throw error
70+
}
71+
}
72+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// ToolsOzoneModerationCancelScheduledActions.swift
3+
// ATProtoKit
4+
//
5+
// Created by Christopher Jr Riley on 2025-11-18.
6+
//
7+
8+
import Foundation
9+
#if canImport(FoundationNetworking)
10+
import FoundationNetworking
11+
#endif
12+
13+
extension ToolsOzoneLexicon.Moderation {
14+
15+
/// A definition model for cancelling any pending scheduled moderation actions for the specified
16+
/// user accounts.
17+
///
18+
/// - Note: According to the AT Protocol specifications: "Cancel all pending scheduled moderation actions for specified subjects"
19+
///
20+
/// - SeeAlso: This is based on the [`tools.ozone.moderation.cancelScheduledActions`][github] lexicon.
21+
///
22+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/cancelScheduledActions.json
23+
public struct CancelScheduledActions: Sendable, Codable {
24+
25+
/// Results of the cancelled pending actions.
26+
public struct CancellationResults: Sendable, Codable {
27+
28+
/// An array of decentralized identifiers (DIDs) that had all of their actions
29+
/// successfully completed.
30+
///
31+
/// - Note: According to the AT Protocol specifications: "DIDs for which all pending scheduled
32+
/// actions were successfully cancelled."
33+
public let successfulActions: [String]
34+
35+
/// An array of error details for each failed action.
36+
///
37+
/// - Note: According to the AT Protocol specifications: "DIDs for which cancellation failed
38+
/// with error details."
39+
public let failedActions: [FailedCancellation]
40+
41+
enum CodingKeys: String, CodingKey {
42+
case successfulActions = "succeeded"
43+
case failedActions = "failed"
44+
}
45+
}
46+
47+
/// Error details for each failed action.
48+
public struct FailedCancellation: Sendable, Codable {
49+
50+
/// The decentralized identifier (DID) of the user account associated with the failed action.
51+
public let did: String
52+
53+
/// The error details.
54+
public let error: String
55+
56+
/// The error code of the failed action. Optional.
57+
public let errorCode: String?
58+
}
59+
}
60+
61+
/// A request body model for cancelling any pending scheduled moderation actions for the specified
62+
/// user accounts.
63+
///
64+
/// - Note: According to the AT Protocol specifications: "Cancel all pending scheduled moderation actions for specified subjects"
65+
///
66+
/// - SeeAlso: This is based on the [`tools.ozone.moderation.cancelScheduledActions`][github] lexicon.
67+
///
68+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/cancelScheduledActions.json
69+
public struct CancelScheduledActionsRequestBody: Sendable, Codable {
70+
71+
/// An array of decentralized identifiers (DIDs) for which the cancellations will occur on.
72+
///
73+
/// - Note: According to the AT Protocol specifications: "Array of DID subjects to cancel scheduled
74+
/// actions for."
75+
public let subjects: [String]
76+
77+
/// A comment to attach to the cancellation. Optional.
78+
///
79+
/// - Note: According to the AT Protocol specifications: "Optional comment describing the reason
80+
/// for cancellation."
81+
public let comment: String?
82+
83+
public init(subjects: [String], comment: String?) {
84+
self.subjects = subjects
85+
self.comment = comment
86+
}
87+
88+
public init(from decoder: any Decoder) throws {
89+
let container = try decoder.container(keyedBy: CodingKeys.self)
90+
91+
self.subjects = try container.decode([String].self, forKey: .subjects)
92+
self.comment = try container.decodeIfPresent(String.self, forKey: .comment)
93+
}
94+
95+
public func encode(to encoder: any Encoder) throws {
96+
var container = encoder.container(keyedBy: CodingKeys.self)
97+
98+
try container.truncatedEncode(self.subjects, forKey: .subjects, upToArrayLength: 100)
99+
try container.encodeIfPresent(self.comment, forKey: .comment)
100+
}
101+
102+
enum CodingKeys: CodingKey {
103+
case subjects
104+
case comment
105+
}
106+
}
107+
108+
// /// An output model for cancelling any pending scheduled moderation actions for the specified
109+
// /// user accounts.
110+
// ///
111+
// /// - Note: According to the AT Protocol specifications: "Cancel all pending scheduled moderation actions for specified subjects"
112+
// ///
113+
// /// - SeeAlso: This is based on the [`tools.ozone.moderation.cancelScheduledActions`][github] lexicon.
114+
// ///
115+
// /// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/cancelScheduledActions.json
116+
// public struct CancelScheduledActionsOutput: Sendable, Codable {
117+
//
118+
// ///
119+
// }
120+
}

0 commit comments

Comments
 (0)