Links

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.
import { PostRepository } from '@amityco/js-sdk';

Query User Feed

You can get any user's feed by calling the method below with the userId:
const liveFeed = PostRepository.queryUserPosts({
userId: 'user1',
tags: ['a','b'], //optional, max no. of tags = 5, max length per tag = 24 chars
});
liveFeed.once('dataUpdated', posts => {
console.log(posts.map(post => post.postId))
});
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:
const liveFeed = PostRepository.queryMyPosts();
liveFeed.once('dataUpdated', posts => {
console.log(posts.map(post => post.postId))
});

Query Group Feed

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

Query Global Feed

You can retrieve your global feed by calling the queryAllPosts method. This method accepts the following parameters:
Parameter
Data type
Description
includeChildrenPosts
boolean
yes = include children posts
includeDeletedPosts
boolean
yes = include deleted posts
sortby
string
sort by 'firstCreated' or 'lastCreated'
useCustomRanking
boolean
yes = use custom post ranking (Refer to Custom Post Ranking for more details.) no = posts will be arranged in chronological order
All these parameters are optional. Below is the sample code to query the global feed.
const liveFeed = PostRepository.queryAllPosts({
useCustomRanking: true,
useExperimental: true
});
liveFeed.once('dataUpdated', posts => {
console.log(posts.map(post => post.postId))
});
The method will return a LiveCollection instance of post model.
The queryAllPosts method will throw an error if parameters passed are incorrect.

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.
const liveCollection = PostRepository.queryCommunityPosts({
communityId: 'community1',
});
liveCollection.on(“dataUpdated”, posts => console.log(posts))
const loadMore = () => {
if (liveCollection.hasMore) {
liveCollection.nextPage();
}
};
The dataUpdated event will be dispatched when the first set of data from the server is loaded. Calling nextPage will load the next set of data. Once all data are loaded, the dataUpdated event will once again be dispatched.