Posts

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.

EkoImage

When you want to parse EkoImage object you can upload image uri or id by using EkoClient.newFileRepository() the following:

val files = mutableListOf<EkoImage>()
        EkoClient.newFileRepository()
                .uploadImage(:uri)
                .build()
                .transfer()
                .doOnNext {
                    when (it) {
                        is EkoUploadResult.COMPLETE -> {
                            files.add(it.image)
                        }
                        is EkoUploadResult.PROGRESS -> {
                            // do something 
                        }
                        is EkoUploadResult.ERROR, EkoUploadResult.CANCELLED -> {
                           // do something 
                        }
                    }
                }
                .subscribeOn(Schedulers.io())
                .subscribe()

EkoFile

When you want to parse EkoFile object you can upload file uri or id by using EkoClient.newFileRepository() the following:

val files = mutableListOf<EkoFile>()
        EkoClient.newFileRepository()
                .uploadFile(:uri)
                .build()
                .transfer()
                .doOnNext {
                    when (it) {
                        is EkoUploadResult.COMPLETE -> {
                            files.add(it.file)
                        }
                        is EkoUploadResult.PROGRESS -> {
                            // do something 
                        }
                        is EkoUploadResult.ERROR, EkoUploadResult.CANCELLED -> {
                            // do something 
                        }
                    }
                }
                .subscribeOn(Schedulers.io())
                .subscribe()

Create a Text Post

When creating a text post, call the following method:

feedRepository.createPost()
                .targetUser("user1")
                .text("hello!")
                .build()
                .post()
                .doOnSuccess {
                    //Do Action
                }
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe()

Create an Image Post

feedRepository.createPost()
                .targetUser("user1")
                .image(*files.toTypedArray())
                .build()
                .post()
                .doOnSuccess {
                    //Do Action
                }
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe()

Create a File Post

feedRepository.createPost()
                .targetUser("user1")
                .file(*files.toTypedArray())
                .build()
                .post()
                .doOnSuccess {
                    //Do Action
                }
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe()

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

Get Post

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

feedRepository.getPost("post123")
                .doOnNext {
                    //Do Action
                }
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe()

Delete Post

feedRepository.deletePost("post123")
                .doOnComplete { 
                    //Do Action
                }
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe()

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

Update Post

If you prefer to update post. You have to use EkoPost that you received for update post and check data type in the following:

val item: EkoPost.Data = post.getData()
        if (item is EkoPost.Data.TEXT) {
            item.edit()
                    .text("hello!")
                    .build()
                    .apply()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe()
        }

Add Reaction

You can add a reaction to a post by using EkoPost that you received and call the following method:

post.react()
                .addReaction("like")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe()

Remove Reaction

You can remove a reaction of a post by using EkoPost that you received and call the following method:

post.react()
                .removeReaction("like")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe()

Add Comment

You can use EkoPost that you received to add a comment to a post by using our Comment feature:

post.comment()
                .with()
                .text("comment!")
                .build()
                .send()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSuccess { 
                    //Do Action
                }
                .subscribe()

Reply Comment

You can use EkoPost that you received for reply a comment to a post by using our Comment feature:

post.comment()
                .parentId("parentId")
                .with()
                .text("reply comment!")
                .build()
                .send()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnSuccess { 
                    //Do Action
                }
                .subscribe()

Flag Post

You can use EkoPost that you received for flag a post as inappropriate by using the following method:

post.report()
                .flag()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnComplete {
                    //Do Action
                }
                .subscribe()

Check for isFlaggedByMe

You can use EkoPost that you received to get status flag the following:

val result = post.isFlaggedByMe()

Unflag Post

You can use EkoPost that you received for unflag a post the following method:

post.report()
                .unflag()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnComplete {
                    //Do Action
                }
                .subscribe()

Last updated