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 LiveObject with the final community model.
Community management methods are all contained in a CommunityRepository
class. To start using community methods, you only need to import the CommunityRepository.
import { CommunityRepository } from 'eko-sdk';
When creating a new community, first instantiates the CommunnityRepository
, a class that contain all community related methods. Then call createCommunity()
to obtain the LiveObject and observe it in order to obtain the final community model.
When creating a new community, first instantiates the CommunnityRepository
, a class that contain all community related methods. Then call createCommunity()
to obtain the LiveObject and observe it in order to obtain the final community model.
const liveCommunity= CommunityRepository.createCommunity({displayName: 'community1',description: 'hello and welcome!',avatarFileId: 'fileId123',categoryIds: ['new'],tags: ['foo'],metadata: {},isPublic: true,userIds: ['user1', 'user2'],})​liveCommunity.once('dataUpdated', model => {console.log(`Community created: ${model.displayName}`);});
Note that the event listener was registered using once()
. Unlike on()
, once()
will automatically unregister the event listener once the first event was emitted. This is useful if you just need to use the model once but do not need to listen to further events.
Note that the event listener was registered using once()
. Unlike on()
, once()
will automatically unregister the event listener once the first event was emitted. This is useful if you just need to use the model once but do not need to listen to further events.
In the case where you only want to fetch communities data without joining, you can use the communityForId()
method:
const liveCommunity = Community.communityForId('abc');​liveCommunity.once('dataUpdated', data => {...});
const communityHasBeenJoined = await CommunityRepository.joinCommunity('abc');console.log(communityHasBeenJoined) // true
In the case where you only want to fetch communities data without joining, you can use the communityForId()
method:
const communityHasBeenLeft = await CommunityRepository.leaveCommunity('abc');console.log(communityHasBeenLeft) // true
There are methods to obtain communities that only match specific criteria:
the search
parameter let you filter communities based on the community displayName
the isJoined
parameter let you filter communities based on the logged in user membership status
the tags
parameters let you filter communities based on the tags set (or not set) in each community
the categories
parameters let you filter communities based on community categories
the sortBy
parameters let you filter communities based on the order that the communities were created or based on alphabetical order
const communities = CommunityRepository.allCommunitiesWithFilters({search: 'community1',categoryId: 'newsCatId',isDeleted: false,tags: ['new'],filter: enum('all'|'member|'notMember'),sortBy: enum('firstCreated'|'lastCreated'|'displayName'),});​communities.on('dataUpdated', models => {// reload data});
If you want to update a community, you can call the following:
const liveCommunity = CommunityRepository.updateCommunity({displayName: 'community1',description: 'hi this is a community',avatarFileId: 'fileId123',categoryIds: ['news'],tags: ['new'],metadata: {},isPublic: true,});​liveCommunity.once('dataUpdated', data => {...});
Note. By default, only the communities original creator or adminstrators can update the community.
Note. By default, only the communities original creator or adminstrators can update the community.
You can get a list of community members by calling the following method:
const members = CommunityCategory.getCommunityMembers({communityId: 'communnity123',filter: enum('all'|'member'|'notMember'),sortBy: enum('firstCreated'|'lastCreated'),​});members.on('dataUpdated', models => {// reload member table});​// unobserve data changes once you are finishedmembers.removeAllListeners('dataUpdated');
The CommunityRepository
will also be able to manage community categories. When community are put into a category, you will be able to sort and filter each of the community in that category.
The CommunityRepository
will also be able to manage community categories. When community are put into a category, you will be able to sort and filter each of the community in that category.
Note. Right now categories will only be creatable and updatable from the admin panel.
You can fetch a particular category by calling the categoryForId()
method:
const liveCategory = CommunityCategory.categoryForId('abc');​liveCategory.once('dataUpdated', data => {...});
You can also fetch a list of categories:
const liveCategory = CommunityCategory.categoriesForIds({categoryIds: ['news']});​liveCategory.once('dataUpdated', data => {...});
This method provides the ability to obtain all the categories.
const liveCategory = CommunityCategory.queryCategories({isDeleted: false,sortBy: enum('firstCreated'|'lastCreated'|'displayName'),});​liveCategory.on('dataUpdated', models => {// reload data});