diff --git a/Sources/TootSDK/Models/RelationshipParams.swift b/Sources/TootSDK/Models/RelationshipParams.swift new file mode 100644 index 00000000..91a859d8 --- /dev/null +++ b/Sources/TootSDK/Models/RelationshipParams.swift @@ -0,0 +1,28 @@ +// +// RelationshipParams.swift +// +// +// Created by Philip Chu on 4/5/24. +// + +import Foundation + +public struct RelationshipParams: Codable, Sendable { + + /// Whether relationships should be returned for suspended users, defaults to false. + public var withSuspended: Bool? + + public init(withSuspended: Bool? = nil) { + self.withSuspended = withSuspended + } +} + +extension RelationshipParams { + var queryItems: [URLQueryItem] { + [ + URLQueryItem( + name: "with_suspended", + value: withSuspended?.description) + ].filter { $0.value != nil } + } +} diff --git a/Sources/TootSDK/TootClient/TootClient+Relationships.swift b/Sources/TootSDK/TootClient/TootClient+Relationships.swift index d1849e65..d0947e81 100644 --- a/Sources/TootSDK/TootClient/TootClient+Relationships.swift +++ b/Sources/TootSDK/TootClient/TootClient+Relationships.swift @@ -224,11 +224,11 @@ extension TootClient { /// Find out whether a given account is followed, blocked, muted, etc. /// - Parameter id: the ID of the Account in the instance database. /// - Returns: the relationship to the account requested, or an error if unable to retrieve - public func getRelationships(by ids: [String]) async throws -> [Relationship] { + public func getRelationships(by ids: [String], params: RelationshipParams = .init()) async throws -> [Relationship] { let req = HTTPRequestBuilder { $0.url = getURL(["api", "v1", "accounts", "relationships"]) $0.method = .get - $0.query = ids.map({ URLQueryItem(name: "id[]", value: $0) }) + $0.query = ids.map({ URLQueryItem(name: "id[]", value: $0) }) + params.queryItems } return try await fetch([Relationship].self, req) }