Canonical Contact

The CanonicalContact model represents a user’s profile in the ContactsManager ecosystem. This is the server-side representation of a user that can be used for social features, recommendations, and cross-device syncing.

Properties

Identity

  • id: String - Unique identifier for the user
  • organizationId: String? - Organization the user belongs to
  • organizationUserId: String - User identifier within the organization

User Information

  • fullName: String - User’s full name
  • email: String? - User’s email address
  • phone: String? - User’s phone number
  • avatarUrl: String? - URL to user’s profile image

Status

  • isActive: Bool? - Whether the user account is active
  • createdAt: Date? - When the user profile was created
  • updatedAt: Date? - When the user profile was last updated

Metadata

  • contactMetadata: [String: Any]? - Custom metadata for the user profile

Usage Example

// 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)")
    }
}