Feed & Timeline
Let your users showcase their unique personality right in their timelines
Feed is a new way for users to create content on various areas of the SDK. Currently, users and groups can have feeds. Each feed consists of a collection of posts. Users are able to create posts on any groups that they are a member of and any user that they can find.
There are 3 types of feeds:
  1. 1.
    User Feed This is a collection of posts for a user's timeline.
  2. 2.
    Group Feed This is a collection of posts from members of the group or community.
  3. 3.
    Global Feed This is an aggregate of both User and Group feeds.
Feed management methods are all contained in a PostRepository class.
1
import { PostRepository } from '@amityco/js-sdk';
Copied!

Query User Feed

You can get any user's feed by calling the method below with the userId:
1
const liveFeed = PostRepository.queryUserPosts({
2
userId: 'user1',
3
tags: ['a','b'], //optional, max no. of tags = 5, max length per tag = 24 chars
4
});
5
6
liveFeed.once('dataUpdated', posts => {
7
console.log(posts.map(post => post.postId))
8
});
Copied!
When querying posts, the tags parameter is always optional regardless of which feed you are querying. Up to five tags can be added and each tag can be up to 24 characters long. If you don't want to filter by tags when querying, just omit the tags parameter. Do not pass an empty array.
There is a quick easy method to get your own feed:
1
const liveFeed = PostRepository.queryMyPosts();
2
3
liveFeed.once('dataUpdated', posts => {
4
console.log(posts.map(post => post.postId))
5
});
Copied!

Query Group Feed

You can get any group's feed by calling the method below with the communityId:
1
const liveFeed = PostRepository.queryCommunityPosts({
2
communityId: 'community1',
3
tags: ['a','b'], //optional, max no. of tags = 5, max length per tag = 24 chars
4
});
5
6
liveFeed.once('dataUpdated', posts => {
7
console.log(posts.map(post => post.postId))
8
});
Copied!

Query Global Feed

You can retrieve your global feed by calling the following method:
1
const liveFeed = PostRepository.queryAllPosts();
2
3
liveFeed.once('dataUpdated', posts => {
4
console.log(posts.map(post => post.postId))
5
});
Copied!

Implementing feed pagination

Whether you're querying a user, group, or global feed, Live Collection will return a maximum of 20 posts in each page. You can easily fetch more posts by using the nextPage() method from the same live collection.
1
const liveCollection = PostRepository.queryCommunityPosts({
2
communityId: 'community1',
3
});
4
liveCollection.on(“dataUpdated”, posts => console.log(posts))
5
6
If (liveCollection.hasMore) liveCollection.nextPage()
Copied!
Last modified 1mo ago