Realtime Events

Realtime events in web is a way to get realtime updates on different entities of the social SDK. This means that whenever a user updates a community, adds/edits a new post within that community feed or adds/edits a comment within that post, the changes will be reflected immediately to all the users that choose to subscribe to the said community, post or comment.

The changes will be reflected through the callback for either observe* method (e.g. observeCommunity) or individual event subscription(e.g. onCommunityUpdated) The SDK currently supports realtime events subscription to community, post, comment, user, and follow/unfollow models.

Topics

A topic is just a unique path<string> which has to be constructed for each model that we want to subscribe to in realtime. For each model type, SDK has helper methods to create these topics.

The six helper methods we have right now for the five different model types that support realtime events are:

  • getCommunityTopic

  • getPostTopic

  • getCommentTopic

  • getUserTopic

  • getMyFollowersTopic

  • getMyFollowingsTopic

These methods have two parameters :

  1. Data model (required) This is the model that we want to subscribe to.

  2. Subscription level (optional) This is a way to determine the level of events within that model that we want to get realtime updates. The SDK has a SubscriptionLevels enum which can be used. If not provided, the default subscription level will be the model type that is passed.

enum SubscriptionLevels { 
  COMMUNITY = 'community',
  POST = 'post',
  COMMENT = 'comment',
  POST_AND_COMMENT = 'post_and_comment',
  USER = 'user',
};

Community Topic

Community model supports the following subscription levels:

  • COMMUNITY

  • POST

  • COMMENT

  • POST_AND_COMMENT

The default value is COMMUNITY.

Post Topic

Post model supports the following subscription levels:

  • POST

  • COMMENT

The default is POST.

Comment Topic

Comment model supports only COMMENT subscription level as there are no lower level models.

User Topic

User model is similar to the community model in terms of topic creation. User model supports the following subscription levels

  • USER

  • POST

  • COMMENT

  • POST_AND_COMMENT

The default value is USER.

Follow Topics

Subscribe and Unsubscribe

After creating a topic, you can subscribe to the topic using subscribeTopic function.

Subscription Topics limit

The maximum limit for the number of topics that can be subscribed to is 20. Developers should maintain the list of subscriptions themselves and unsubscribe when it's not needed.

There are a few ways we can manage the subscription limit:

  • We advise the developers to use higher level of topics. For example, instead of creating a topic for each post within a community and for each comment within the posts, it's better to create a single community topic for all the posts and comments within that community by using the getCommunity topic method with SubscriptionLevel of POST_AND_COMMENT.

  • We advise the developers to subscribe to a topic when a model is rendered and unsubscribe when not. For example, if you have a list of communities rendered on a page, and you click on one and move to a page that shows the details of that community, you might want to subscribe when user is only viewing community details in details page and unsubscribe when user moves back to community list page.

Observing Realtime events

Here are some example usage for subscribing and observing realtime events for a community:

If the session is logged out, all the existing subscriptions will be removed.

Available event handlers:

  • onCommunityCreated

  • onCommunityUpdated

  • onCommunityDeleted

  • onCommunityJoined

  • onCommunityLeft

  • onCommunityUserAdded

  • onCommunityUserBanned

  • onCommunityUserRemoved

  • onCommunityUserUnbanned

  • onPostCreated

  • onPostUpdated

  • onPostDeleted

  • onPostApproved

  • onPostDeclined

  • onPostFlagged

  • onPostUnflagged

  • onPostReactionAdded

  • onPostReactionRemoved

  • onCommentCreated

  • onCommentUpdated

  • onCommentDeleted

  • onCommentFlagged

  • onCommentUnflagged

  • onCommentReactionAdded

  • onCommentReactionRemoved

  • onUserFollowed

  • onUserUnfollowed

  • onFollowerRequested

  • onFollowRequestAccepted

  • onFollowRequestCanceled

  • onFollowRequestDeclined

  • onFollowerDeleted

  • onFollowInfoUpdated

Last updated