Skip to content

Commit bd15190

Browse files
committed
feat: apply safe decoding array to url strings array
1 parent ebf2911 commit bd15190

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

Sources/VRCKit/Models/FriendModel.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension Friend: ProfileElementRepresentable, LocationRepresentable {}
1111

1212
public struct Friend {
1313
public let bio: String?
14-
public var bioLinks: [String]
14+
public var bioLinks: SafeDecodingArray<URL>
1515
public let currentAvatarImageUrl: String?
1616
public let currentAvatarThumbnailImageUrl: String?
1717
public let displayName: String
@@ -26,14 +26,16 @@ public struct Friend {
2626
public let userIcon: String?
2727
public let location: String
2828
public let friendKey: String
29-
3029
}
3130

3231
extension Friend: Codable {
3332
public init(from decoder: any Decoder) throws {
3433
let container = try decoder.container(keyedBy: CodingKeys.self)
3534
self.bio = try container.decodeIfPresent(String.self, forKey: .bio)
36-
self.bioLinks = try container.decodeIfPresent([String].self, forKey: .bioLinks) ?? []
35+
self.bioLinks = try container.decodeIfPresent(
36+
SafeDecodingArray<URL>.self,
37+
forKey: .bioLinks
38+
) ?? SafeDecodingArray(elements: [])
3739
self.currentAvatarImageUrl = try container.decodeIfPresent(String.self, forKey: .currentAvatarImageUrl)
3840
self.currentAvatarThumbnailImageUrl = try container.decodeIfPresent(
3941
String.self,

Sources/VRCKit/Models/UserDetailModel.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public typealias Tag = String
1313

1414
public struct UserDetail {
1515
public var bio: String?
16-
public var bioLinks: [String]
16+
public var bioLinks: SafeDecodingArray<URL>
1717
public let currentAvatarImageUrl: String?
1818
public let currentAvatarThumbnailImageUrl: String?
1919
public let displayName: String
@@ -38,7 +38,10 @@ extension UserDetail: Codable {
3838
public init(from decoder: any Decoder) throws {
3939
let container = try decoder.container(keyedBy: CodingKeys.self)
4040
bio = try container.decodeIfPresent(String.self, forKey: .bio)
41-
bioLinks = try container.decodeIfPresent([String].self, forKey: .bioLinks) ?? []
41+
bioLinks = try container.decodeIfPresent(
42+
SafeDecodingArray<URL>.self,
43+
forKey: .bioLinks
44+
) ?? SafeDecodingArray(elements: [])
4245
currentAvatarImageUrl = try container.decodeIfPresent(String.self, forKey: .currentAvatarImageUrl)
4346
currentAvatarThumbnailImageUrl = try container.decodeIfPresent(
4447
String.self,
@@ -72,7 +75,7 @@ public struct EditableUserInfo: Codable, Hashable {
7275

7376
public init(detail: any ProfileDetailRepresentable) {
7477
self.bio = detail.bio ?? ""
75-
self.bioLinks = []
78+
self.bioLinks = detail.bioLinks.elements
7679
self.status = detail.status
7780
self.statusDescription = detail.statusDescription
7881
self.tags = detail.tags

Sources/VRCKit/Models/UserModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct User: ProfileDetailRepresentable {
1111
public let activeFriends: [String]
1212
public let allowAvatarCopying: Bool
1313
public let bio: String?
14-
public var bioLinks: [String]
14+
public var bioLinks: SafeDecodingArray<URL>
1515
public let currentAvatar: String
1616
public let currentAvatarAssetUrl: String
1717
public let currentAvatarImageUrl: String?
@@ -60,7 +60,10 @@ extension User: Codable {
6060
self.activeFriends = try container.decode([String].self, forKey: .activeFriends)
6161
self.allowAvatarCopying = try container.decode(Bool.self, forKey: .allowAvatarCopying)
6262
self.bio = try container.decodeIfPresent(String.self, forKey: .bio)
63-
self.bioLinks = try container.decodeIfPresent([String].self, forKey: .bioLinks) ?? []
63+
self.bioLinks = try container.decodeIfPresent(
64+
SafeDecodingArray<URL>.self,
65+
forKey: .bioLinks
66+
) ?? SafeDecodingArray(elements: [])
6467
self.currentAvatar = try container.decode(String.self, forKey: .currentAvatar)
6568
self.currentAvatarAssetUrl = try container.decode(String.self, forKey: .currentAvatarAssetUrl)
6669
self.currentAvatarImageUrl = try container.decodeIfPresent(String.self, forKey: .currentAvatarImageUrl)

Sources/VRCKit/PreviewServices/PreviewDataProvider.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class PreviewDataProvider {
6363
activeFriends: onlineFriends.map(\.id),
6464
allowAvatarCopying: false,
6565
bio: "This is the demo user.",
66-
bioLinks: [],
66+
bioLinks: SafeDecodingArray(elements: []),
6767
currentAvatar: "",
6868
currentAvatarAssetUrl: "",
6969
currentAvatarImageUrl: "",
@@ -120,7 +120,7 @@ final class PreviewDataProvider {
120120
) -> Friend {
121121
Friend(
122122
bio: nil,
123-
bioLinks: [],
123+
bioLinks: SafeDecodingArray(elements: []),
124124
currentAvatarImageUrl: nil,
125125
currentAvatarThumbnailImageUrl: nil,
126126
displayName: "User_\(id.uuidString.prefix(8))",
@@ -147,7 +147,7 @@ final class PreviewDataProvider {
147147
) -> UserDetail {
148148
UserDetail(
149149
bio: "Demo",
150-
bioLinks: [],
150+
bioLinks: SafeDecodingArray(elements: []),
151151
currentAvatarImageUrl: nil,
152152
currentAvatarThumbnailImageUrl: nil,
153153
displayName: "User_\(id.uuidString.prefix(8))",

Sources/VRCKit/Protocols/ProfileProtocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
/// This protocol can be adopted by structures such as User, Friend, and UserDetail.
1212
public protocol ProfileElementRepresentable: Hashable, Identifiable {
1313
var bio: String? { get }
14-
var bioLinks: [String] { get }
14+
var bioLinks: SafeDecodingArray<URL> { get }
1515
var currentAvatarImageUrl: String? { get }
1616
var currentAvatarThumbnailImageUrl: String? { get }
1717
var displayName: String { get }

0 commit comments

Comments
 (0)