Yaron Levi
Yaron Levi

Reputation: 13079

Stream - Get the total number of followers

I've created a feed reference and fetched the followers like so:

var admin = client.feed('user', 'admin');
const res = await admin.followers();

But the returned result contains paginated data. How can I count the total number of followers?

Will this feature be available or any rough estimation on the roadmap?

Is there any other recommended architecture to get this total count when working with Stream?

Upvotes: 15

Views: 634

Answers (2)

tobias
tobias

Reputation: 1004

It's now supported with the client.followStats() function:

// 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']})

Which returns something like:

{  
  results: { 
    followers: { count: 1529, feed: 'user:me' }, 
    followings: { count: 81, feed: 'user:me' }   
  }, 
  duration: '1.92ms' 
}

Here is the API documentation for it: https://getstream.io/activity-feeds/docs/node/following/?language=javascript#reading-follow-stats

Upvotes: 3

Vladimir Marton
Vladimir Marton

Reputation: 576

Looks like this is not supported yet.

Dwight Gunning wrote on github on 3rd of May, 2018:

Thanks for the interest. This is still on our long-range backlog.

https://github.com/GetStream/stream-django/issues/42

Upvotes: 3

Related Questions