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 will be able to generate different types of posts as well as to react and comment on posts. SDK provides different builder classes to create each type of post. First, you need to build the post by using one of the builder classes. Then use the instance of EkoFeedRepository
to actually create the post. createPost
method requires instance of builder, targetId
and targetType
. TargetType is an enum with two cases, which is user
and community
.
If you want to create a post on a particular user's feed, you can provide the id of that user for targetId parameter. If you want to create a post on your own feed, set targetId to nil. If you want to post on particular community, then targetType would be community.
Create a Text Post
Use EkoTextPostBuilder
to create text post.
Create an Image Post
In order to create image post, images must be uploaded first. SDK provides a convenient class EkoFileRepository
to handle upload and download images. The repository contains uploadImages
method which takes array of UIImage
and provides you with array of EkoImageData
for successful upload and array of UIImage
for failed uploads.
A post can have maximum 10 images.
Now to create the image post. We can build the post first by using EkoImagePostBuilder
. Then use the same createPost
method in EkoFeedRepository
to create image post.
Create a File Post
File post follows the same order as image post. First you upload the file using EkoFileRepository
, build the post using EkoFilePostBuilder
and then finally create the post. To upload the file, EkoFileRepository
provides uploadFile
method which takes an instance of UploadableFile
. It provides you with EkoFileData
for successful upload and Error
for failed upload. Its okay to call this method inside a loop if you want to upload multiple files.
Note: A post can consist of either a list of images or a list of files but not both.
Now to create file post, we build the post using EkoFilePostBuilder
.
Get Post
You can also query for each individual post based on its postId. EkoFeedRepository
provides a convenient method getPostForPostId(_:)
which returns EkoObject<EkoPost>
.
The observe
block can get called multiple times depending upon where the post is being fetched from. We can check the dataStatus
property for liveObject to see if the post is being fetched from server or locally. Please refer to Accessing Post Information section.
Delete Post
EkoFeedRepository
provides another convenient method to delete post. To delete the post, you just need the post id. If you are deleting child post, you need to pass the parent id too. If it is the parent post, just pass nil
.
Note: Only the post owner or an admin will be able to delete a post.
Accessing Post Information
Each post is represented by EkoPost
instance. Each instance of EkoPost
holds several information such as data, reactions, comments, metadata, child posts etc. For text based post, you can access to the actual data for the post through data
property.
Post with images or files follow Parent - Child relationship. Each images or files uploaded will be a separate child post. Any text that you set while creating image/file post will act as a Parent post. Parent post contains childrenPosts
property which gives you array of EkoPost
.
You can access data for child post through same data
property for child post. Alternatively, you can also access more details about uploaded files and images through getFileInfo()
or getImageInfo()
method.
Let's consider our post contains some text & 1 image. This means parent post would be a text post and its child post will be an image post. Here is how we can access it.
Add Reaction
You can add any number of reactions to the given post. EkoReactionRepository
provides addReaction
method which accepts reaction name. Reaction name is case sensitive i.e "like" & "Like" are two different reactions.
Remove Reaction
You can remove any reactions added to the post. EkoReactionRepository
provides removeReaction
method which removes reaction name. Reaction name is case sensitive in this case too.
Flag a Post
You can flag a post as inappropriate using EkoPostFlagger
instance.
Check for isFlaggedByMe
Unflag Post
Comments
EkoPost
object provides few latest comments through latestComments
property. To fetch all comments for the post, please refer to documentation for Comments.
Last updated