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

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:

// Create a feed id
let fid = FeedId(group: "user", id: "john")

// Create the feed instance from your client
let feed = client.feed(for: fid)

// Get the latest data
try await feed.getOrCreate()

// Access the state
let feedState = feed.state

Available Properties

The FeedState provides the following published properties:

// Core feed data
@Published var feed: FeedData?                    // The feed information
@Published var activities: [ActivityData]         // Activities in the feed
@Published var ownCapabilities: [FeedOwnCapability] // Your permissions

// Follow relationships
@Published var followers: [FollowData]            // Users following this feed
@Published var following: [FollowData]            // Feeds this user follows
@Published var followRequests: [FollowData]       // Pending follow requests

// Feed members
@Published var members: [FeedMemberData]          // Members of the feed

// Pagination
var canLoadMoreActivities: Bool                   // 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
let activity = client.activity(
    for: "activity-123",
    in: FeedId(group: "user", id: "john")
)

// Get the latest data
try await activity.get()

// Access the state
let activityState = activity.state

Available Properties

The ActivityState provides the following published properties:

@Published var activity: ActivityData?            // The activity data
@Published var comments: [CommentData]            // Comments on the activity
@Published var poll: PollData?                    // Associated poll (if any)
© Getstream.io, Inc. All Rights Reserved.