Social real-time events enable live updates for social features through topic subscriptions. A topic is a distinct path constructed for each model you wish to subscribe to, with helper methods provided for each model type.
To subscribe to updates from a community or its content, users must have ‘Member’ status. Leaving a community automatically stops event delivery.

Community Topic

Subscribe to community events with different subscription levels:
Event TypeDescription
COMMUNITYChanges in the community object (default)
POSTSChanges of post objects in the community
COMMENTSChanges of comment objects in the community
POSTS_AND_COMMENTSChanges of posts and comments in the community
STORY_AND_COMMENTSChanges of stories and story comments in the community
// Subscribe to community events  
let eventTopic1 = AmityCommunityTopic(community: community, andEvent: .community)
subscriptionManager.subscribeTopic(eventTopic1) { success, error in
    // Handle Result
}

// Subscribe to posts events
let eventTopic2 = AmityCommunityTopic(community: community, andEvent: .posts)
subscriptionManager.subscribeTopic(eventTopic2) { success, error in
    // Handle Result
}

// Subscribe to comments events
let eventTopic3 = AmityCommunityTopic(community: community, andEvent: .comments)
subscriptionManager.subscribeTopic(eventTopic3) { success, error in
    // Handle Result
}

// Subscribe to posts and comments events
let eventTopic4 = AmityCommunityTopic(community: community, andEvent: .postsAndComments)
subscriptionManager.subscribeTopic(eventTopic4) { success, error in
    // Handle Result
}

// Subscribe to story and comments events
let eventTopic5 = AmityCommunityTopic(community: community, andEvent: .storyAndComments)
subscriptionManager.subscribeTopic(eventTopic5) { success, error in
    // Handle Result
}

Post Topic

Subscribe to individual post events:
Event TypeDescription
POSTChanges of the post object (default)
COMMENTSChanges of comment objects on the post
// Subscribe to post events
let eventTopic1 = AmityPostTopic(post: post, andEvent: .post)
subscriptionManager.subscribeTopic(eventTopic1) { success, error in
    // Handle Result
}

// Subscribe to comment events
let eventTopic2 = AmityPostTopic(post: post, andEvent: .comments)
subscriptionManager.subscribeTopic(eventTopic2) { success, error in
    // Handle Result
}

Comment Topic

Subscribe to individual comment events:
Event TypeDescription
COMMENTChanges in the comment object
// Subscribe to comment events
let eventTopic1 = AmityCommentTopic(comment: comment, andEvent: .comment)
subscriptionManager.subscribeTopic(eventTopic1) { success, error in
    // Handle results
}

User Topic

Subscribe to user-related events:
Event TypeDescription
USERChanges in the user object (default)
POSTSChanges of post objects in user feed
COMMENTSChanges of comment objects in user feed
POSTS_AND_COMMENTSChanges of posts and comments in user feed
// Subscribe to user events
let eventTopic1 = AmityUserTopic(user: user, andEvent: .user)
subscriptionManager.subscribeTopic(eventTopic1) { success, error in
    // Handle the result
}

Follow Topic

Subscribe to follower/following relationship events:
Event TypeDescription
MY_FOLLOWERSChanges related to users that follow the current user
MY_FOLLOWINGChanges related to users that the current user follows
// Subscribe to user follower events
let eventTopic1 = AmityFollowTopic(event: .myFollowers)
subscriptionManager.subscribeTopic(eventTopic1) { success, error in
    // Handle results
}

Story Topic

Subscribe to story-related events:
// Subscribe to story events
let eventTopic1 = AmityStoryTopic(story: story, andEvent: .story)
subscriptionManager.subscribeTopic(eventTopic1) { success, error in
    // Handle the result
}

Next Steps