Following Feeds

Following relationships are a fundamental part of social networks and many other apps that feature feeds. They link one Feed to another and cause Activities added to a feed to appear in any other feeds that follow it.

When an Activity is added to a feed, it is automatically added to any other feeds that follow the feed. This does not propagate further through the graph of following relationships. If your app requires that the Activity be added to other feeds, “to” field targeting or a batch activity add may be suitable.

The code example below shows you how to follow a feed:

// A timeline feed for the current user.
let timelineFeed = Client.shared.flatFeed(feedSlug: "timeline")

// `timeline:current_user_id` follows `user:user_42`:
timelineFeed?.follow(toTarget: FeedId(feedSlug: "user", userId: "user_42")) { result in /* ... */ }

// Follow feed without copying the activities:
timelineFeed?.follow(toTarget: FeedId(feedSlug: "user", userId: "user_42"), activityCopyLimit: 0) { result in /* ... */ }

Also take note that:

Only Flat Feeds may be followed

A Feed cannot follow itself

By default, the most recent 100 existing activities in the target feed will be added to the follower feed, but this can be changed via the activity_copy_limit parameter.

Parameters

nametypedescriptiondefaultoptional
feedstringThe feed id-
targetstringThe feed id of the target feed-
activity_copy_limitintHow many activities should be copied from the target feed. max 1000-

If you need to follow many feeds at once have a look at how to batch follow later in this document. If you need to run large imports, use our JSON import format.

Unfollowing Feeds

Unfollowing a feed removes the following relationship with the feed specified in the target parameter. See the following examples:

// Stop following feed user_42 - purging history:
timelineFeed?.unfollow(fromTarget: FeedId(feedSlug: "user", userId: "user_42")) { result in /* ... */ }

// Stop following feed user_42 but keep history of activities:
timelineFeed?.unfollow(fromTarget: FeedId(feedSlug: "user", userId: "user_42"), keepHistory: true) { result in /* ... */ }

Existing Activities in the feed that originated in a no longer followed target feed will be purged unless the keep_history parameter is provided.

Parameters

nametypedescriptiondefaultoptional
feedstringThe feed id-
targetstringThe feed id of the target feed-
keep_historybooleanWhether the activities from the unfollowed feeds should be removedfalse

Re-following a feed that is already followed has no effect. However, unfollowing and re-following a feed will result in feed updates as Activities are purged and re-added to the feed.

Reading Feed Followers

Returns a paginated list of the given feed’s followers. See the following example:

// The current user feed.
let userFeed = Client.shared.flatFeed(feedSlug: "user")

// List followers.
userFeed?.followers(offset: 10, limit: 10) { result in /* ... */ }

The followers returned by the API are sorted reverse chronologically, according to the time the follow relationship was created.

The number of followers that can be retrieved is limited to 1,000.

Parameters

nametypedescriptiondefaultoptional
limitintegerAmount of results per request, max 10025
offsetintegerNumber of rows to skip before returning results, max 9990

Response Data

{
 "results": [
  {
   "feed_id": "conversation2:test",
   "target_id": "conversation2:user_2",
   "created_at": "2018-01-19T09:35:17.817332Z"
  }
 ],
 "duration": "1.92ms"
}

Reading Followed Feeds

Returns a paginated list of the feeds which are followed by the feed. See the following example:

// Retrieve last 10 feeds followed by the current user.
userFeed?.following(limit: 10) { result in /* ... */ }

// Retrieve 10 feeds followed by the current user starting from the 11th.
userFeed?.following(offset: 10, limit: 10) { result in /* ... */ }

// Check if the current user follows specific feeds.
userFeed?.following(filter: [FeedId(feedSlug: "user", userId: "42"),
               FeedId(feedSlug: "user", userId: "43")], limit: 2) { result in /* ... */ }

The followed feeds returned by the API are sorted reverse chronologically, according to the time the follow relationship was created.

The number of followed feeds that can be retrieved is limited to 1,000.

Parameters

nametypedescriptiondefaultoptional
limitintegerAmount of results per request, max 10025
offsetintegerNumber of rows to skip before returning results, max 9990
filterstringThe comma-separated list of feeds to filter results on-

Response Data

{ 
 results: [
   {
    feed_id: 'conversation2:test',
    target_id: 'conversation2:user_2',
    created_at: '2018-01-19T09:35:17.817332Z',
    updated_at: null
   }
  ],
 duration: '1.92ms'
}

Reading follow stats

Paginating followers and/or followings is sometimes not the answer and only counts are needed. In this case, stats can be retrieved directly too. With default permissions, it works automatically for server side auth. For client-side auth, please contact support to add it to your required feed groups.

Counts are up to 10K. If a feed has more followers or followings than this number, please contact support to increase limits.

// get follower and following stats of the feed
client.feed('user', 'me').followStats()

// get follower and following stats of the feed but also filter with given slugs
// count by how many timelines follow me
// count by how many markets are followed
client.feed.followStats({followerSlugs: ['timeline'], followingSlugs: ['market']})

Response Data

{ 
 results: {
  followers: { count: 1529, feed: 'user:me' },
  following: { count: 81, feed: 'user:me' } 
 },
 duration: '1.92ms'
}
© Getstream.io, Inc. All Rights Reserved.