1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import Foundation
enum AvatarImageURL {
static func thumbnail(_ url: URL) -> URL {
replacingPreset(in: url, with: "avatar_thumbnail")
}
static func fullSize(_ url: URL) -> URL {
replacingPreset(in: url, with: "avatar")
}
private static func replacingPreset(in url: URL, with preset: String) -> URL {
guard url.scheme?.lowercased() == "https", url.host?.lowercased() == "cdn.bsky.app",
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)
else { return url }
let path = components.percentEncodedPath
guard let prefix = ["/img/avatar/", "/img/avatar_thumbnail/"].first(where: path.hasPrefix) else {
return url
}
components.percentEncodedPath = "/img/\(preset)/" + path.dropFirst(prefix.count)
return components.url ?? url
}
}
struct Account: Equatable {
let handle: String
private let providedDisplayName: String
var id: String = ""
var avatarURL: URL?
var isAvatarURLKnown = true
var displayName: String {
providedDisplayName.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty ? handle : providedDisplayName
}
init(handle: String, displayName: String, id: String = "", avatarURL: URL? = nil) {
self.handle = handle
self.providedDisplayName = displayName
self.id = id
self.avatarURL = avatarURL
}
}
struct Profile: Equatable {
struct Link: Equatable, Identifiable {
let id: String
let title: String
let url: URL
var moderationLabels: [ModerationPolicy.Label] = []
}
var author: Post.Author
var bio: String
let location: String?
let website: URL?
let followerCount: Int
let followingCount: Int
var isFollowing: Bool = false
var followURI: String?
var isFollowedBy: Bool = false
var links: [Link] = []
}
enum ProfileConnectionKind: String, Codable {
case followers
case following
var title: String {
switch self {
case .followers: "Followers"
case .following: "Following"
}
}
}
struct ProfileConnectionsPage {
let accounts: [Post.Author]
let cursor: String?
}