Social Features
Implementing social features with the ContactsManager SDK
Social Features
The ContactsManager SDK provides comprehensive social features to enhance your app with follow relationships and activity feeds. These features enable your users to connect with each other, follow other users of interest, and create an engaging social experience within your application. This guide explains how to implement these features using the SDK.
Follow Relationships
Follow relationships are the foundation of social connectivity in your app. They allow users to curate their network by following specific users, which determines whose content appears in their feeds and activity streams.
Following a User
Allow users to follow other users in your app. Following creates a one-way relationship where a user can see updates from people they follow without requiring mutual connection.
The followUser
method requires:
userId
: The organization-specific user ID of the user to follow
The response indicates whether the follow action was successful or if the user was already following the specified user.
Unfollowing a User
Users may want to stop following certain users. The unfollow action removes the relationship, preventing that user’s updates from appearing in the user’s feed.
The unfollowUser
method requires only the organization-specific user ID of the user to unfollow.
Checking Follow Status
Determining if a user is following another user is essential for displaying the correct UI state, such as follow/unfollow buttons on profile pages.
The isFollowingUser
method returns a status object with an isFollowing
property that indicates the current relationship status. This is useful for updating UI elements that depend on follow status.
Retrieving Followers and Following
Building social experiences often requires displaying lists of followers or users being followed. These methods provide paginated access to these relationships with rich user information.
Both getFollowers
and getFollowing
methods:
- Support pagination through
skip
andlimit
parameters - Return the total number of relationships for implementing UIs with counters
- Provide both server profile data and local contact information when available
- Can be used to create scrollable lists in profile views or dedicated followers/following screens
Get followers for a specific user
Sometimes you may want to display followers of a specific user rather than the current user. This is useful for viewing another user’s profile or analyzing social connections.
By providing the optional userId
parameter, you can retrieve followers for any user in the system, not just the authenticated user.
Get Mutual Follows
Mutual follows (users who follow the current user and whom the current user follows back) often represent stronger social connections. Displaying mutual follows can help users identify their most engaged connections.
The getMutualFollows
method returns bidirectional relationships where both users follow each other. This is useful for implementing “close friends” features or prioritizing content from mutual connections.
Activity Feeds
The SDK provides activity feeds to display content from users. Activity feeds create a dynamic social experience where users can see updates, events, and actions from people they follow. For detailed implementation of feed features and events, please refer to the Events documentation.
Building a Social Activity Feed
Here’s an example of building a social activity feed with SwiftUI, demonstrating a complete implementation of a scrollable feed with pagination, error handling, and empty states.
This is a comprehensive example that shows a complete implementation. The core concepts can be adapted to fit your app’s design and requirements.
This example demonstrates how to:
- Implement pagination for efficient data loading
- Handle different UI states (loading, error, empty, populated)
- Create visually appealing event cards
- Implement pull-to-refresh functionality
- Automatically load more content when scrolling to the bottom
Best Practices for Social Features
-
Handle Network Failures: Social features rely on network communication, so implement proper error handling with user-friendly error messages and retry options to ensure a smooth experience even with spotty connectivity.
-
Implement Pagination: Use skip and limit parameters for better performance with large datasets. Avoid loading the entire dataset at once, which can cause performance issues and waste bandwidth.
-
Optimize for Offline Use: Cache social data for a better offline experience. Consider storing the most recent feed items locally so users can view content even without an internet connection.
-
Follow Privacy Guidelines: Clearly communicate to users how their data is used. Implement proper permissions for accessing user information and provide clear opt-in/opt-out mechanisms for social features.
-
Support Pull-to-Refresh: Implement refreshable lists for up-to-date content, as social feeds frequently change and users expect to be able to check for new content easily.
-
Pre-fetch Content: Load the next page of content before the user reaches the end of the list to create a seamless scrolling experience without visible loading indicators.
Troubleshooting
Common Issues
-
Authentication Errors
- Ensure the SDK is properly initialized with a valid token before attempting social operations
- Check that the token hasn’t expired, and implement proper token refresh mechanisms
- Verify that users have the necessary permissions to perform social actions
-
Missing or Incomplete Data
- Verify that the necessary user data has been properly synced before enabling social features
- Check that users have complete profiles with required fields filled out
- Ensure proper initialization of the ContactsService before accessing social features
-
Performance Issues
- Implement proper pagination in all list views to avoid loading excessive data
- Use background fetch for keeping social data up-to-date without blocking the UI
- Cache commonly accessed data locally to reduce network requests and improve responsiveness