Feed

Feeds are 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 group that they are a member of and any user that they can find.

There is also a global feed which is an aggregate of all the posts in a user's feeds.

Feed management methods are all contained in a FeedRepository class.

import { FeedRepository } from 'eko-sdk';

Query User Feed

You can get any user's feed by calling the method below with the userId:

const liveFeed = FeedRepository.getUserFeed({
userId: 'user1'
});
liveFeed.once('dataUpdated', models => {
//
});

There is also a quick easy method to get your own feed:

const liveFeed = FeedRepository.getMyFeed();
liveFeed.once('dataUpdated', models => {
//
});

Query Group Feed

You can get any group's feed by calling the method below with the communityId:

const liveFeed = FeedRepository.getCommunityFeed({
communityId: 'community1',
});
liveFeed.once('dataUpdated', models => {
//
});

Query Global Feed

You can retrieve your global feed by calling the following method:

const liveFeed = FeedRepository.getGlobalFeed();
liveFeed.once('dataUpdated', models => {
//
});

Post Repository

A feed is made up of a collection of posts. Users are able to generate different types of posts as well as be able to react and comment on posts using PostRepository.

import { PostRepository } from 'eko-sdk';

Create a Text Post

When creating a text post, calling the following method:

import { EkoPostTargetType, PostRepository } from 'eko-sdk';
const post = PostRepository.createTextPost({
targetId: 'user1',
targetType: EkoPostTargetType.UserFeed,
text: 'hello!',
})

Create an Image Post

import { EkoPostTargetType, PostRepository } from 'eko-sdk';
const post = PostRepository.createImagePost({
targetId: 'user1',
targetType: EkoPostTargetType.CommunityFeed,
imageIds: ['image1'], // max: 10
})

Create a File Post

import { EkoPostTargetType, PostRepository } from 'eko-sdk';
const post = PostRepository.createFilePost({
targetId: 'group1',
targetType: EkoPostTargetType.CommunityFeed,
fileIds: ['file1'], // max: 10
})

Note. A post can consist of either a list of images or a list of files but not both.

Create a Custom Post

If text, image, files type posts are not enough for you, you can create your own type with whatever data you need for rendering. To do this, you need to call PostRepository.createPost and pass dataType, a string that defines the type of the post so you can distinguish your new post from others, and data, an object containing whatever data you need for your post.

import { EkoPostTargetType, PostRepository } from 'eko-sdk';
const post = PostRepository.createPost({
targetId: 'group1',
targetType: EkoPostTargetType.CommunityFeed,
dataType: 'birthdayPost',
data: {
userId: '123',
birthdayMessage: 'Happy Birthday, dear user 123',
},
})

Get Post

You can use the postForId() method in order to get a single post:

const post = PostRepository.postForId('post123');

Delete Post

const post = PostRepository.deletePost('post123');

Note. Only the post owner or an admin are able to delete a post.

Note. Only the post owner or an admin are able to update a post.

Update Post

const post = PostRepository.updatePost({
postId: 'post123',
data: { text: 'hello!'},
});

Add Reaction

You can add a reaction to a post by calling the following method:

const result = PostRepository.addReaction({
postId: 'post123',
reactionName: 'like',
});

Remove Reaction

const result = PostRepository.removeReaction({
postId: 'post123',
reactionName: 'like',
});

Add Comment

You can also add a comment to a post using our Comment feature:

const commentLiveObject = CommentRepository.createTextComment({
referenceType: 'post',
referenceId: 'post123',
text: 'Hi!',
});

See more on Comments

Flag Post

You can flag a post as inappropriate using the following method:

const result = PostRepository.flag('post123');

Check for isFlaggedByMe

const result = PostRepository.isFlaggedByMe();

Unflag Post

const result = PostRepository.unflag('post123');