feedsClient
.events
.collect { event ->
// Handle the event types you care about
when (event) {
is ActivityAddedEvent -> {
println("New activity added: ${event.activity.text}")
}
is CommentAddedEvent -> {
println("New comment added: ${event.comment.text}")
}
is FollowCreatedEvent -> {
println("New follow created: ${event.follow.targetFeed}")
}
else -> {
println("Received event: ${event::class.java.simpleName}")
}
}
}
Event Handling
The state layer provides a way to be notified about state updates easily. However, it’s also possible to watch for WebSocket events directly by collecting an events flow, should you need it.
Observing events
The FeedsClient
exposes an events()
function to create and get a flow of events:
Leveraging the Flow API
With the events coming as a Flow
, no special knowledge is needed to get started. You can use all the power of Kotlin’s
coroutines and Flow API to handle events in a way that suits your use cases.
For example, if you want to only listen for a specific event type, like new activities added, you can use the
filterIsInstance
operator:
feedsClient
.events
.filterIsInstance<ActivityAddedEvent>()
.collect { event ->
println("New activity added: ${event.activity.text}")
}
Handling backpressure
If your event processing is slow, you might want to add explicit backpressure handling because the events flow will drop events if the consumer cannot keep up.
For example, you can use the buffer
operator and specify your desired strategy:
feedsClient
.events
.buffer(capacity = 100, onBufferOverflow = BufferOverflow.DROP_OLDEST)
.collect { event ->
// Process the event
}
Available Event Types
Below is a table of all available events:
Event Name | Description |
---|---|
Activity Events | |
ActivityAddedEvent | Fired when a new activity is added to a feed. |
ActivityUpdatedEvent | Fired when an activity is modified. |
ActivityDeletedEvent | Fired when an activity is removed. |
ActivityRemovedFromFeedEvent | Fired when an activity is removed from a specific feed. |
ActivityMarkEvent | Fired when activities are marked as read/seen. |
ActivityPinnedEvent | Fired when an activity is pinned to the top. |
ActivityUnpinnedEvent | Fired when an activity is unpinned. |
Comment Events | |
CommentAddedEvent | Fired when a new comment is added to an activity. |
CommentUpdatedEvent | Fired when a comment is modified. |
CommentDeletedEvent | Fired when a comment is removed. |
Reaction Events | |
ActivityReactionAddedEvent | Fired when a reaction is added to an activity. |
ActivityReactionUpdatedEvent | Fired when a reaction is modified on an activity. |
ActivityReactionDeletedEvent | Fired when a reaction is removed from an activity. |
CommentReactionAddedEvent | Fired when a reaction is added to a comment. |
CommentReactionUpdatedEvent | Fired when a reaction is modified on a comment. |
CommentReactionDeletedEvent | Fired when a reaction is removed from a comment. |
Poll Events | |
PollClosedFeedEvent | Fired when a poll is closed. |
PollDeletedFeedEvent | Fired when a poll is deleted. |
PollUpdatedFeedEvent | Fired when a poll is modified. |
PollVoteCastedFeedEvent | Fired when a vote is cast on a poll. |
PollVoteChangedFeedEvent | Fired when a vote is changed on a poll. |
PollVoteRemovedFeedEvent | Fired when a vote is removed from a poll. |
Feed Events | |
FeedCreatedEvent | Fired when a new feed is created. |
FeedUpdatedEvent | Fired when a feed is modified. |
FeedDeletedEvent | Fired when a feed is deleted. |
FeedGroupChangedEvent | Fired when a feed group is modified. |
FeedGroupDeletedEvent | Fired when a feed group is deleted. |
NotificationFeedUpdatedEvent | Fired when a notification feed has new content. |
Member Events | |
FeedMemberAddedEvent | Fired when a member is added to a feed. |
FeedMemberRemovedEvent | Fired when a member is removed from a feed. |
FeedMemberUpdatedEvent | Fired when a member’s role or permissions change. |
Follow Events | |
FollowCreatedEvent | Fired when a follow relationship is created. |
FollowUpdatedEvent | Fired when follow settings are modified. |
FollowDeletedEvent | Fired when a follow relationship is removed. |
Bookmark Events | |
BookmarkAddedEvent | Fired when an activity is bookmarked. |
BookmarkUpdatedEvent | Fired when bookmark metadata is modified. |
BookmarkDeletedEvent | Fired when a bookmark is removed. |
BookmarkFolderUpdatedEvent | Fired when a bookmark folder is modified. |
BookmarkFolderDeletedEvent | Fired when a bookmark folder is deleted. |
User Events | |
UserUpdatedEvent | Fired when a user’s data is updated. |
UserBannedEvent | Fired when a user is banned from the app. |
UserMutedEvent | Fired when a user is muted. |
UserDeactivatedEvent | Fired when a user account is deactivated. |
UserReactivatedEvent | Fired when a user account is reactivated. |
Moderation Events | |
ModerationFlaggedEvent | Fired when content is flagged for moderation. |
ModerationMarkReviewedEvent | Fired when a moderator marks content as reviewed. |
ModerationCustomActionEvent | Fired when a custom moderation action is triggered. |
System Events | |
AppUpdatedEvent | Fired when there is a global app-level update. |