Activity Feeds V3 is in closed alpha — do not use it in production (just yet).

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:

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}")
            }
        }
    }

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 NameDescription
Activity Events
ActivityAddedEventFired when a new activity is added to a feed.
ActivityUpdatedEventFired when an activity is modified.
ActivityDeletedEventFired when an activity is removed.
ActivityRemovedFromFeedEventFired when an activity is removed from a specific feed.
ActivityMarkEventFired when activities are marked as read/seen.
ActivityPinnedEventFired when an activity is pinned to the top.
ActivityUnpinnedEventFired when an activity is unpinned.
Comment Events
CommentAddedEventFired when a new comment is added to an activity.
CommentUpdatedEventFired when a comment is modified.
CommentDeletedEventFired when a comment is removed.
Reaction Events
ActivityReactionAddedEventFired when a reaction is added to an activity.
ActivityReactionUpdatedEventFired when a reaction is modified on an activity.
ActivityReactionDeletedEventFired when a reaction is removed from an activity.
CommentReactionAddedEventFired when a reaction is added to a comment.
CommentReactionUpdatedEventFired when a reaction is modified on a comment.
CommentReactionDeletedEventFired when a reaction is removed from a comment.
Poll Events
PollClosedFeedEventFired when a poll is closed.
PollDeletedFeedEventFired when a poll is deleted.
PollUpdatedFeedEventFired when a poll is modified.
PollVoteCastedFeedEventFired when a vote is cast on a poll.
PollVoteChangedFeedEventFired when a vote is changed on a poll.
PollVoteRemovedFeedEventFired when a vote is removed from a poll.
Feed Events
FeedCreatedEventFired when a new feed is created.
FeedUpdatedEventFired when a feed is modified.
FeedDeletedEventFired when a feed is deleted.
FeedGroupChangedEventFired when a feed group is modified.
FeedGroupDeletedEventFired when a feed group is deleted.
NotificationFeedUpdatedEventFired when a notification feed has new content.
Member Events
FeedMemberAddedEventFired when a member is added to a feed.
FeedMemberRemovedEventFired when a member is removed from a feed.
FeedMemberUpdatedEventFired when a member’s role or permissions change.
Follow Events
FollowCreatedEventFired when a follow relationship is created.
FollowUpdatedEventFired when follow settings are modified.
FollowDeletedEventFired when a follow relationship is removed.
Bookmark Events
BookmarkAddedEventFired when an activity is bookmarked.
BookmarkUpdatedEventFired when bookmark metadata is modified.
BookmarkDeletedEventFired when a bookmark is removed.
BookmarkFolderUpdatedEventFired when a bookmark folder is modified.
BookmarkFolderDeletedEventFired when a bookmark folder is deleted.
User Events
UserUpdatedEventFired when a user’s data is updated.
UserBannedEventFired when a user is banned from the app.
UserMutedEventFired when a user is muted.
UserDeactivatedEventFired when a user account is deactivated.
UserReactivatedEventFired when a user account is reactivated.
Moderation Events
ModerationFlaggedEventFired when content is flagged for moderation.
ModerationMarkReviewedEventFired when a moderator marks content as reviewed.
ModerationCustomActionEventFired when a custom moderation action is triggered.
System Events
AppUpdatedEventFired when there is a global app-level update.
© Getstream.io, Inc. All Rights Reserved.