From 765e85b66b122b54089b7fcb704dac99f5896a49 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 4 Aug 2024 13:25:44 +0900 Subject: [PATCH 1/4] feat: implement trust rank utility --- Sources/VRCKit/Utils/TrustRank.swift | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Sources/VRCKit/Utils/TrustRank.swift diff --git a/Sources/VRCKit/Utils/TrustRank.swift b/Sources/VRCKit/Utils/TrustRank.swift new file mode 100644 index 0000000..958e61a --- /dev/null +++ b/Sources/VRCKit/Utils/TrustRank.swift @@ -0,0 +1,43 @@ +// +// TrustRank.swift +// VRCKit +// +// Created by makinosp on 2024/08/04. +// + +public enum TrustRank { + case trusted, known, user, newUser, visitor, unknown +} + +public extension ProfileElementRepresentable { + var trustRank: TrustRank { + let rankTags: [SystemTag] = [ + .systemTrustVeteran, + .systemTrustTrusted, + .systemTrustKnown, + .systemTrustBasic + ] + let rankTag = rankTags.first(where: { tags.systemTags.contains($0) }) + guard let rankTag = rankTag else { return .visitor } + return switch rankTag { + case .systemTrustVeteran: .trusted + case .systemTrustTrusted: .known + case .systemTrustKnown: .user + case .systemTrustBasic: .newUser + default: .unknown + } + } +} + +extension TrustRank: CustomStringConvertible { + public var description: String { + switch self { + case .trusted: "Trusted" + case .known: "Known" + case .user: "User" + case .newUser: "New User" + case .visitor: "Visitor" + case .unknown: "Unknown" + } + } +} From 45d073c82aa0646d2aaad8b37405109250bc6fe1 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 4 Aug 2024 13:39:41 +0900 Subject: [PATCH 2/4] refact: split profile image URL utility to the file --- .../VRCKit/Protocols/ProfileProtocols.swift | 20 ------------- Sources/VRCKit/Utils/ProfileImageURL.swift | 28 +++++++++++++++++++ 2 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 Sources/VRCKit/Utils/ProfileImageURL.swift diff --git a/Sources/VRCKit/Protocols/ProfileProtocols.swift b/Sources/VRCKit/Protocols/ProfileProtocols.swift index 53060ba..d799c19 100644 --- a/Sources/VRCKit/Protocols/ProfileProtocols.swift +++ b/Sources/VRCKit/Protocols/ProfileProtocols.swift @@ -34,23 +34,3 @@ public protocol ProfileDetailRepresentable: ProfileElementRepresentable { var lastActivity: Date { get } var state: User.State { get } } - -public extension ProfileElementRepresentable { - var thumbnailUrl: URL? { - if let userIcon = userIcon { - return userIcon - } - guard let url = avatarThumbnailUrl, - let urlString = url.absoluteString.hasSuffix("256") - ? String(url.absoluteString.dropLast(3)) + "512" - : avatarImageUrl?.absoluteString else { return nil } - return URL(string: urlString) - } - - var userIconUrl: URL? { - if let userIcon = userIcon { - return userIcon - } - return avatarThumbnailUrl - } -} diff --git a/Sources/VRCKit/Utils/ProfileImageURL.swift b/Sources/VRCKit/Utils/ProfileImageURL.swift new file mode 100644 index 0000000..eb3a802 --- /dev/null +++ b/Sources/VRCKit/Utils/ProfileImageURL.swift @@ -0,0 +1,28 @@ +// +// ProfileImageURL.swift +// VRCKit +// +// Created by makinosp on 2024/08/04. +// + +import Foundation + +public extension ProfileElementRepresentable { + var thumbnailUrl: URL? { + if let userIcon = userIcon { + return userIcon + } + guard let url = avatarThumbnailUrl, + let urlString = url.absoluteString.hasSuffix("256") + ? String(url.absoluteString.dropLast(3)) + "512" + : avatarImageUrl?.absoluteString else { return nil } + return URL(string: urlString) + } + + var userIconUrl: URL? { + if let userIcon = userIcon { + return userIcon + } + return avatarThumbnailUrl + } +} From 7996c47a991c9511ea7ded31cb0d58b328ea738e Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 4 Aug 2024 13:40:22 +0900 Subject: [PATCH 3/4] refact: lint trailing colosure --- Sources/VRCKit/Utils/TrustRank.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/VRCKit/Utils/TrustRank.swift b/Sources/VRCKit/Utils/TrustRank.swift index 958e61a..88c45e1 100644 --- a/Sources/VRCKit/Utils/TrustRank.swift +++ b/Sources/VRCKit/Utils/TrustRank.swift @@ -17,7 +17,7 @@ public extension ProfileElementRepresentable { .systemTrustKnown, .systemTrustBasic ] - let rankTag = rankTags.first(where: { tags.systemTags.contains($0) }) + let rankTag = rankTags.first { tags.systemTags.contains($0) } guard let rankTag = rankTag else { return .visitor } return switch rankTag { case .systemTrustVeteran: .trusted From 004b43f4f6f1dac6a61b075186c8f9f24bc53722 Mon Sep 17 00:00:00 2001 From: makinosp Date: Sun, 4 Aug 2024 13:47:13 +0900 Subject: [PATCH 4/4] refact: format instance type description --- Sources/VRCKit/Models/InstanceModel.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Sources/VRCKit/Models/InstanceModel.swift b/Sources/VRCKit/Models/InstanceModel.swift index 4922f40..bc78498 100644 --- a/Sources/VRCKit/Models/InstanceModel.swift +++ b/Sources/VRCKit/Models/InstanceModel.swift @@ -44,7 +44,7 @@ public struct Instance: Identifiable, Hashable, Codable { } public extension Instance { - enum InstanceTypeDescription: String { + enum InstanceTypeAlias: String { case `public` = "Public" case friendsPlus = "Friends+" case friends = "Friends" @@ -54,19 +54,20 @@ public extension Instance { case groupPublic = "Group Public" } - var instanceTypeDescription: InstanceTypeDescription { - switch type { + var typeDescription: String { + let instanceTypeAlias: InstanceTypeAlias = switch type { case .public: .public case .hidden: .friendsPlus case .friends: .friends case .private: .private - case .group: groupAccessType?.instanceTypeDescription ?? .group + case .group: groupAccessType?.typeDescription ?? .group } + return instanceTypeAlias.description } } extension Instance.GroupAccessType { - var instanceTypeDescription: Instance.InstanceTypeDescription { + var typeDescription: Instance.InstanceTypeAlias { switch self { case .public: .groupPublic case .plus: .groupPlus @@ -78,6 +79,6 @@ extension Instance.InstanceType: CustomStringConvertible { public var description: String { rawValue } } -extension Instance.InstanceTypeDescription: CustomStringConvertible { +extension Instance.InstanceTypeAlias: CustomStringConvertible { public var description: String { rawValue } }