Follow / Unfollow

Following relationships are a fundamental part of social networks. This creates a relationship between users in social features.

The connection between users will be used to determine the visibility and the accessibility of data in User Feed and Global feed.

User relationship concept

In the current state, our SDK provides a one-direction relationship. For example, when user A has followed User B, in this case, the system will know that user A has connected with B.

‌User connection method concept

In the current state, our SDK provides two ways for users to create relationships with other users. This connection method will be applied to every user in the network.

  1. With request process This means that once a user sends the Follow action to the target userId , the system will send the request to the target user. Until the target user accepts the follow request, the connection will not be established yet.

  2. Without Request process This means that once a user sends the Follow action to the target userId, the system will automatically establish the connection between 2 users.

The default connection method is the With request process. If you wish to change the connection method, you can contact our support team.

Get follow status and connection counter

The first step to start following other users is to know the connection status of the target user. You can follow this sample code.

Our SDK does provide 3 statuses:

  1. Accept This status means the target user has already connected to the SDK method caller.

  2. Pending This status means the target user has already received the follow request from the SDK method caller. This status will only be available when the connection method setting is With request process.

  3. None This status means the target user has not connected to the SDK caller.

With the getFollowCount method, you can get the total count of :

  1. Following

    This is the total number of users that the target user is following.

  2. Follower This is the total number of users who followed the target user.

  3. Pending This is the total number of follow requests the target user has received

‌Follow other user

To start following other users, you can simply pass the userId of the user that you want to follow and we will do the rest. Use the following code:

Withdraw your follow request or Unfollow other user

If you want to withdraw the follow request, you may use this code:

Get the list of followers

To see the followers user list, you can use this code:

‌For myself

For other user

We currently do not support sorting of the follower user list.

Get the list of the following user

To see the Following user list, you can try this code:

For myself

For other user

We currently do not support sorting of the following user list.

Get the list of follow requests

To see the follow request list, you can try this code:

We currently do not support sorting of the follow request user list.

Accept follow request

To accept the follow request, you can try this code:

If the Follow request is no longer available (either the sender of the follow request has withdrawn the request or the request has been accepted or declined before) SDK will return an error message.

Decline follow request

To decline the follow request , you can try this code.

If the Follower request is no longer available (either the follower request sender has withdrawn the request or the request has been accepted or declined before) SDK will return the error message.

Getting Realtime Updates

SDK supports follow / unfollow relationship updates in realtime. In order to get these updates, you need to create a follow event topic and then subscribe to that topic.

Create Follow Topic

In order to create a new follow/unfollow topic for subscription, SDK supports a helper method known as getUserFollowTopic. The helper method has a FollowEventTypes argument which determines the type of follow event that you want to subscribe to.

The FollowEventTypes can have one of these values:

  • MY_FOLLOWERS - subscribe to follow events of all the followers of the current user

  • MY_FOLLOWINGS - subscribe to follow events of all the users the current user follows.

Subscribe to Follow Event

After creating a topic, you can subscribe and unsubscribe to the topic using the EventSubscriberRepository class.

Observe Follow Events in Realtime

Once you have successfully subscribed to the topics, you will start to receive the data in the liveObject or liveCollection related to follow / unfollow.

Let's consider the example below:

Last updated