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

Follows

Follow & Unfollow

// Follow a user
let timeline = client.feed(group: "timeline", id: "john")
_ = try await timeline.follow(FeedId(group: "user", id: "tom"))

// Follow a stock
_ = try await timeline.follow(FeedId(group: "stock", id: "apple"))

// Follow with more fields
_ = try await timeline.follow(
    FeedId(group: "stock", id: "apple"),
    custom: ["reason": "investment"]
)

Querying Follows

// All my follows
let allQuery = FollowsQuery(
    filter: .equal(.userId, "me"),
    limit: 20
)
let allFollowList = client.followList(for: allQuery)
let allFollowsPage1 = try await allFollowList.get()

// Do I follow a list of feeds
// My feed is timeline:john
let followQuery = FollowsQuery(
    filter: .and([
        .equal(.sourceFeed, "timeline:john"),
        .in(.targetFeed, ["user:sara", "user:adam"])
    ])
)
let followList = client.followList(for: followQuery)
let page1 = try await followList.get()
let page2 = try await followList.queryMoreFollows()
let page1And2 = followList.state.follows

// Paginating through followers for a feed
// My feed is timeline:john
let followerQuery = FollowsQuery(
    filter: .equal(.targetFeed, "timeline:john")
)
let followerList = client.followList(for: followerQuery)
let followerPage1 = try await followerList.get()

Follow Requests

Some apps require the user’s approval for following them.

// See if a feed needs a request for follow
let feed = client.feed(group: "user", id: "amber")
let feedData = try await feed.getOrCreate()
if feedData.visibility == "followers" {
    // We need to request a follow
}

// Request to follow this feed
let timeline = client.feed(group: "timeline", id: "john")
try await timeline.follow(FeedId(group: "user", id: "amber"))

// Accept
try await feed.acceptFollow(.init(group: "timeline", id: "john"))
// or reject the follow
try await feed.rejectFollow(.init(group: "timeline", id: "john"))
© Getstream.io, Inc. All Rights Reserved.