From ac1d8f26cddc430f2fe1c30f91325e42f9b96030 Mon Sep 17 00:00:00 2001 From: Christopher Jr Riley Date: Sun, 16 Jun 2024 09:22:42 -0400 Subject: [PATCH] Add and tweak lexicons for thread management --- .../Lexicons/Models/app.bsky/AppBskyGraph.md | 8 +++ .../app.bsky/Feed/AppBskyFeedDefs.swift | 4 ++ .../Graph/AppBskyGraphMuteThread.swift | 26 ++++++++++ .../Graph/AppBskyGraphUnmuteThread.swift | 25 +++++++++ .../Networking/PlatformAPI/MuteThread.swift | 51 +++++++++++++++++++ .../Networking/PlatformAPI/UnmuteThread.swift | 50 ++++++++++++++++++ 6 files changed, 164 insertions(+) create mode 100644 Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphMuteThread.swift create mode 100644 Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphUnmuteThread.swift create mode 100644 Sources/ATProtoKit/Networking/PlatformAPI/MuteThread.swift create mode 100644 Sources/ATProtoKit/Networking/PlatformAPI/UnmuteThread.swift diff --git a/Sources/ATProtoKit/ATProtoKit.docc/Extensions/Lexicons/Models/app.bsky/AppBskyGraph.md b/Sources/ATProtoKit/ATProtoKit.docc/Extensions/Lexicons/Models/app.bsky/AppBskyGraph.md index ff4ef4f16f..49c5164d85 100644 --- a/Sources/ATProtoKit/ATProtoKit.docc/Extensions/Lexicons/Models/app.bsky/AppBskyGraph.md +++ b/Sources/ATProtoKit/ATProtoKit.docc/Extensions/Lexicons/Models/app.bsky/AppBskyGraph.md @@ -80,6 +80,10 @@ - ``MuteActorListRequestBody`` +### app.bsky.graph.muteThread + +- ``MuteThreadRequestBody`` + ### app.bsky.graph.unmuteActor - ``UnmuteActorRequestBody`` @@ -87,3 +91,7 @@ ### app.bsky.graph.unmuteActorList - ``UnmuteActorListRequestBody`` + +### app.bsky.graph.unmuteThread + += ``UnmuteThreadRequestBody`` diff --git a/Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedDefs.swift b/Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedDefs.swift index 76d60689bc..baf1ce6f09 100644 --- a/Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedDefs.swift +++ b/Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedDefs.swift @@ -136,12 +136,16 @@ extension AppBskyLexicon.Feed { /// The URI of the requesting account's like of the subject account's post. Optional. public let likeURI: String? + /// Indicates whether the thread has been muted. + public let isThreadMuted: Bool + /// Indicates whether the requesting account can reply to the account's post. Optional. public let areRepliesDisabled: Bool? enum CodingKeys: String, CodingKey { case repostURI = "repost" case likeURI = "like" + case isThreadMuted = "threadMuted" case areRepliesDisabled = "replyDisabled" } } diff --git a/Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphMuteThread.swift b/Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphMuteThread.swift new file mode 100644 index 0000000000..aa46e8dc40 --- /dev/null +++ b/Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphMuteThread.swift @@ -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 + } +} diff --git a/Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphUnmuteThread.swift b/Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphUnmuteThread.swift new file mode 100644 index 0000000000..884050bd4f --- /dev/null +++ b/Sources/ATProtoKit/Models/Lexicons/app.bsky/Graph/AppBskyGraphUnmuteThread.swift @@ -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 + } +} diff --git a/Sources/ATProtoKit/Networking/PlatformAPI/MuteThread.swift b/Sources/ATProtoKit/Networking/PlatformAPI/MuteThread.swift new file mode 100644 index 0000000000..c14f923511 --- /dev/null +++ b/Sources/ATProtoKit/Networking/PlatformAPI/MuteThread.swift @@ -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 + } + } +} diff --git a/Sources/ATProtoKit/Networking/PlatformAPI/UnmuteThread.swift b/Sources/ATProtoKit/Networking/PlatformAPI/UnmuteThread.swift new file mode 100644 index 0000000000..ed3119f8f8 --- /dev/null +++ b/Sources/ATProtoKit/Networking/PlatformAPI/UnmuteThread.swift @@ -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 + } + } +}