Skip to content

Commit a04701f

Browse files
committed
Update lexicon models and methods
1 parent b1fd9d9 commit a04701f

File tree

8 files changed

+305
-7
lines changed

8 files changed

+305
-7
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// GetReporterStats.swift
3+
//
4+
//
5+
// Created by Christopher Jr Riley on 2025-02-20.
6+
//
7+
8+
import Foundation
9+
10+
extension ATProtoAdmin {
11+
12+
/// Retrieves statistics about reporters for a list of users.
13+
///
14+
/// - Note: According to the AT Protocol specifications: "Get reporter stats for a list
15+
/// of users."
16+
///
17+
/// - SeeAlso: This is based on the [`tools.ozone.moderation.getReporterStats`][github] lexicon.
18+
///
19+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/getReporterStats.json
20+
///
21+
/// - Parameter dids: An array of Decentralized Identifiers (DIDs) to extract the
22+
/// repository information. Limits to 100 items.
23+
/// - Returns: An array of reporter statistics.
24+
///
25+
/// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to
26+
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details.
27+
public func getReporterStats(from dids: [String]) async throws -> ToolsOzoneLexicon.Moderation.GetReporterStatsOutput {
28+
guard session != nil,
29+
let accessToken = session?.accessToken else {
30+
throw ATRequestPrepareError.missingActiveSession
31+
}
32+
33+
guard let sessionURL = session?.pdsURL,
34+
let requestURL = URL(string: "\(sessionURL)/xrpc/tools.ozone.moderation.getReporterStats") else {
35+
throw ATRequestPrepareError.invalidRequestURL
36+
}
37+
38+
var queryItems = [(String, String)]()
39+
40+
let cappedDIDArray = dids.prefix(100)
41+
queryItems += cappedDIDArray.map { ("dids", $0) }
42+
43+
let queryURL: URL
44+
45+
do {
46+
queryURL = try APIClientService.setQueryItems(
47+
for: requestURL,
48+
with: queryItems
49+
)
50+
51+
let request = APIClientService.createRequest(
52+
forRequest: queryURL,
53+
andMethod: .get,
54+
acceptValue: "application/json",
55+
contentTypeValue: nil,
56+
authorizationValue: "Bearer \(accessToken)"
57+
)
58+
let response = try await APIClientService.shared.sendRequest(
59+
request,
60+
decodeTo: ToolsOzoneLexicon.Moderation.GetReporterStatsOutput.self
61+
)
62+
63+
return response
64+
} catch {
65+
throw error
66+
}
67+
}
68+
}

Sources/ATProtoKit/APIReference/AdminAndModeratorAPI/ListMembersAsAdmin.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,31 @@ import Foundation
1010
extension ATProtoAdmin {
1111

1212
/// Lists all of the ozone service members as an administrator.
13-
///
13+
///
1414
/// - Important: This is an administrator task and as such, regular users won't be able to
1515
/// access this; if they attempt to do so, an error will occur.
16-
///
16+
///
1717
/// - Note: According to the AT Protocol specifications: "List all members with access to the
1818
/// ozone service."
19-
///
19+
///
2020
/// - SeeAlso: This is based on the [`tools.ozone.team.listMembers`][github] lexicon.
21-
///
21+
///
2222
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/team/listMembers.json
23-
///
23+
///
2424
/// - Parameters:
25+
/// - isDisabled: Determines whether the members are disabled. Optional.
26+
/// - roles: An array of roles for the members. Optional.
2527
/// - limit: The number of invite codes in the list. Defaults to `50`.
2628
/// - cursor: The mark used to indicate the starting point for the next set
2729
/// of results. Optional.
28-
/// - Returns: An array of members in the ozone service that the administrator is in.
29-
///
30+
/// - Returns: An array of members in the ozone service that the administrator is in, with an
31+
/// optional cursor to extend the array.
32+
///
3033
/// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to
3134
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details.
3235
public func listMembers(
36+
isDisabled: Bool? = nil,
37+
roles: [String]? = nil,
3338
limit: Int? = 50,
3439
cursor: String? = nil
3540
) async throws -> ToolsOzoneLexicon.Team.ListMembersOutput {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// ListRepositoriesByCollection.swift
3+
//
4+
//
5+
// Created by Christopher Jr Riley on 2025-02-20.
6+
//
7+
8+
import Foundation
9+
10+
extension ATProtoKit {
11+
12+
/// Enumerates all decentralized identifiers (DIDs) with records in the given collection's
13+
/// Namespace Identifier (NSID).
14+
///
15+
/// - Note: According to the AT Protocol specifications: "Enumerates all the DIDs which have
16+
/// records with the given collection NSID."
17+
///
18+
/// - SeeAlso: This is based on the [`com.atproto.sync.listReposByCollection`][github] lexicon.
19+
///
20+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/sync/listReposByCollection.json
21+
///
22+
/// - Parameters:
23+
/// - collection: The Namespaced Identifier (NSID) of the repository.
24+
/// - limit: The number of repositories in the array. Optional. Defaults to `500`. Can only
25+
/// choose between `1` and `2,000`.
26+
/// - cursor: The mark used to indicate the starting point for the next set
27+
/// of results. Optional.
28+
/// - pdsURL: The URL of the Personal Data Server (PDS). Defaults to `https://api.bsky.app`.
29+
/// - Returns: An array of repositories, with an optional cursor to extend the array.
30+
///
31+
/// - Throws: An ``ATProtoError``-conforming error type, depending on the issue. Go to
32+
/// ``ATAPIError`` and ``ATRequestPrepareError`` for more details.
33+
public func listRepositoriesByCollection(
34+
collection: String,
35+
limit: Int? = 500,
36+
cursor: String? = nil,
37+
pdsURL: String = "https://api.bsky.app"
38+
) async throws -> ComAtprotoLexicon.Sync.ListRepositoriesByCollectionOutput {
39+
let finalPDSURL = self.determinePDSURL(customPDSURL: pdsURL)
40+
41+
guard let requestURL = URL(string: "\(finalPDSURL)/xrpc/com.atproto.sync.listReposByCollection") else {
42+
throw ATRequestPrepareError.invalidRequestURL
43+
}
44+
45+
var queryItems = [(String, String)]()
46+
47+
queryItems.append(("collection", String(collection)))
48+
49+
if let limit {
50+
let finalLimit = max(1, min(limit, 2_000))
51+
queryItems.append(("limit", "\(finalLimit)"))
52+
}
53+
54+
if let cursor {
55+
queryItems.append(("cursor", cursor))
56+
}
57+
58+
let queryURL: URL
59+
60+
do {
61+
queryURL = try APIClientService.setQueryItems(
62+
for: requestURL,
63+
with: queryItems
64+
)
65+
66+
let request = APIClientService.createRequest(
67+
forRequest: queryURL,
68+
andMethod: .get,
69+
acceptValue: "application/json",
70+
contentTypeValue: nil,
71+
authorizationValue: nil
72+
)
73+
let response = try await APIClientService.shared.sendRequest(
74+
request,
75+
decodeTo: ComAtprotoLexicon.Sync.ListRepositoriesByCollectionOutput.self
76+
)
77+
78+
return response
79+
} catch {
80+
throw error
81+
}
82+
}
83+
}

Sources/ATProtoKit/ATProtoKit.docc/Extensions/Lexicons/Models/com.atproto/ComAtprotoSync.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
- ``ComAtprotoLexicon/Sync/ListRepositories``
2121
- ``ComAtprotoLexicon/Sync/ListRepositoriesOutput``
2222

23+
### com.atproto.sync.listReposByCollection
24+
25+
- ``ComAtprotoLexicon/Sync/ListRepositories``
26+
- ``ComAtprotoLexicon/Sync/ListRepositoriesOutput``
27+
2328
### com.atproto.sync.subscribeRepos
2429

2530
- ``ComAtprotoLexicon/Sync/SubscribeRepos``

Sources/ATProtoKit/ATProtoKit.docc/Extensions/Lexicons/Models/tools.ozone/ToolsOzoneModeration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- ``ToolsOzoneLexicon/Moderation/VideoDetailsDefinition``
4242
- ``ToolsOzoneLexicon/Moderation/AccountHostingDefinition``
4343
- ``ToolsOzoneLexicon/Moderation/RecordHostingDefinition``
44+
- ``ToolsOzoneLexicon/Moderation/ReporterStatsDefinition``
4445

4546
### tools.ozone.moderation.emitEvent
4647

@@ -50,6 +51,10 @@
5051

5152
- ``ToolsOzoneLexicon/Moderation/GetRecordsOutput``
5253

54+
### tools.ozone.moderation.getReporterStats
55+
56+
- ``ToolsOzoneLexicon/Moderation/GetReporterStatsOutput``
57+
5358
### tools.ozone.moderation.getRepos
5459

5560
- ``ToolsOzoneLexicon/Moderation/GetRepositoriesOutput``
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// ComAtprotoSyncListReposByCollection.swift
3+
//
4+
//
5+
// Created by Christopher Jr Riley on 2025-02-20.
6+
//
7+
8+
import Foundation
9+
10+
extension ComAtprotoLexicon.Sync {
11+
12+
/// A definition model for enumerating all decentralized identifiers (DIDs) with records
13+
/// in the given collection's Namespace Identifier (NSID).
14+
///
15+
/// - Note: According to the AT Protocol specifications: "Enumerates all the DIDs which have
16+
/// records with the given collection NSID."
17+
///
18+
/// - SeeAlso: This is based on the [`com.atproto.sync.listReposByCollection`][github] lexicon.
19+
///
20+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/sync/listReposByCollection.json
21+
public struct ListRepositoriesByCollection: Sendable, Codable {
22+
23+
/// A repository.
24+
public struct Repository: Sendable, Codable {
25+
26+
/// The decentralized identifier of the repository.
27+
public let did: String
28+
}
29+
}
30+
31+
/// An output model for enumerating all decentralized identifiers (DIDs) with records
32+
/// in the given collection's Namespace Identifiers (NSID).
33+
///
34+
/// - Note: According to the AT Protocol specifications: "Enumerates all the DIDs which have
35+
/// records with the given collection NSID."
36+
///
37+
/// - SeeAlso: This is based on the [`com.atproto.sync.listReposByCollection`][github] lexicon.
38+
///
39+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/sync/listReposByCollection.json
40+
public struct ListRepositoriesByCollectionOutput: Sendable, Codable {
41+
42+
/// The mark used to indicate the starting point for the next set of results. Optional.
43+
public let cursor: String?
44+
45+
/// An array of repositories.
46+
public let repositories: [ListRepositoriesByCollection.Repository]
47+
}
48+
}

Sources/ATProtoKit/Models/Lexicons/tools.ozone/Moderation/ToolsOzoneModerationDefs.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,4 +1708,63 @@ extension ToolsOzoneLexicon.Moderation {
17081708
case unknown
17091709
}
17101710
}
1711+
1712+
/// A definition model for the reporter's statistics.
1713+
///
1714+
/// - SeeAlso: This is based on the [`tools.ozone.moderation.defs`][github] lexicon.
1715+
///
1716+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/admin/defs.json
1717+
public struct ReporterStatsDefinition: Sendable, Codable {
1718+
1719+
/// The decentralized identifier (DID) of the reporter.
1720+
public let did: String
1721+
1722+
/// The number of reports made by the user on accounts.
1723+
///
1724+
/// - Note: According to the AT Protocol specifications: "The total number of reports made
1725+
/// by the user on accounts."
1726+
public let accountReportCount: Int
1727+
1728+
/// The number of reports made by the user.
1729+
///
1730+
/// - Note: According to the AT Protocol specifications: "The total number of reports made
1731+
/// by the user on records."
1732+
public let recordReportCount: Int
1733+
1734+
/// The number of accounts reported by the user.
1735+
///
1736+
/// - Note: According to the AT Protocol specifications: "The total number of accounts
1737+
/// reported by the user."
1738+
public let reportedAccountCount: Int
1739+
1740+
/// The number of records reported by the user.
1741+
///
1742+
/// - Note: According to the AT Protocol specifications: "The total number of records
1743+
/// reported by the user."
1744+
public let reportedRecordCount: Int
1745+
1746+
/// The number of accounts taken down due to user reports.
1747+
///
1748+
/// - Note: According to the AT Protocol specifications: "The total number of accounts
1749+
/// taken down as a result of the user's reports."
1750+
public let takendownAccountCount: Int
1751+
1752+
/// The number of records taken down due to user reports.
1753+
///
1754+
/// - Note: According to the AT Protocol specifications: "The total number of records
1755+
/// taken down as a result of the user's reports."
1756+
public let takendownRecordCount: Int
1757+
1758+
/// The number of accounts labeled by the user’s reports.
1759+
///
1760+
/// - Note: According to the AT Protocol specifications: "The total number of accounts
1761+
/// labeled as a result of the user's reports."
1762+
public let labeledAccountCount: Int
1763+
1764+
/// The number of records labeled based on user reports.
1765+
///
1766+
/// - Note: According to the AT Protocol specifications: "The total number of records
1767+
/// labeled as a result of the user's reports."
1768+
public let labeledRecordCount: Int
1769+
}
17111770
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// ToolsOzoneModeratorGetReporterStats.swift
3+
//
4+
//
5+
// Created by Christopher Jr Riley on 2025-02-20.
6+
//
7+
8+
import Foundation
9+
10+
extension ToolsOzoneLexicon.Moderation {
11+
12+
/// An output model for retrieving statistics about reporters for a list of users.
13+
///
14+
/// - Note: According to the AT Protocol specifications: "Get reporter stats for a list
15+
/// of users."
16+
///
17+
/// - SeeAlso: This is based on the [`tools.ozone.moderation.getReporterStats`][github] lexicon.
18+
///
19+
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/tools/ozone/moderation/getReporterStats.json
20+
public struct GetReporterStatsOutput: Sendable, Codable {
21+
22+
/// An array of reporter statistics.
23+
public let stats: [ToolsOzoneLexicon.Moderation.ReporterStatsDefinition]
24+
}
25+
}

0 commit comments

Comments
 (0)