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.feed,
    target_feed: { $in: ["user:sara", "user:adam"] },
  },
});

console.log(response.follows);

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

// Paginating through followers for a feed - won't store followers in state
const firstPage = await userFeed.queryFollowers({
  limit: 20,
});

// Next page - won't store followers in state
const secondPage = await userFeed.queryFollowers({
  limit: 20,
  next: firstPage.next,
});

// or load when reading feed - will store followers in state
await feed.getOrCreate({
  followers_pagination: {
    limit: 10,
  },
});

// and then load next pages (or first if followers are not yet loaded) - will store followers in state
await feed.loadNextPageFollowers({ limit: 10 });

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

// Filter by source - feeds that I follow - won't store followings in state
await myTimeline.queryFollowing({ limit: 10 });

// or load when reading feed - will store followings in state
await feed.getOrCreate({
  following_pagination: {
    limit: 10,
  },
});

// and then load next pages (or first if followings are not yet loaded) - will store followings in state
await feed.loadNextPageFollowing({ limit: 10 });

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

Follows Queryable Built-In Fields

nametypedescriptionsupported operationsexample
source_feedstring or list of stringsThe feed ID that is following$in, $eq{ source_feed: { $eq: 'messaging:general' } }
target_feedstring or list of stringsThe feed ID being followed$in, $eq{ target_feed: { $in: [ 'sports:news', 'tech:updates' ] } }
statusstring or list of stringsThe follow status$in, $eq{ status: { $in: [ 'accepted', 'pending', 'rejected' ] } }
created_atstring, must be formatted as an RFC3339 timestampThe time the follow relationship was created$eq, $gt, $gte, $lt, $lte{ created_at: { $gte: '2023-12-04T09:30:20.45Z' } }

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.feed);

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

await saraClient.acceptFollow({
  source: adamTimeline.feed,
  target: saraFeed.feed,
  // Optionally provide role
  follower_role: "feed_member",
});

await saraClient.rejectFollow({
  source: adamTimeline.feed,
  target: saraFeed.feed,
});

Push Preferences on Follow

When following a feed, you can set push_preference to control push notifications for future activities from that feed:

  • all - Receive push notifications for all activities from the followed feed
  • none (default) - Don’t receive push notifications for activities from the followed feed

Note: The push_preference parameter controls future notifications from the followed feed, while skip_push controls whether the follow action itself triggers a notification.

Examples: Push Preferences vs Skip Push

Understanding the difference between push_preference and skip_push:

// Scenario 1: Follow a user and receive notifications for their future activities
await timeline.follow("user:alice", {
  push_preference: "all", // You'll get push notifications for Alice's future posts
});

// Scenario 2: Follow a user but don't get notifications for their activities
await timeline.follow("user:bob", {
  push_preference: "none", // You won't get push notifications for Bob's future posts
});

// Scenario 3: Follow a user silently
await timeline.follow("user:charlie", {
  skip_push: true, // Charlie won't get a "you have a new follower" notification
  push_preference: "all", // But you'll still get notifications for Charlie's future posts
});

// Scenario 4: Silent follow with no future notifications
await timeline.follow("user:diana", {
  skip_push: true, // Diana won't know you followed her
  push_preference: "none", // And you won't get notifications for her posts
});
© Getstream.io, Inc. All Rights Reserved.