Follow Relationship

The FollowRelationship model represents a social connection between two users in the ContactsManager ecosystem, where one user follows another. This model is the foundation for social features like activity feeds and user discovery.

Properties

Identifiers

  • id: String - Unique identifier for the follow relationship
  • followerId: String - ID of the user who is following
  • followedId: String - ID of the user being followed
  • userId: String - External user ID of the followed user

Timestamps

  • createdAt: Date - When the follow relationship was created

Linked Profiles

  • follower: CanonicalContact? - Canonical profile of the follower
  • followed: CanonicalContact? - Canonical profile of the followed user
  • localContact: Contact? - Local device contact data if available

Usage Example

// Display followers with pagination
func displayFollowers() async {
    do {
        let followers = try await ContactsService.shared.socialService.getFollowers(
            skip: 0, 
            limit: 20
        )
        
        print("You have \(followers.total) followers")
        
        // Process followers
        for relationship in followers.items {
            if let follower = relationship.follower {
                // Display follower information
                let followerName = follower.fullName
                let followerId = follower.id
                
                print("Follower: \(followerName)")
                
                // Access additional details if available
                if let email = follower.email {
                    print("  Email: \(email)")
                }
                
                if let avatarUrl = follower.avatarUrl {
                    print("  Avatar: \(avatarUrl)")
                }
                
                // Access local contact data if available
                if let localContact = relationship.localContact {
                    print("  Local contact: \(localContact.displayName ?? "Unknown")")
                    print("  Phone numbers: \(localContact.phoneNumbers.count)")
                }
            }
        }
    } catch {
        print("Error retrieving followers: \(error.localizedDescription)")
    }
}

Accessing Follow Relationships

The SDK provides several methods to work with follow relationships:

  • Get Followers: Retrieve users following the current user
  • Get Following: Retrieve users the current user is following
  • Get Mutual Follows: Find users with bidirectional follow relationships
  • Follow User: Create a new follow relationship
  • Unfollow User: Remove an existing follow relationship
  • Check Follow Status: Determine if a user is being followed

These methods enable implementation of rich social features in your app, such as “Follow” buttons, follower lists, and personalized content feeds.