Here's an overview of how you can get started integrating comments into your applications
Create Repository
Copy val communityRepository = EkoClient. newCommunityRepository ()
When creating a new community, first instantiates the EkoCommunityRepository
, a class that contain all community related methods. Then call createCommunity()
to obtain the RxJava and observe it in order to obtain the final community model.
Copy communityRepository
. createCommunity ( "community1" )
. isPublic ( true )
. description ( "hello and welcome!" )
. categoryIds ( listOf ( "new" ))
. userIds ( listOf ( "user1" , "user2" ))
. build ()
. create ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. doOnSuccess {
//Do Action
}
. subscribe ()
With Avatar
If you prefer create community with an avatar you can first upload image with EkoFileRepository
then pass the obtained EkoImage
to createCommunity
API.
Step 1.
Copy private var avatar : EkoImage ? = null
EkoClient. newFileRepository ()
. uploadImage (uri)
. build ()
. transfer ()
. doOnNext {
when (it) {
is EkoUploadResult.COMPLETE -> {
avatar = it. getFile ()
}
is EkoUploadResult.PROGRESS -> {
Log. d ( "LOG " , "EkoImageUpload.PROGRESS" )
}
is EkoUploadResult.ERROR, EkoUploadResult.CANCELLED -> {
Log. d ( "LOG " , "EkoImageUpload.CANCELLED" )
}
}
}
. subscribeOn (Schedulers. io ())
. subscribe ()
Step 2.
Copy communityRepository
. createCommunity ( "community1" )
. avatar (avatar)
. build ()
. create ()
. subscribeOn (Schedulers. io ())
. subscribe ()
The joinCommunity()
method will add the active user as a member of the channel.
This API can be called as many time as needed. If the community has already been joined, a "success" result will be returned, ie., going into doOnComplete{}
block.
Copy communityRepository
. joinCommunity ( "community1" )
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. doOnComplete {
//Do Action
}
. subscribe ()
Copy communityRepository
. leaveCommunity ( "community1" )
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. doOnComplete {
//Do Action
}
. subscribe ()
In the case where you only want to fetch a community data without joining, you can use the getCommunity(:id)
method:
Copy communityRepository
. getCommunity ( "community1" )
. firstOrError ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. doOnSuccess {
//Do Action
}
. subscribe ()
There are methods to obtain communities that only match specific criteria:
the withKeyword
parameter let you filter communities based on the community displayName
the sortBy
parameters let you filter communities based on the order that the communities were created or based on alphabetical order
the filter
parameter let you filter communities based on the logged in user membership status
the categoryId
parameters let you filter communities based on community categories
Enum Types
Copy EkoCommunitySortOption.DISPLAY_NAME
EkoCommunitySortOption.LAST_CREATED
EkoCommunitySortOption.FIRST_CREATED
Copy EkoCommunityFilter.ALL
EkoCommunityFilter.MEMBER
EkoCommunityFilter.NOT_MEMBER
Copy communityRepository. getCommunityCollection ()
. withKeyword ( "keyword" )
. sortBy (EkoCommunitySortOption.LAST_CREATED)
. filter (EkoCommunityFilter.ALL)
. categoryId ( "categoryId" )
. build ()
. query ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. subscribe {
//Do action
}
If you want to update a community, you can call the following:
Copy communityRepository
. updateCommunity ( "community1" )
. isPublic ( true )
. description ( "hi this is a community" )
. categoryIds ( listOf ( "news" ))
. avatar ( * files. toTypedArray ())
. build ()
. update ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. doOnSuccess {
//Do Action
}
. subscribe ()
Note. By default, only the community's original creator or administrators can update the community.
You can get a list of community members by calling the following method:
Enum Types
Copy EkoCommunityMembershipFilter.ALL
EkoCommunityMembershipFilter.BANNED
EkoCommunityMembershipFilter.MEMBER
EkoCommunityMembershipFilter.NONE
Copy EkoCommunityMembershipSortOption.FIRST_CREATED
EkoCommunityMembershipSortOption.LAST_CREATED
Copy communityRepository. membership (communityId)
. getCollection ()
. filter (EkoCommunityMembershipFilter.ALL)
. sortBy (EkoCommunityMembershipSortOption.FIRST_CREATED)
. build ()
. query ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. doOnNext {
//Do Action
}
. subscribe ()
Note. By default of sortBy is LAST_CREATED so you can skip .sortBy in builder
also you can query community membership with userId by use getCommunityMembership(:userId)
via EkoCommunityParticipation
.
Copy EkoClient . newCommunityRepository ()
. membership ( : communityId)
. getCommunityMembership ( : userId)
. subscribe ()
Role and Permission
Creator of community can add and remove role of user via EkoCommunityModeration
.
Role
Copy //Add role
EkoClient . newCommunityRepository ()
. moderate ( : communityId)
. addRole (role = : roleName , userIds = listOf( : userId) )
. subscribe ()
//Remove role
EkoClient . newCommunityRepository ()
. moderate ( : communityId)
. removeRole (role = : roleName , userIds = listOf( : userId) )
. subscribe ()
Query memberships by role
The EkoCommunityParticipation
provides a list of members by role in the given community.
Copy EkoClient . newCommunityRepository ()
. membership ( : communityId)
. getCollection ()
. roles ( listOf( : roleName) )
. build ()
. query ()
. subscribe ()
Permission
You can check your permission in community by sending EkoPermission
enums to EkoClient.hasPermission(:ekoPermission)
method.
Copy EkoClient . hasPermission ( : ekoPermission)
. atCommunity ( : communityId)
. check ()
. subscribe ()
The EkoCommunityRepository
will also be able to manage community categories. When communities are put into a category, you will be able to sort and filter each of the communities in that category.
Note. Right now categories will only be creatable and updatable from the Amity Social Cloud Console.
Category Query
This method provides the ability to obtain all the categories.
Enum Types
Copy EkoCommunityCategorySortOption.FIRST_CREATED
EkoCommunityCategorySortOption.NAME
EkoCommunityCategorySortOption.LAST_CREATED
Copy communityRepository
. getAllCategories ()
. sortBy (EkoCommunityCategorySortOption.LAST_CREATED)
. build ()
. query ()
. subscribeOn (Schedulers. io ())
. observeOn (AndroidSchedulers. mainThread ())
. doOnNext {
//Do Action
}
. subscribe ()
Note. By default of sortBy is NAME so you can skip .sortBy in builder