Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/relationships-blocking-by-list-key.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@germ-network/atprotoclient": patch
---

`Relationships` now decodes and encodes `blockingByList` under the lexicon's key. It used `blockingbyList`, so the viewer's own list blocks never decoded.
3 changes: 2 additions & 1 deletion Sources/AtprotoClient/Lexicon/AppBsky/Graph/GraphDefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ extension Lexicon.App.Bsky.Graph {
case following
case followedBy
case blockedByList
case blockingbyList
// The property name's casing is a typo kept for source compatibility.
case blockingbyList = "blockingByList"
}

public init(
Expand Down
43 changes: 43 additions & 0 deletions Tests/AtprotoClientTests/GetRelationshipsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,46 @@ private func xrpcURL(
#expect(collector.all.flatMap { $0 } == subjects.map(\.rawValue))
}
}

@Suite struct RelationshipsCodingTests {
@Test("Decodes the lexicon's camel-cased list-block keys")
func decodesListBlockKeys() throws {
let json = """
{
"$type": "app.bsky.graph.defs#relationship",
"did": "did:plc:subject",
"blockedByList": "at://did:plc:subject/app.bsky.graph.listblock/a",
"blockingByList": "at://did:plc:actor/app.bsky.graph.listblock/b"
}
"""
let relationship = try JSONDecoder().decode(
Lexicon.App.Bsky.Graph.Relationships.self,
from: Data(json.utf8)
)
#expect(
relationship.blockedByList?.rawValue
== "at://did:plc:subject/app.bsky.graph.listblock/a")
#expect(
relationship.blockingbyList?.rawValue
== "at://did:plc:actor/app.bsky.graph.listblock/b")
}

@Test("Encodes blockingByList under the lexicon's key")
func encodesBlockingByListKey() throws {
let relationship = Lexicon.App.Bsky.Graph.Relationships(
did: .init(method: .plc, identifier: "subject"),
blocking: nil,
blockedBy: nil,
following: nil,
followedBy: nil,
blockedByList: nil,
blockingbyList: try .init(
string: "at://did:plc:actor/app.bsky.graph.listblock/b")
)
let object = try #require(
JSONSerialization.jsonObject(with: JSONEncoder().encode(relationship))
as? [String: Any])
#expect(object["blockingByList"] != nil)
#expect(object["blockingbyList"] == nil)
}
}
Loading