Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #66

Merged
merged 4 commits into from
Aug 4, 2024
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
13 changes: 7 additions & 6 deletions Sources/VRCKit/Models/InstanceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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 }
}
20 changes: 0 additions & 20 deletions Sources/VRCKit/Protocols/ProfileProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
28 changes: 28 additions & 0 deletions Sources/VRCKit/Utils/ProfileImageURL.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
43 changes: 43 additions & 0 deletions Sources/VRCKit/Utils/TrustRank.swift
Original file line number Diff line number Diff line change
@@ -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 { 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"
}
}
}