-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and tweak lexicons for thread management
- Loading branch information
Showing
6 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphMuteThread.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// AppBskyGraphMuteThread.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-06-16. | ||
// | ||
|
||
import Foundation | ||
|
||
extension AppBskyLexicon.Graph { | ||
|
||
/// A request body model for muting a thread. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Mutes a thread preventing | ||
/// notifications from the thread and any of its children. Mutes are private in Bluesky. | ||
/// Requires auth." | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.graph.muteThread`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/graph/muteThread.json | ||
public struct MuteThreadRequestBody: Codable { | ||
|
||
/// The URI of the root of the post. | ||
public let root: String | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphUnmuteThread.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// AppBskyGraphUnmuteThread.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-06-16. | ||
// | ||
|
||
import Foundation | ||
|
||
extension AppBskyLexicon.Graph { | ||
|
||
/// A request body model for unmuting a thread. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: ""Unmutes the specified thread. | ||
/// Requires auth" | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.graph.unmuteThread`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/graph/unmuteThread.json | ||
public struct UnmuteThreadRequestBody: Codable { | ||
|
||
/// The URI of the root of the post. | ||
public let root: String | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Sources/ATProtoKit/Networking/PlatformAPI/MuteThread.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// MuteThread.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-06-16. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ATProtoKit { | ||
|
||
/// Mutes a thread. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: "Mutes a thread preventing | ||
/// notifications from the thread and any of its children. Mutes are private in Bluesky. | ||
/// Requires auth." | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.graph.muteThread`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/graph/muteThread.json | ||
/// | ||
/// - Parameter root: The URI of the root of the post. | ||
public func muteThread(_ root: String) async throws { | ||
guard session != nil, | ||
let accessToken = session?.accessToken else { | ||
throw ATRequestPrepareError.missingActiveSession | ||
} | ||
|
||
guard let sessionURL = session?.pdsURL, | ||
let requestURL = URL(string: "\(sessionURL)/xrpc/app.bsky.graph.muteThread") else { | ||
throw ATRequestPrepareError.invalidRequestURL | ||
} | ||
|
||
let requestBody = AppBskyLexicon.Graph.MuteThreadRequestBody( | ||
root: root | ||
) | ||
|
||
do { | ||
let request = APIClientService.createRequest(forRequest: requestURL, | ||
andMethod: .get, | ||
acceptValue: "application/json", | ||
contentTypeValue: nil, | ||
authorizationValue: "Bearer \(accessToken)") | ||
|
||
try await APIClientService.sendRequest(request, | ||
withEncodingBody: requestBody) | ||
} catch { | ||
throw error | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
Sources/ATProtoKit/Networking/PlatformAPI/UnmuteThread.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// UnmuteThread.swift | ||
// | ||
// | ||
// Created by Christopher Jr Riley on 2024-06-16. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ATProtoKit { | ||
|
||
/// Unmutes a thread. | ||
/// | ||
/// - Note: According to the AT Protocol specifications: ""Unmutes the specified thread. | ||
/// Requires auth" | ||
/// | ||
/// - SeeAlso: This is based on the [`app.bsky.graph.unmuteThread`][github] lexicon. | ||
/// | ||
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/app/bsky/graph/unmuteThread.json | ||
/// | ||
/// - Parameter root: The URI of the root of the post. | ||
public func unmuteThread(_ root: String) async throws { | ||
guard session != nil, | ||
let accessToken = session?.accessToken else { | ||
throw ATRequestPrepareError.missingActiveSession | ||
} | ||
|
||
guard let sessionURL = session?.pdsURL, | ||
let requestURL = URL(string: "\(sessionURL)/xrpc/app.bsky.graph.unmuteThread") else { | ||
throw ATRequestPrepareError.invalidRequestURL | ||
} | ||
|
||
let requestBody = AppBskyLexicon.Graph.UnmuteThreadRequestBody( | ||
root: root | ||
) | ||
|
||
do { | ||
let request = APIClientService.createRequest(forRequest: requestURL, | ||
andMethod: .get, | ||
acceptValue: "application/json", | ||
contentTypeValue: nil, | ||
authorizationValue: "Bearer \(accessToken)") | ||
|
||
try await APIClientService.sendRequest(request, | ||
withEncodingBody: requestBody) | ||
} catch { | ||
throw error | ||
} | ||
} | ||
} |