Community

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.

Create Repository

val communityRepository = EkoClient.newCommunityRepository()

Create Community

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()

With Avatar

If you prefer create community with an avatar you can first upload image with EkoFileRepository then pass the obtained EkoImageto createCommunityAPI.

Step1

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()

Step2

communityRepository
.createCommunity("community1")
.avatar(avatar)
.build()
.create()
.subscribeOn(Schedulers.io())
.subscribe()

Join Community

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()

Leave Community

communityRepository
.leaveCommunity("community1")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnComplete {
//Do Action
}
.subscribe()

Get Community

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()

Community Query

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

EkoCommunitySortOption

EkoCommunitySortOption.DISPLAY_NAME
EkoCommunitySortOption.LAST_CREATED
EkoCommunitySortOption.FIRST_CREATED

EkoCommunityFilter

EkoCommunityFilter.ALL
EkoCommunityFilter.MEMBER
EkoCommunityFilter.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
}

Update Community

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.

Community Membership

You can get a list of community members by calling the following method:

Enum Types

EkoCommunityMembershipFilter

EkoCommunityMembershipFilter.ALL
EkoCommunityMembershipFilter.BANNED
EkoCommunityMembershipFilter.MEMBER
EkoCommunityMembershipFilter.NONE

EkoCommunityMembershipSortOption

EkoCommunityMembershipSortOption.FIRST_CREATED
EkoCommunityMembershipSortOption.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()

Role and Permission

Creator of community can add and remove role of user via EkoCommunityModeration.

Role

//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.

EkoClient.newCommunityRepository()
.membership(:communityId)
.getCollection()
.roles(listOf(:roleName))
.build()
.query()
.subscribe()

Permission

You can check your permission in community by send EkoPermission enums to EkoClient.hasPermission(:ekoPermission) method.

EkoClient.hasPermission(:ekoPermission)
.atCommunity(:communityId)
.check()
.subscribe()

Community Categories

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.

Category Query

This method provides the ability to obtain all the categories.

Enum Types

EkoCommunityCategorySortOption

EkoCommunityCategorySortOption.FIRST_CREATED
EkoCommunityCategorySortOption.NAME
EkoCommunityCategorySortOption.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