// Using a canonical contact from API response
func displayUserProfile(canonicalContact: CanonicalContact) {
userNameLabel.text = canonicalContact.fullName
if let email = canonicalContact.email {
emailLabel.text = email
} else {
emailLabel.isHidden = true
}
if let avatarUrl = canonicalContact.avatarUrl, let url = URL(string: avatarUrl) {
// Load avatar image from URL
loadProfileImage(url: url)
} else {
// Display default profile image
profileImageView.image = UIImage(named: "default_avatar")
}
// Access custom metadata if available
if let metadata = canonicalContact.contactMetadata,
let userLevel = metadata["userLevel"] as? Int {
userLevelLabel.text = "Level: \(userLevel)"
}
}
// Following a user with their canonical contact info
func followUser(canonicalUser: CanonicalContact) async {
do {
let result = try await ContactsService.shared.socialService.followUser(
userId: canonicalUser.organizationUserId
)
if let success = result.success, success {
print("Successfully followed \(canonicalUser.fullName)")
}
} catch {
print("Error following user: \(error.localizedDescription)")
}
}