Skip to content

Commit c55f54a

Browse files
authored
Merge pull request #245 from mcprostar205/main
Backfill additional missing initializers: init, decode, and encode
2 parents e606193 + bf2d63e commit c55f54a

2 files changed

Lines changed: 224 additions & 6 deletions

File tree

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedDefs.swift

Lines changed: 182 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ extension AppBskyLexicon.Feed {
6565
///
6666
/// - Note: According to the AT Protocol specifications: "Debug information for internal development."
6767
public let debug: UnknownType?
68-
68+
6969
public init(from decoder: any Decoder) throws {
7070
let container = try decoder.container(keyedBy: CodingKeys.self)
7171

@@ -226,6 +226,38 @@ extension AppBskyLexicon.Feed {
226226
/// Indicates whether the post record is pinned. Optional.
227227
public let isPinned: Bool?
228228

229+
public init(repostURI: String?, likeURI: String?, isBookmarked: Bool?, isThreadMuted: Bool?, areRepliesDisabled: Bool?, isEmbeddingDisabled: Bool?, isPinned: Bool?) {
230+
self.repostURI = repostURI
231+
self.likeURI = likeURI
232+
self.isBookmarked = isBookmarked
233+
self.isThreadMuted = isThreadMuted
234+
self.areRepliesDisabled = areRepliesDisabled
235+
self.isEmbeddingDisabled = isEmbeddingDisabled
236+
self.isPinned = isPinned
237+
}
238+
239+
public init(from decoder: any Decoder) throws {
240+
let container = try decoder.container(keyedBy: CodingKeys.self)
241+
self.repostURI = try container.decodeIfPresent(String.self, forKey: .repostURI)
242+
self.likeURI = try container.decodeIfPresent(String.self, forKey: .likeURI)
243+
self.isBookmarked = try container.decodeIfPresent(Bool.self, forKey: .isBookmarked)
244+
self.isThreadMuted = try container.decodeIfPresent(Bool.self, forKey: .isThreadMuted)
245+
self.areRepliesDisabled = try container.decodeIfPresent(Bool.self, forKey: .areRepliesDisabled)
246+
self.isEmbeddingDisabled = try container.decodeIfPresent(Bool.self, forKey: .isEmbeddingDisabled)
247+
self.isPinned = try container.decodeIfPresent(Bool.self, forKey: .isPinned)
248+
}
249+
250+
public func encode(to encoder: any Encoder) throws {
251+
var container = encoder.container(keyedBy: CodingKeys.self)
252+
try container.encodeIfPresent(self.repostURI, forKey: .repostURI)
253+
try container.encodeIfPresent(self.likeURI, forKey: .likeURI)
254+
try container.encodeIfPresent(self.isBookmarked, forKey: .isBookmarked)
255+
try container.encodeIfPresent(self.isThreadMuted, forKey: .isThreadMuted)
256+
try container.encodeIfPresent(self.areRepliesDisabled, forKey: .areRepliesDisabled)
257+
try container.encodeIfPresent(self.isEmbeddingDisabled, forKey: .isEmbeddingDisabled)
258+
try container.encodeIfPresent(self.isPinned, forKey: .isPinned)
259+
}
260+
229261
enum CodingKeys: String, CodingKey {
230262
case repostURI = "repost"
231263
case likeURI = "like"
@@ -248,6 +280,24 @@ extension AppBskyLexicon.Feed {
248280

249281
/// The URI of the root author's like record.
250282
public let rootAuthorLike: String?
283+
284+
public init(rootAuthorLike: String?) {
285+
self.rootAuthorLike = rootAuthorLike
286+
}
287+
288+
public init(from decoder: any Decoder) throws {
289+
let container = try decoder.container(keyedBy: CodingKeys.self)
290+
self.rootAuthorLike = try container.decodeIfPresent(String.self, forKey: .rootAuthorLike)
291+
}
292+
293+
public func encode(to encoder: any Encoder) throws {
294+
var container = encoder.container(keyedBy: CodingKeys.self)
295+
try container.encodeIfPresent(self.rootAuthorLike, forKey: .rootAuthorLike)
296+
}
297+
298+
public enum CodingKeys: CodingKey {
299+
case rootAuthorLike
300+
}
251301
}
252302

253303
/// A definition model for a feed's view.
@@ -280,6 +330,22 @@ extension AppBskyLexicon.Feed {
280330
/// passed back alongside interactions."
281331
public let requestID: String?
282332

333+
public init(post: PostViewDefinition, reply: ReplyReferenceDefinition? = nil, reason: ReasonUnion? = nil, feedContext: String? = nil, requestID: String? = nil) {
334+
self.post = post
335+
self.reply = reply
336+
self.reason = reason
337+
self.feedContext = feedContext
338+
self.requestID = requestID
339+
}
340+
public init(from decoder: any Decoder) throws {
341+
let container = try decoder.container(keyedBy: CodingKeys.self)
342+
self.post = try container.decode(AppBskyLexicon.Feed.PostViewDefinition.self, forKey: .post)
343+
self.reply = try container.decodeIfPresent(AppBskyLexicon.Feed.ReplyReferenceDefinition.self, forKey: .reply)
344+
self.reason = try container.decodeIfPresent(AppBskyLexicon.Feed.FeedViewPostDefinition.ReasonUnion.self, forKey: .reason)
345+
self.feedContext = try container.decodeIfPresent(String.self, forKey: .feedContext)
346+
self.requestID = try container.decodeIfPresent(String.self, forKey: .requestID)
347+
}
348+
283349
public func encode(to encoder: any Encoder) throws {
284350
var container = encoder.container(keyedBy: CodingKeys.self)
285351

@@ -369,6 +435,32 @@ extension AppBskyLexicon.Feed {
369435
/// post, this is the author of that post."
370436
public let grandparentAuthor: AppBskyLexicon.Actor.ProfileViewBasicDefinition?
371437

438+
public init(root: RootUnion, parent: ParentUnion, grandparentAuthor: AppBskyLexicon.Actor.ProfileViewBasicDefinition?) {
439+
self.root = root
440+
self.parent = parent
441+
self.grandparentAuthor = grandparentAuthor
442+
}
443+
444+
public init(from decoder: any Decoder) throws {
445+
let container = try decoder.container(keyedBy: CodingKeys.self)
446+
self.root = try container.decode(AppBskyLexicon.Feed.ReplyReferenceDefinition.RootUnion.self, forKey: .root)
447+
self.parent = try container.decode(AppBskyLexicon.Feed.ReplyReferenceDefinition.ParentUnion.self, forKey: .parent)
448+
self.grandparentAuthor = try container.decodeIfPresent(AppBskyLexicon.Actor.ProfileViewBasicDefinition.self, forKey: .grandparentAuthor)
449+
}
450+
451+
public func encode(to encoder: any Encoder) throws {
452+
var container = encoder.container(keyedBy: CodingKeys.self)
453+
try container.encode(self.root, forKey: .root)
454+
try container.encode(self.parent, forKey: .parent)
455+
try container.encodeIfPresent(self.grandparentAuthor, forKey: .grandparentAuthor)
456+
}
457+
458+
enum CodingKeys: CodingKey {
459+
case root
460+
case parent
461+
case grandparentAuthor
462+
}
463+
372464
// Unions
373465
/// The original post of the thread.
374466
public enum RootUnion: ATUnionProtocol, Equatable, Hashable {
@@ -498,6 +590,13 @@ extension AppBskyLexicon.Feed {
498590
/// The date and time the repost was last indexed.
499591
public let indexedAt: Date
500592

593+
public init(by: AppBskyLexicon.Actor.ProfileViewBasicDefinition, uri: String? = nil, cid: String? = nil, indexedAt: Date) {
594+
self.by = by
595+
self.uri = uri
596+
self.cid = cid
597+
self.indexedAt = indexedAt
598+
}
599+
501600
public init(from decoder: any Decoder) throws {
502601
let container = try decoder.container(keyedBy: CodingKeys.self)
503602

@@ -550,6 +649,36 @@ extension AppBskyLexicon.Feed {
550649
/// The context of the thread view. Optional.
551650
public let threadContext: ThreadContextDefinition?
552651

652+
public init(post: PostViewDefinition, parent: ParentUnion?, replies: [RepliesUnion]?, threadContext: ThreadContextDefinition?) {
653+
self.post = post
654+
self.parent = parent
655+
self.replies = replies
656+
self.threadContext = threadContext
657+
}
658+
659+
public init(from decoder: any Decoder) throws {
660+
let container = try decoder.container(keyedBy: CodingKeys.self)
661+
self.post = try container.decode(AppBskyLexicon.Feed.PostViewDefinition.self, forKey: .post)
662+
self.parent = try container.decodeIfPresent(AppBskyLexicon.Feed.ThreadViewPostDefinition.ParentUnion.self, forKey: .parent)
663+
self.replies = try container.decodeIfPresent([AppBskyLexicon.Feed.ThreadViewPostDefinition.RepliesUnion].self, forKey: .replies)
664+
self.threadContext = try container.decodeIfPresent(AppBskyLexicon.Feed.ThreadContextDefinition.self, forKey: .threadContext)
665+
}
666+
667+
public func encode(to encoder: any Encoder) throws {
668+
var container = encoder.container(keyedBy: CodingKeys.self)
669+
try container.encode(self.post, forKey: .post)
670+
try container.encodeIfPresent(self.parent, forKey: .parent)
671+
try container.encodeIfPresent(self.replies, forKey: .replies)
672+
try container.encodeIfPresent(self.threadContext, forKey: .threadContext)
673+
}
674+
675+
public enum CodingKeys: CodingKey {
676+
case post
677+
case parent
678+
case replies
679+
case threadContext
680+
}
681+
553682
// Unions
554683
/// The direct post that the user's post is replying to.
555684
public indirect enum ParentUnion: ATUnionProtocol, Equatable, Hashable {
@@ -654,7 +783,7 @@ extension AppBskyLexicon.Feed {
654783
}
655784
}
656785

657-
enum CodingKeys: String, CodingKey {
786+
public enum CodingKeys: String, CodingKey {
658787
case type = "$type"
659788
}
660789
}
@@ -673,7 +802,22 @@ extension AppBskyLexicon.Feed {
673802
/// Indicates whether the post wasn't found. Defaults to `true`.
674803
public let isNotFound: Bool = true
675804

676-
enum CodingKeys: String, CodingKey {
805+
public init(feedURI: String) {
806+
self.feedURI = feedURI
807+
}
808+
809+
public init(from decoder: any Decoder) throws {
810+
let container = try decoder.container(keyedBy: CodingKeys.self)
811+
self.feedURI = try container.decode(String.self, forKey: .feedURI)
812+
}
813+
814+
public func encode(to encoder: any Encoder) throws {
815+
var container = encoder.container(keyedBy: CodingKeys.self)
816+
try container.encode(self.feedURI, forKey: .feedURI)
817+
try container.encode(self.isNotFound, forKey: .isNotFound)
818+
}
819+
820+
public enum CodingKeys: String, CodingKey {
677821
case feedURI = "uri"
678822
case isNotFound = "notFound"
679823
}
@@ -709,7 +853,7 @@ extension AppBskyLexicon.Feed {
709853
self.author = try container.decode(BlockedAuthorDefinition.self, forKey: .author)
710854
}
711855

712-
enum CodingKeys: String, CodingKey {
856+
public enum CodingKeys: String, CodingKey {
713857
case feedURI = "uri"
714858
case isBlocked = "blocked"
715859
case author
@@ -729,7 +873,24 @@ extension AppBskyLexicon.Feed {
729873
/// The viewer state of the user. Optional.
730874
public let viewer: AppBskyLexicon.Actor.ViewerStateDefinition?
731875

732-
enum CodingKeys: CodingKey {
876+
public init(did: String, viewer: AppBskyLexicon.Actor.ViewerStateDefinition?) {
877+
self.did = did
878+
self.viewer = viewer
879+
}
880+
881+
public init(from decoder: any Decoder) throws {
882+
let container = try decoder.container(keyedBy: CodingKeys.self)
883+
self.did = try container.decode(String.self, forKey: .did)
884+
self.viewer = try container.decodeIfPresent(AppBskyLexicon.Actor.ViewerStateDefinition.self, forKey: .viewer)
885+
}
886+
887+
public func encode(to encoder: any Encoder) throws {
888+
var container = encoder.container(keyedBy: CodingKeys.self)
889+
try container.encode(self.did, forKey: .did)
890+
try container.encodeIfPresent(self.viewer, forKey: .viewer)
891+
}
892+
893+
public enum CodingKeys: CodingKey {
733894
case did
734895
case viewer
735896
}
@@ -831,7 +992,7 @@ extension AppBskyLexicon.Feed {
831992
try container.encodeDateIfPresent(self.indexedAt, forKey: .indexedAt)
832993
}
833994

834-
enum CodingKeys: String, CodingKey {
995+
public enum CodingKeys: String, CodingKey {
835996
case feedURI = "uri"
836997
case cid
837998
case feedDID = "did"
@@ -1032,6 +1193,21 @@ extension AppBskyLexicon.Feed {
10321193
/// originally supplied by the feed generator on getFeedSkeleton."
10331194
public let feedContext: String?
10341195

1196+
public init(itemURI: String?, event: Event?, requestID: String?, feedContext: String?) {
1197+
self.itemURI = itemURI
1198+
self.event = event
1199+
self.requestID = requestID
1200+
self.feedContext = feedContext
1201+
}
1202+
1203+
public init(from decoder: any Decoder) throws {
1204+
let container = try decoder.container(keyedBy: CodingKeys.self)
1205+
self.itemURI = try container.decodeIfPresent(String.self, forKey: .itemURI)
1206+
self.event = try container.decodeIfPresent(AppBskyLexicon.Feed.InteractionDefinition.Event.self, forKey: .event)
1207+
self.feedContext = try container.decodeIfPresent(String.self, forKey: .feedContext)
1208+
self.requestID = try container.decodeIfPresent(String.self, forKey: .requestID)
1209+
}
1210+
10351211
public func encode(to encoder: any Encoder) throws {
10361212
var container = encoder.container(keyedBy: CodingKeys.self)
10371213

Sources/ATProtoKit/Models/Lexicons/app.bsky/Feed/AppBskyFeedThreadgate.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ extension AppBskyLexicon.Feed {
9595
/// The identifier of the object.
9696
public let type = "app.bsky.feed.threadgate#mentionRule"
9797

98+
public init() { }
99+
100+
public init(from decoder: any Decoder) throws { }
101+
102+
public func encode(to encoder: any Encoder) throws {
103+
var container = encoder.container(keyedBy: CodingKeys.self)
104+
try container.encode(self.type, forKey: .type)
105+
}
106+
98107
enum CodingKeys: String, CodingKey {
99108
case type = "$type"
100109
}
@@ -109,6 +118,15 @@ extension AppBskyLexicon.Feed {
109118
/// The identifier of the object.
110119
public let type = "app.bsky.feed.threadgate#followerRule"
111120

121+
public init() { }
122+
123+
public init(from decoder: any Decoder) throws { }
124+
125+
public func encode(to encoder: any Encoder) throws {
126+
var container = encoder.container(keyedBy: CodingKeys.self)
127+
try container.encode(self.type, forKey: .type)
128+
}
129+
112130
enum CodingKeys: String, CodingKey {
113131
case type = "$type"
114132
}
@@ -122,6 +140,15 @@ extension AppBskyLexicon.Feed {
122140
/// The identifier of the object.
123141
public let type = "app.bsky.feed.threadgate#followingRule"
124142

143+
public init() { }
144+
145+
public init(from decoder: any Decoder) throws { }
146+
147+
public func encode(to encoder: any Encoder) throws {
148+
var container = encoder.container(keyedBy: CodingKeys.self)
149+
try container.encode(self.type, forKey: .type)
150+
}
151+
125152
enum CodingKeys: String, CodingKey {
126153
case type = "$type"
127154
}
@@ -138,6 +165,21 @@ extension AppBskyLexicon.Feed {
138165
/// The list itself.
139166
public let listURI: String
140167

168+
public init(listURI: String) {
169+
self.listURI = listURI
170+
}
171+
172+
public init(from decoder: any Decoder) throws {
173+
let container = try decoder.container(keyedBy: CodingKeys.self)
174+
self.listURI = try container.decode(String.self, forKey: .listURI)
175+
}
176+
177+
public func encode(to encoder: any Encoder) throws {
178+
var container = encoder.container(keyedBy: CodingKeys.self)
179+
try container.encode(self.type, forKey: .type)
180+
try container.encode(self.listURI, forKey: .listURI)
181+
}
182+
141183
enum CodingKeys: String, CodingKey {
142184
case type = "$type"
143185
case listURI = "list"

0 commit comments

Comments
 (0)