Skip to content

Commit

Permalink
Add and tweak lexicons for thread management
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterJ93 committed Jun 16, 2024
1 parent d93cfea commit ac1d8f2
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,18 @@

- ``MuteActorListRequestBody``

### app.bsky.graph.muteThread

- ``MuteThreadRequestBody``

### app.bsky.graph.unmuteActor

- ``UnmuteActorRequestBody``

### app.bsky.graph.unmuteActorList

- ``UnmuteActorListRequestBody``

### app.bsky.graph.unmuteThread

= ``UnmuteThreadRequestBody``
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
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
}
}
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 Sources/ATProtoKit/Networking/PlatformAPI/MuteThread.swift
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 Sources/ATProtoKit/Networking/PlatformAPI/UnmuteThread.swift
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
}
}
}

0 comments on commit ac1d8f2

Please sign in to comment.