Manage group members
This guide covers querying and managing channel members, including admins and followed members.
Channel members
Get members by role (paginated)
Call createGroupMembersByRoleQueryWithParams: on NCGroupChannel to create a query object, then call loadNextPageWithCompletion: to fetch pages:
- Swift
- Objective-C
import NexconnChatSDK
let params = GroupMembersByRoleQueryParams()
params.groupId = "groupId"
params.role = .undef
params.pageSize = 20
params.isAscending = false
let query = GroupChannel.createGroupMembersByRoleQuery(params: params)
query.loadNextPage { page, error in
if error == nil, let page, !page.data.isEmpty {
// Load next page by calling loadNextPage again
}
}
NCGroupMembersByRoleQueryParams *params = [[NCGroupMembersByRoleQueryParams alloc] init];
params.groupId = @"groupId";
params.role = NCGroupMemberRoleUndef;
params.pageSize = 20;
params.isAscending = NO;
NCGroupMembersByRoleQuery *query = [NCGroupChannel createGroupMembersByRoleQueryWithParams:params];
[query loadNextPageWithCompletion:^(NCGroupMembersByRolePageResult *result, NCError *error) {
if (error == nil && result.data.count > 0) {
// Load next page by calling loadNextPageWithCompletion: again
}
}];
Role enum (NCGroupMemberRole):
| Value | Description |
|---|---|
NCGroupMemberRoleUndef | All roles |
NCGroupMemberRoleNormal | Channel member |
NCGroupMemberRoleManager | Channel admin |
NCGroupMemberRoleOwner | Channel owner |
Get specific members
Call getMembersWithUserIds:completion: on an NCGroupChannel instance to get info for specific users (max 100 per call):
You must be a channel member to query member info.
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else {
return
}
channel.getMembers(userIds: ["user1", "user2"]) { members, error in
if error == nil {
// Success
print("Matched members: \(members?.count ?? 0)")
}
}
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel getMembersWithUserIds:@[@"user1", @"user2"]
completion:^(NSArray<NCGroupMemberInfo *> *members, NCError *error) {
if (error == nil) {
// Success
}
}];
Search members by nickname
Call createSearchGroupMembersQueryWithParams: on NCGroupChannel to create a search query:
- Swift
- Objective-C
import NexconnChatSDK
let params = SearchGroupMembersQueryParams()
params.groupId = "groupId"
params.memberName = "searchQuery"
params.pageSize = 20
let query = GroupChannel.createSearchGroupMembersQuery(params: params)
query.loadNextPage { members, error in
if error == nil {
// Handle results
print("Matched members: \(members?.count ?? 0)")
}
}
NCSearchGroupMembersQueryParams *params = [[NCSearchGroupMembersQueryParams alloc] init];
params.groupId = @"groupId";
params.memberName = @"searchQuery";
params.pageSize = 20;
NCSearchGroupMembersQuery *query = [NCGroupChannel createSearchGroupMembersQueryWithParams:params];
[query loadNextPageWithCompletion:^(NSArray<NCGroupMemberInfo *> *members, NCError *error) {
// Handle results
}];
Set member info
Call setMemberInfoWithParams:completion: on an NCGroupChannel instance to update a member's nickname or extra data. The memberInfoEditPermission setting controls who can modify member info.
All members receive onGroupMemberInfoChanged on success.
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else {
return
}
let params = SetGroupMemberInfoParams()
params.userId = "user1"
params.nickname = "Display Name"
params.extra = "extra info"
channel.setMemberInfo(params: params) { errorKeys, error in
if error == nil {
// Updated
print("Failed keys: \(errorKeys ?? [])")
}
}
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
NCSetGroupMemberInfoParams *params = [[NCSetGroupMemberInfoParams alloc] init];
params.userId = @"user1";
params.nickname = @"Display Name";
params.extra = @"extra info";
[channel setMemberInfoWithParams:params
completion:^(NSArray<NSString *> *errorKeys, NCError *error) {
if (error == nil) {
// Updated
}
}];
Channel admins
Add admins
Call addManagersWithUserIds:completion: on an NCGroupChannel instance to promote members to admin. All members receive onGroupOperation with type NCGroupOperationTypeAddManager.
- Only the channel owner can add admins.
- Members must be in the group. The owner cannot be set as admin.
- Maximum 10 admins per group.
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else {
return
}
channel.addManagers(userIds: ["user1", "user2"]) { error in
if error == nil {
// Added
}
}
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel addManagersWithUserIds:@[@"user1", @"user2"]
completion:^(NCError *error) {
if (error == nil) {
// Added
}
}];
Remove admins
Call removeManagersWithUserIds:completion: (max 10 per call). All members receive onGroupOperation with type NCGroupOperationTypeRemoveManager.
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else {
return
}
channel.removeManagers(userIds: ["user1"]) { error in
if error == nil {
// Removed
}
}
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel removeManagersWithUserIds:@[@"user1"]
completion:^(NCError *error) {
if (error == nil) {
// Removed
}
}];
Follow channel members
Followed members bypass the channel's do not disturb setting — their messages always trigger notifications.
- Max 200 followed members per group.
- Priority: App-level DND > silent message flag > followed member > channel DND setting
Add followed members
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else {
return
}
channel.addFavorites(userIds: ["user1", "user2"]) { error in
if error == nil {
// Added
}
}
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel addFavoritesWithUserIds:@[@"user1", @"user2"]
completion:^(NCError *error) {
if (error == nil) {
// Added
}
}];
Remove followed members
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else {
return
}
channel.removeFavorites(userIds: ["user1"]) { error in
if error == nil {
// Removed
}
}
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel removeFavoritesWithUserIds:@[@"user1"]
completion:^(NCError *error) {
if (error == nil) {
// Removed
}
}];
Get followed members
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = GroupChannel(channelId: "groupId") else {
return
}
channel.getFavorites { favorites, error in
if error == nil {
// Success
print("Followed members: \(favorites?.count ?? 0)")
}
}
NCGroupChannel *channel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[channel getFavoritesWithCompletion:^(NSArray<NCGroupFavoriteInfo *> *favorites, NCError *error) {
if (error == nil) {
// Success
}
}];