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

Feeds

Creating a Feed

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Reading a Feed

Here is a basic example of how to read a feed:

$firstPageResponse = $this->feedsV3Client->queryActivities(
    new GeneratedModels\QueryActivitiesRequest(
        limit: 3,
        filter: (object)['user_id' => $this->testUserId]
    )
);

The response will contain the following data.

You have more options when reading a feed, let’s go over a few:

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Feed Pagination

Here is how you can read the next page on the feed:

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Filtering Examples

Another common use case is filtering a feed. This is trickier than it seems. Keep in mind that for performance reasons feeds often have to be computed on write time. To allow for filtering we expose the following API.

Filter tags are indexed, so filtering by this field is performant.

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

The filter syntax also supports $or and $and, so here’s an example that’s a little more complicated:

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

The following fields and opearators are supported when filtering:

nametypedescriptionsupported operationsexample
idstring or list of stringsThe ID of the activity$in, $eq{ id: { $in: [ 'abc', 'xyz' ] } }
activity_typestring or list of stringsThe type of the activity$in, $eq{ activity_type: { $in: [ 'abc', 'xyz' ] } }
user_idstring or list of stringsThe ID of the user who created the activity$in, $eq{ user_id: { $in: [ 'abc', 'xyz' ] } }
textstringThe text content of the activity$eq, $q, $autocomplete{ text: { $q: 'popularity' } }
search_dataobjectThe extra metadata for search indexing$contains, $path_exists{ search_data: { $contains: { 'category': 'sports', 'status': 'active' } } }
interest_tagslist of stringsTags for user interests$eq, $contains{ interest_tags: { $in: [ 'sports', 'music' ] } }
filter_tagslist of stringsTags for filtering$eq, $contains{ filter_tags: { $in: [ 'categoryA', 'categoryB' ] } }
created_atstring, must be formatted as an RFC3339 timestampThe time the activity was created$eq, $gt, $lt, $gte, $lte{ created_at: { $gte: '2023-12-04T09:30:20.45Z' } }
popularitynumberThe popularity score of the activity$eq, $ne, $gt, $lt, $gte, $lte{ popularity: { $gte: 70 } }
nearobjectIndicates the GEO point to search nearby activities$eq{ near: { $eq: { lat: 40.0, lng: -74.0, distance: 200 } } }
within_boundsobjectIndicates the GEO bounds to search for activities within$eq{ within_bounds: { $eq: { ne_lat: 40.0, ne_lng: -115.0, sw_lat: 32.0, sw_lng: -125.0 } } }
visible_to_userbooleanIndicate whether the activity is visible to the user$eq{ visible_to_user: { $eq: true } }

Feed Members

You can add and remove members to a feed. This is useful for building communities where a set of users can add content to the feed.

It’s not possible to set/update member role on client-side. Use server-side SDKs for this. When adding members client-side all new members will have feed_member role:

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Feed members vs followers

Followers and members might seem like similar concepts, but they serve two different purposes with some key differences.

Followers can only be feeds (for example the timeline feed of Alice follows the user feed of Bob). Followers’ aim is to access the content of a feed they’re interested in and interact with it.

Members can only be users (for example Alice adds Bob as a member to her feed about “Travel Hacks”). The aim of feed members is usually to help out with admin tasks (helpful if you want to build apps similar to Facebook pages) or to decide what activities a user has access to using membership levels (for example Bob becomes a premium member in Alice’s community).

Member invites

You can invite members with the invite flag, where invited users can accept or reject the membership.

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Query Feeds

Querying feeds allows you to do things like showing the list of communities you’ve joined.

Here’s an example of how to query feeds:

Querying My Feeds

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Querying Feeds Where I Am a Member

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Querying feeds by name or visibility

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Querying feeds by creator name

$feedResponse1 = $this->testFeed->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId)
);
$feedResponse2 = $this->testFeed2->getOrCreateFeed(
    new GeneratedModels\GetOrCreateFeedRequest(userID: $this->testUserId2)
);

Feeds Queryable Built-in Fields

nametypedescriptionsupported operationsexample
idstring or list of stringsThe ID of the feed$in, $eq{ id: { $in: [ 'abc', 'xyz' ] } }
group_idstring or list of stringsThe ID of the group this feed belongs to$in, $eq{ group_id: { $in: [ 'abc', 'xyz' ] } }
feedstring or list of stringsThe fully qualified feed ID (group_id:id)$in, $eq{ fid: { $in: [ 'abc', 'xyz' ] } }
visibilitystring or list of stringsThe visibility setting of the feed$in, $eq{ visibility: { $eq: 'public' } }
created_by_idstring or list of stringsThe ID of the user who created the feed$in, $eq{ created_by_id: { $in: [ 'abc', 'xyz' ] } }
created_by.namestringThe name of the user who created the feed$eq, $q, $autocomplete{ 'created_by.name': { $autocomplete: 'Frank' } }
namestringThe name of the feed$eq, $q, $autocomplete{ name: { $q: 'Sports' } }
descriptionstringThe description of the feed$eq, $q, $autocomplete{ description: { $autocomplete: 'tech' } }
member_countnumberThe number of members in this feed$eq, $ne, $gt, $lt, $gte, $lte{ member_count: { $gt: 100 } }
memberslist of stringsThe list of members in this feed$in{ members: { $in: [ 'bob', 'alice' ] } }
following_countnumberThe number of feeds this feed follows$eq, $ne, $gt, $lt, $gte, $lte{ following_count: { $gt: 100 } }
following_feedslist of stringsThe list of feeds this feed follows$in{ following_feeds: { $in: [ 'feed1', 'feed2' ] } }
follower_countnumberThe number of followers of this feed$eq, $ne, $gt, $lt, $gte, $lte{ follower_count: { $gt: 100 } }
created_atstring, RFC3339 timestampThe time the feed was created$eq, $gt, $lt, $gte, $lte{ created_at: { $gte: '2023-12-04T09:30:20.45Z' } }
updated_atstring, RFC3339 timestampThe time the feed was updated$eq, $gt, $lt, $gte, $lte{ updated_at: { $gte: '2023-12-04T09:30:20.45Z' } }

Feeds can be sorted by created_at, updated_at, member_count, follower_count, and following_count.

Be sure to reach out to support if you need additional query feed capabilities.

© Getstream.io, Inc. All Rights Reserved.