Skip to content

Commit 93e43a5

Browse files
committed
feat: implement custom decoder for user tags
1 parent ae20e6a commit 93e43a5

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

Sources/VRCKit/Models/UserDetailModel.swift

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
import Foundation
99

10-
extension UserDetail: ProfileDetailRepresentable, LocationRepresentable {}
11-
1210
public typealias Tag = String
1311

14-
public struct UserDetail {
12+
public struct UserDetail: ProfileDetailRepresentable, LocationRepresentable {
1513
public var bio: String?
1614
public var bioLinks: SafeDecodingArray<URL>
1715
public let avatarImageUrl: URL?
@@ -25,17 +23,49 @@ public struct UserDetail {
2523
public let state: User.State
2624
public let status: UserStatus
2725
public var statusDescription: String
28-
public var tags: [Tag]
26+
public var tags: Tags
2927
public let userIcon: URL?
3028
public let location: String
3129
public let friendKey: String
3230
public let dateJoined: String
3331
public var note: String
3432
public let lastActivity: Date
33+
34+
public struct Tags: Codable, Hashable {
35+
let systemTags: [SystemTag]
36+
var languageTags: [LanguageTag]
37+
}
38+
}
39+
40+
public extension UserDetail.Tags {
41+
init() {
42+
systemTags = []
43+
languageTags = []
44+
}
45+
}
46+
47+
public extension UserDetail.Tags {
48+
init(from decoder: Decoder) throws {
49+
var systemTags: [SystemTag] = []
50+
var languageTags: [LanguageTag] = []
51+
var container = try decoder.unkeyedContainer()
52+
while !container.isAtEnd {
53+
let systemTag = try? container.decode(SystemTag.self)
54+
let languageTag = try? container.decode(LanguageTag.self)
55+
if let systemTag = systemTag {
56+
systemTags.append(systemTag)
57+
}
58+
if let languageTag = languageTag {
59+
languageTags.append(languageTag)
60+
}
61+
}
62+
self.systemTags = systemTags
63+
self.languageTags = languageTags
64+
}
3565
}
3666

3767
extension UserDetail: Codable {
38-
public init(from decoder: any Decoder) throws {
68+
public init(from decoder: Decoder) throws {
3969
let container = try decoder.container(keyedBy: CodingKeys.self)
4070
bio = try container.decodeIfPresent(String.self, forKey: .bio)
4171
bioLinks = try container.decodeSafeNullableArray(URL.self, forKey: .bioLinks)
@@ -50,7 +80,7 @@ extension UserDetail: Codable {
5080
state = try container.decode(User.State.self, forKey: .state)
5181
status = try container.decode(UserStatus.self, forKey: .status)
5282
statusDescription = try container.decode(String.self, forKey: .statusDescription)
53-
tags = try container.decode([Tag].self, forKey: .tags)
83+
tags = try container.decode(Tags.self, forKey: .tags)
5484
userIcon = try? container.decodeIfPresent(URL.self, forKey: .userIcon)
5585
location = try container.decode(String.self, forKey: .location)
5686
friendKey = try container.decode(String.self, forKey: .friendKey)
@@ -99,6 +129,7 @@ public extension EditableUserInfo {
99129
bioLinks = detail.bioLinks.elements
100130
status = detail.status
101131
statusDescription = detail.statusDescription
102-
tags = detail.tags
132+
// tags = detail.tags
133+
tags = []
103134
}
104135
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// UserTagModel.swift
3+
// VRCKit
4+
//
5+
// Created by makinosp on 2024/08/03.
6+
//
7+
8+
import Foundation
9+
10+
public enum SystemTag: String, Hashable, Codable {
11+
case adminAvatarAccess = "admin_avatar_access"
12+
case adminCanGrantLicenses = "admin_can_grant_licenses"
13+
case adminCannyAccess = "admin_canny_access"
14+
case adminLockTags = "admin_lock_tags"
15+
case adminLockLevel = "admin_lock_level"
16+
case adminModerator = "admin_moderator"
17+
case adminOfficialThumbnail = "admin_official_thumbnail"
18+
case adminScriptingAccess = "admin_scripting_access"
19+
case adminWorldAccess = "admin_world_access"
20+
case showSocialRank = "show_social_rank"
21+
case showModTag = "show_mod_tag"
22+
case systemAvatarAccess = "system_avatar_access"
23+
case systemEarlyAdopter = "system_early_adopter"
24+
case systemFeedbackAccess = "system_feedback_access"
25+
case systemProbableTroll = "system_probable_troll"
26+
case systemSupporter = "system_supporter"
27+
case systemTroll = "system_troll"
28+
case systemTrustBasic = "system_trust_basic"
29+
case systemTrustKnown = "system_trust_known"
30+
case systemTrustTrusted = "system_trust_trusted"
31+
case systemTrustVeteran = "system_trust_veteran"
32+
case systemWorldAccess = "system_world_access"
33+
}
34+
35+
public enum LanguageTag: String, Hashable, Codable {
36+
case english = "language_eng"
37+
case korean = "language_kor"
38+
case russian = "language_rus"
39+
case spanish = "language_spa"
40+
case portuguese = "language_por"
41+
case chinese = "language_zho"
42+
case german = "language_deu"
43+
case japanese = "language_jpn"
44+
case french = "language_fra"
45+
case swedish = "language_swe"
46+
case dutch = "language_nld"
47+
case polish = "language_pol"
48+
case danish = "language_dan"
49+
case norwegian = "language_nor"
50+
case italian = "language_ita"
51+
case thai = "language_tha"
52+
case finnish = "language_fin"
53+
case hungarian = "language_hun"
54+
case czech = "language_ces"
55+
case turkish = "language_tur"
56+
case arabic = "language_ara"
57+
case romanian = "language_ron"
58+
case vietnamese = "language_vie"
59+
case americanSignLanguage = "language_ase"
60+
case britishSignLanguage = "language_bfi"
61+
case dutchSignLanguage = "language_dse"
62+
case frenchSignLanguage = "language_fsl"
63+
case japaneseSignLanguage = "language_jsl"
64+
case koreanSignLanguage = "language_kvk"
65+
}

Sources/VRCKit/PreviewServices/PreviewDataProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ final class PreviewDataProvider {
158158
state: state,
159159
status: status,
160160
statusDescription: "Demo",
161-
tags: [],
161+
tags: UserDetail.Tags(),
162162
userIcon: URL(string: "https://ul.h3z.jp/9gGIcerr.png"),
163163
location: location,
164164
friendKey: "",

Sources/VRCKit/Protocols/ProfileProtocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public protocol ProfileElementRepresentable: Hashable, Identifiable {
2222
var profilePicOverride: URL? { get }
2323
var status: UserStatus { get }
2424
var statusDescription: String { get }
25-
var tags: [Tag] { get }
25+
// var tags: [Tag] { get }
2626
var userIcon: URL? { get }
2727
var friendKey: String { get }
2828
}

0 commit comments

Comments
 (0)