Communities is a new way for users to join and interact with other users. Each channel contains a community
When creating communities, users can pass a displayName
, which will be the name of the community.
You will not be able to create a community from an existing channel. New communities will need to be created with new
channelIds
.
There are three ways of obtaining a community: via create, join, or get. They all return a RxJava with the final community model.
Community management methods are all contained in a EkoCommunityRepository
class. Before calling any community methods, you must ensure to first instantiate a repository instance.
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.
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()
If you prefer create community with an avatar you can first upload image with EkoFileRepository
then pass the obtained EkoImage
to createCommunity
API.
private var avatar : EkoImage? = nullEkoClient.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()
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.
communityRepository.joinCommunity("community1").subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnComplete {//Do Action}.subscribe()
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:
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
EkoCommunitySortOption
EkoCommunitySortOption.DISPLAY_NAMEEkoCommunitySortOption.LAST_CREATEDEkoCommunitySortOption.FIRST_CREATED
EkoCommunityFilter
EkoCommunityFilter.ALLEkoCommunityFilter.MEMBEREkoCommunityFilter.NOT_MEMBER
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:
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:
EkoCommunityMembershipFilter
EkoCommunityMembershipFilter.ALLEkoCommunityMembershipFilter.BANNEDEkoCommunityMembershipFilter.MEMBEREkoCommunityMembershipFilter.NONE
EkoCommunityMembershipSortOption
EkoCommunityMembershipSortOption.FIRST_CREATEDEkoCommunityMembershipSortOption.LAST_CREATED
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
.
EkoClient.newCommunityRepository().membership(:communityId).getCommunityMembership(:userId).subscribe()
Creator of community can add and remove role of user via EkoCommunityModeration
.
//Add roleEkoClient.newCommunityRepository().moderate(:communityId).addRole(role = :roleName, userIds = listOf(:userId)).subscribe()​//Remove roleEkoClient.newCommunityRepository().moderate(:communityId).removeRole(role = :roleName, userIds = listOf(:userId)).subscribe()
The EkoCommunityParticipation
provides a list of members by role in the given community.
EkoClient.newCommunityRepository().membership(:communityId).getCollection().roles(listOf(:roleName)).build().query().subscribe()
You can check your permission in community by send EkoPermission
enums to EkoClient.hasPermission(:ekoPermission)
method.
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 admin panel.
This method provides the ability to obtain all the categories.
EkoCommunityCategorySortOption
EkoCommunityCategorySortOption.FIRST_CREATEDEkoCommunityCategorySortOption.NAMEEkoCommunityCategorySortOption.LAST_CREATED
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