Community Membership
You can get a list of community members through community participation class. It exposes the method to get the members of the community, which accepts membership options and sorting parameters.
iOS
Android
JavaScript
TypeScript
Flutter
- The
membershipOptions
parameter can have the following filters:.none
- filters all non-members in a community.member
- filters all unbanned members in a community.ban
- filters all banned members in a community
- The
roles
parameter filter members by specific role.To query members with the default moderator roles assigned, you can use'channel-moderator'
,'community-moderator
'. At this moment, we do not have a way to query for member-only roles. However, if you have assigned a custom role to a member in the community, you can pass in theroleId
of the custom role to filter members by this role.
Please note that you can only assign custom roles to a member in a community via the SDK. This feature is not yet available in the Amity Console.
If you assign a custom role to a user via the Amity console, the role will only be applied at the user level and not at the community level, and if you try to query for a member with this custom role, no results will be returned.
sortBy
- sorting method to arrange the returned collection. The possible values are: (seeCommunitySortingMethod
)'firstCreated'
'lastCreated'
'displayName'
search
- query string
AmityCommunityMembershipFilter
AmityCommunityMembershipFilter.ALL
AmityCommunityMembershipFilter.BANNED
AmityCommunityMembershipFilter.MEMBER
AmityCommunityMembershipFilter.NONE
AmityCommunityMembershipSortOption.FIRST_CREATED
AmityCommunityMembershipSortOption.LAST_CREATED
Required Parameters
communityId
- the ID of the community to query
Optional Parameters
memberships
- filter for membership type. The possible values are: (seeCommunityUserMembership
)'none'
- not a member of the community'member'
- member of the community'banned'
- member banned from the community
sortBy
- sorting method to arrange the returned collection. The possible values are: (seeCommunitySortingMethod
)'firstCreated'
'lastCreated'
The default value of
sortBy
is LAST_CREATED
so you can skip .sortBy
in builder.communityId
- the ID of the community to query
memberships
- filter for membership type. The possible values are: (seeCommunityUserMembership
)'none'
- not a member of the community'member'
- member of the community'banned'
- member banned from the community
roles
- filter members by specific role. To query members with the default moderator roles assigned, you can use'channel-moderator'
,'community-moderator
'. At this moment, we do not have a way to query for member-only roles. However, if you have assigned a custom role to a member in the community, you can pass in theroleId
of the custom role to filter members by this role.
Please note that you can only assign custom roles to a member in a community via the SDK. This feature is not available yet on Amity Console.
Applying a custom role to a user via Amity Console will only apply the role at the user-level, and not at the community level, and if you try to query for a member with this custom role, no results will be returned.
sortBy
- sorting method to arrange the returned collection. The possible values are: (seeCommunitySortingMethod
)'firstCreated'
'lastCreated'
'displayName'
communityId
- the ID of the community to query
memberships
- filter for membership type. The possible values are: (seeCommunityUserMembership
)'none'
- not a member of the community'member'
- member of the community'banned'
- member banned from the community
roles
- filter members by specific role. To query members with the default moderator roles assigned, you can use'channel-moderator'
,'community-moderator
'. At this moment, we do not have a way to query for member-only roles. However, if you have assigned a custom role to a member in the community, you can pass in theroleId
of the custom role to filter members by this role.
Please note that you can only assign custom roles to a member in a community via the SDK. This feature is not available yet on Amity Console.
Applying a custom role to a user via Amity Console will only apply the role at the user-level, and not at the community level, and if you try to query for a member with this custom role, no results will be returned.
sortBy
- sorting method to arrange the returned collection'firstCreated'
'lastCreated'
'displayName'
Available sort options:
AmityMembershipSortOption.LAST_CREATED
AmityMembershipSortOption.FIRST_CREATED
Available filter options:
AmityCommunityMembershipFilter.ALL
AmityCommunityMembershipFilter.MEMBER
AmityCommunityMembershipFilter.NOT_MEMBER
iOS
Android
JavaScript
TypeScript
Flutter
Passing an empty option set for
membershipOptions
parameter will default to .member
. This means that the result for both sample code below is the same.Same class provides
addMembers(_:)
and removeMembers(_:)
which can be used to add or remove users from the community.Passing an empty option set for
membershipOptions
parameter will default to .member
.Below is the sample code to get a list of community members. This method will return a
LiveCollection
instance. Last modified 1mo ago