Posts

Here's an overview of posts and how you can get started with integrating them into your applications

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

Create a Text Post

When creating a text post, call the following method:

import { EkoPostTargetType } from 'eko-sdk';

const post = FeedRepository.createTextPost({
  targetId: 'user1',
  targetType: EkoPostTargetType.UserFeed,
  text: 'hello!',
})

Create an Image Post

import { EkoPostTargetType } from 'eko-sdk';

const post = FeedRepository.createImagePost({
  targetId: 'user1',
  targetType: EkoPostTargetType.CommunityFeed,
  imageIds: ['image1'], // max: 10
})

Create a File Post

import { EkoPostTargetType } from 'eko-sdk';

const post = FeedRepository.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, and file types post 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 = FeedRepository.postForId('post123');

Delete Post

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

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

Post Repository

As well as the general creation of posts, users are also able to interact with posts using the PostRepository. This repository's main purpose is to manage posts, reactions, and flags on a post.

import { PostRepository } from 'eko-sdk';

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');

Last updated