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

Follows

Follow & Unfollow

const timeline = client.feed("timeline", "john");
await timeline.getOrCreate();

// Follow a user
await timeline.follow("user:tom");

// Follow a stock
await timeline.follow("stock:apple");

// Follow with more fields
await timeline.follow("stock:apple", {
  push_preference: "all",
  custom: {
    reason: "investment",
  },
});

Querying Follows

const myTimeline = client.feed("timeline", "john");
await myTimeline.getOrCreate();

// Do I follow a list of feeds
const response = await client.queryFollows({
  filter: {
    source_feed: myTimeline.fid,
    target_feed: { $in: ["user:sara", "user:adam"] },
  },
});

console.log(response.follows);

const userFeed = client.feeds.feed("user", "john");
await userFeed.getOrCreate();

// Paginating through followers for a feed
const firstPage = await userFeed.queryFollowers({
  limit: 20,
});

// Next page
const secondPage = await userFeed.queryFollowers({
  limit: 20,
  next: firstPage.next,
});

// or load when reading feed
await feed.getOrCreate({
  follower_pagination: {
    limit: 10,
  },
});

// and then load next pages
await feed.loadNextPageFollowers();

console.log(feed.state.getLatestValue().followers);

// Filter by source - feeds that I follow
await myTimeline.queryFollowing();

// or load when reading feed
await feed.getOrCreate({
  following_pagination: {
    limit: 10,
  },
});

// and then load next pages
await feed.loadNextPageFollowing();

console.log(feed.state.getLatestValue().following);

Follow Requests

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

const saraFeed = saraClient.feed("user", uuidv4());
await saraFeed.getOrCreate({
  // You need to set followers visibility to have follow requests
  data: { visibility: "followers" },
});

const adamTimeline = adamClient.feed("timeline", uuidv4());
await adamTimeline.getOrCreate();

const followRequest = await adamTimeline.follow(saraFeed.fid);

console.log(followRequest.follow.status); // pending

await saraClient.acceptFollow({
  source_fid: adamTimeline.fid,
  target_fid: saraFeed.fid,
  // Optionally provide role
  follower_role: "feed_member",
});

await saraClient.rejectFollow({
  source_fid: adamTimeline.fid,
  target_fid: saraFeed.fid,
});
© Getstream.io, Inc. All Rights Reserved.