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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import SwiftUI
extension ProfileView {
var profileHeader: some View {
VStack(alignment: .leading, spacing: 16) {
HStack(alignment: .center, spacing: 14) {
if !displayPreferences.hideAvatars { profileAvatar }
VStack(alignment: .leading, spacing: 4) {
Text(author.map { displayPreferences.name($0) } ?? "Profile")
.appFont(.title2, weight: .bold)
.accessibilityIdentifier("profileDisplayName")
if !displayPreferences.handlesOnly {
Text("@\(author?.handle ?? actorID)")
.appFont(.subheadline)
.foregroundStyle(.secondary)
}
if profile?.isFollowedBy == true, actorID != model.account?.id {
Text("Follows you")
.appFont(.caption)
.foregroundStyle(.secondary)
.accessibilityIdentifier("profileFollowsYou")
}
}
Spacer(minLength: 4)
if author?.id != model.account?.id {
if model.uncertainFollowIDs.contains(actorID) {
Text("Follow status unknown")
.appFont(.footnote)
.foregroundStyle(.secondary)
} else if isFollowing {
Button {
Task { await model.toggleFollow(actorID: actorID) }
} label: {
Text("Following").fontWeight(.semibold)
}
.buttonStyle(.bordered)
.disabled(model.activeFollowIDs.contains(actorID) || model.uncertainFollowIDs.contains(actorID))
.accessibilityIdentifier("followButton")
} else {
Button {
Task { await model.toggleFollow(actorID: actorID) }
} label: {
Text("Follow").fontWeight(.semibold)
}
.buttonStyle(.borderedProminent)
.disabled(model.activeFollowIDs.contains(actorID) || model.uncertainFollowIDs.contains(actorID))
.accessibilityIdentifier("followButton")
}
}
}
if let profile {
if !profile.bio.isEmpty {
Text(profile.bio)
.fixedSize(horizontal: false, vertical: true)
}
let links = profile.links.filter { link in
guard let decision = model.contentDecision(author: profile.author, labels: link.moderationLabels)
else { return false }
return decision.action != .hide && !decision.ui(.contentView).blur
}
if !links.isEmpty || profile.website != nil {
ProfileLinksLayout {
ForEach(links) { link in
Link(destination: link.url) {
Label(link.title, systemImage: "link")
}
.accessibilityIdentifier("profileLink-\(link.id)")
}
if let website = profile.website {
Link(destination: website) {
Label(website.host() ?? website.absoluteString, systemImage: "link")
}
.accessibilityIdentifier("profileWebsiteLink")
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.multilineTextAlignment(.leading)
.buttonStyle(.bordered)
.buttonBorderShape(.capsule)
.appFont(.subheadline)
.padding(.vertical, 4)
.externalLinkBrowser { url in
PostTextFacets.openInternalURL(url, openActor: openProfile, openPost: openPost)
}
}
HStack(spacing: 16) {
connectionButton(profile.followingCount, kind: .following)
connectionButton(profile.followerCount, kind: .followers)
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("profileCounts")
if let location = profile.location {
Label(location, systemImage: "mappin.and.ellipse")
.appFont(.subheadline)
.foregroundStyle(.secondary)
}
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
@ViewBuilder
var profileAvatar: some View {
if let author, model.contentDecision(author: author)?.ui(.avatar).blur == false, let url = author.avatarURL {
Button {
selectedAvatar = ImageViewerRequest(
urls: [AvatarImageURL.fullSize(url)], descriptions: [:], index: 0, requiresGIFReveal: false)
} label: {
AccountAvatar(
account: Account(handle: author.handle, displayName: author.name, id: author.id, avatarURL: url),
size: 72, isDecorative: true)
}
.buttonStyle(.plain)
.accessibilityLabel("View profile photo")
.accessibilityIdentifier("profileAvatarButton")
} else {
AccountAvatar(account: nil, size: 72, isDecorative: false)
.accessibilityLabel("Profile photo")
}
}
func connectionButton(_ count: Int, kind: ProfileConnectionKind) -> some View {
Button {
openConnections(kind)
} label: {
HStack(spacing: 4) {
Text(count.formatted()).fontWeight(.semibold).foregroundStyle(.primary)
Text(kind.title).foregroundStyle(.secondary)
}
.appFont(.subheadline)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityIdentifier("profile-\(kind.rawValue)")
}
}