Communities

Build and nurture vibrant communities where users can exchange and connect

Create Community

First, you will need to create the community by using EkoCommunityCreationDataBuilder instance. The mandatory property is displayName. You can set other properties as per your necessities.

let builder = EkoCommunityCreationDataBuilder()
builder.setDisplayName("Test")
builder.setTags(["test"])
builder.setCommunityDescription("For testing")
builder.setIsPublic(false)
builder.setMetadata(["test": "test-content"])

communityRepository.createCommunity(builder, completion: { (liveObject, error) in
    // Do something
})

Join Community

communityRepository.joinCommunity(withCommunityId: "community-id") {  (success, error) in
    // Do something
}

Leave Community

communityRepository.leaveCommunity(withCommunityId: "community-id") {  (success, error) in
    // Do something
}

Get Community

In the case where you only want to fetch a community's data without joining, you can use the getCommunity(withId:) method:

collection = communityRepository.getCommunity(withId: testCommunityId)
token = collection.observe { [weak self] (community, error) in
    // Do something
}

Community Query

There are methods to obtain communities that will only meet certain specific criterias:

  • the keyword parameter allows you to filter communities based on the community displayName

  • 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

  • the sortBy parameters let you filter communities based on the order that the communities were created or based on alphabetical order

  • the includeDeleted parameters let you specify if you want to include deleted communities in your query

If you want to fetch all communities, you can pass the keyword as nil.

let collection = communityRepository.getCommunitiesWithKeyword("search-keyword", filter: .all, sortBy: .lastCreated, categoryId: nil, includeDeleted: false)
token = collection.observe({ [weak self] (collection, _, _) in
    // React to changes here
})

Community Repository also provides a way to fetch trending communities or recommended communities. getTrendingCommunities method fetches trending communities whereas getRecommendedCommunities method fetches recommended communities.

Update Community

SDK provides the builder class EkoCommunityUpdateDataBuilder which allows you to set properties that you want to update. Then you can use updateCommunity method in EkoCommunityRepository to update the community.

let builder = EkoCommunityUpdateDataBuilder()
builder.setDisplayName("updated-name")
builder.setCommunityDescription("updated-description")
builder.setIsPublic(false)
...       
communityRepository.updateCommunity(withId: "community-id", builder: builder, completion: { (community, error) in
    // React to changes here
})

You can also delete the community by using deleteCommunity(_:) method.

Note. By default, only the community's original creator or administrators can update/delete the community.

Community Membership

You can get a list of community members through EkoCommunityParticipation class. It exposes getMemberships method which accepts filter and sortBy parameters.

let membershipCollection = communityParticipation.getMemberships(.all, roles: [], sortBy: .firstCreated)
token = membershipCollection.observe({ (collection, change, error) in
    // React to changes here
})

Same class provides addUsers(_:) and removeUsers(_:) which can be used to add or remove user from the community.

Community Moderation

EkoCommunityModeration class provides a way to moderate the community by banning or unbanning users. banUsers(_:) method accepts array of user ids to ban and unbanUsers(_:) accepts array of user ids to unban. You can also add/remove roles using addRole(_:) and removeRole(_:) method.

addRole(_:) and removeRole(_:) does not create new roles but assign and remove existing roles from given user.

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. You can access the categories for any communities through categories property in each EkoCommunity object.

Note: Categories can only be created and updated from Amity Social Cloud Console.

Get Categories

categoryColllection = communityRepository.getAllCategories(.displayName, includeDeleted: true|false)
categoryCollectionToken = categoryColllection?.observe({ (collection, _, _) in
    // React to changes here
})

Last updated