// Create a feed id
val fid = FeedId(group = "user", id = "john")
// Create the feed instance from your client
val feed = client.feed(fid = fid)
// Get the latest data
feed.getOrCreate()
// Access the state
val feedState = feed.state
State Layer
The State layer provides observable state management for feeds and activities in Stream Feeds. It uses @Published
properties to automatically update your UI when data changes.
FeedState
FeedState
manages the state of a feed, including activities, followers, members, and pagination information. It’s an ObservableObject
that automatically updates when the feed data changes.
Getting FeedState
To access the state of a feed, you need to create a Feed
instance and access its state
property:
Available Properties
The FeedState
provides the following published properties:
// Core feed data
val feed: StateFlow<FeedData?> // The feed information
val activities: StateFlow<List<ActivityData>> // Activities in the feed
val ownCapabilities: StateFlow<List<FeedOwnCapability>> // Your permissions
// Follow relationships
val followers: StateFlow<List<FollowData>> // Users following this feed
val following: StateFlow<List<FollowData>> // Feeds this user follows
val followRequests: StateFlow<List<FollowData>> // Pending follow requests
// Feed members
val members: StateFlow<List<FeedMemberData>> // Members of the feed
// Pagination
val canLoadMoreActivities: Boolean // Whether more activities can be loaded
ActivityState
ActivityState
manages the state of a single activity, including its comments, reactions, and associated poll data. It’s also an ObservableObject
that updates automatically.
Getting ActivityState
To access the state of an activity, you need to create an Activity
instance:
// Create an activity instance
val activity = client.activity(
activityId = "activity-123",
fid = FeedId(group = "user", id = "john")
)
// Get the latest data
activity.get()
// Access the state
val activityState = activity.state
Available Properties
The ActivityState
provides the following properties:
val activity: StateFlow<ActivityData?> // The activity data
val comments: StateFlow<List<ThreadedCommentData>> // Comments on the activity
val poll: StateFlow<PollData?> // Associated poll (if any)