Skip to content

Commit

Permalink
Merge pull request #275 from technicat/relationship-with-suspended
Browse files Browse the repository at this point in the history
added optional withSuspended param to TootClient.getRelationships (specifies whether to ignore suspended accounts)
  • Loading branch information
davidgarywood committed Apr 17, 2024
2 parents 0fea7ec + 527c35a commit aecaeb4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions 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 }
}
}
4 changes: 2 additions & 2 deletions Sources/TootSDK/TootClient/TootClient+Relationships.swift
Expand Up @@ -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)
}
Expand Down

0 comments on commit aecaeb4

Please sign in to comment.