Skip to main content

Manage group channels

This guide covers how to create groups, update group info, kick members, leave a group, dismiss a group, and transfer ownership using the Chat SDK.

Group events

Group events are delivered through GroupChannelHandler and cover operations, group info changes, member info changes, membership requests, and favorites sync.

tip

In managed group services, SDK notifications from group operations are counted in message distribution statistics, regardless of whether your app implements event listeners.

swift
import NexconnChatSDK

final class GroupEventService: NSObject, GroupChannelHandler {
func start() {
NCEngine.addGroupChannelHandler(identifier: "GROUP_HANDLER", handler: self)
}

func onGroupOperation(_ event: GroupOperationEvent) {
print("Group operation: \(event.groupId), \(event.operation.rawValue)")
}

func onGroupInfoChanged(_ event: GroupInfoChangedEvent) {
print("Group info changed: \(event.groupInfo.groupId), fields: \(event.changedProperties)")
}

func onGroupMemberInfoChanged(_ event: GroupMemberInfoChangedEvent) {
print("Group member updated: \(event.memberInfo.userId)")
}

func onGroupApplicationEvent(_ event: GroupApplicationEvent) {
print("Group application event: \(event.info.groupId)")
}

func onGroupFavoritesChangedSync(_ event: GroupFavoritesChangedSyncEvent) {
print("Group favorites changed: \(event.groupId), users: \(event.userIds)")
}
}

Group management

Create a group

Call GroupChannel.createGroup(params:completion:) to create a new group:

swift
import NexconnChatSDK

let params = CreateGroupParams(groupId: "groupId", groupName: "groupName")
params.inviteeUserIds = ["user1", "user2"]
params.portraitUri = "https://example.com/avatar.jpg"

GroupChannel.createGroup(params: params) { processCode, errorKeys, error in
if let error {
print("Failed to create group: \(error.localizedDescription), fields: \(errorKeys ?? [])")
return
}

print("Group created. processCode = \(processCode)")
}

CreateGroupParams properties:

PropertyTypeRequiredDescription
groupIdNSStringYesGroup ID. Provided in the initializer.
groupNameNSStringYesGroup name. Provided in the initializer.
inviteeUserIdsNSArrayNoInitial member IDs. Max 30 per request.
portraitUriNSStringNoAvatar URL.
introductionNSStringNoGroup description.
noticeNSStringNoGroup announcement.
extProfileNSDictionaryNoCustom properties configured in the Console first.
joinPermissionNCGroupJoinPermissionNoJoin permission. Default is owner verification.
removeMemberPermissionNCGroupOperationPermissionNoKick permission. Default is owner only.
invitePermissionNCGroupOperationPermissionNoInvite permission. Default is owner only.
inviteHandlePermissionNCGroupInviteHandlePermissionNoInvitee approval. Default is no approval required.
groupInfoEditPermissionNCGroupOperationPermissionNoInfo edit permission. Default is owner only.
memberInfoEditPermissionNCGroupMemberInfoEditPermissionNoMember info edit permission.
tip
  • The group creation result is not affected by processCode. A callback without error means the group was created.
  • The channel owner receives onGroupOperation(_:) with type create.

Update group info

Call updateInfo(params:completion:) on a GroupChannel instance to modify group properties. Only non-nil fields are updated.

swift
import NexconnChatSDK

guard let channel = GroupChannel(channelId: "groupId") else {
return
}

let params = UpdateGroupInfoParams()
params.groupName = "New Group Name"
params.notice = "New announcement"
params.setJoinPermission(.free)

channel.updateInfo(params: params) { errorKeys, error in
if error == nil {
print("Group info updated.")
} else {
print("Failed fields: \(errorKeys ?? [])")
}
}

Kick members

Call kickMembers(params:completion:) to remove members. All members receive onGroupOperation(_:) with type kick.

swift
import NexconnChatSDK

guard let channel = GroupChannel(channelId: "groupId") else {
return
}

let params = KickGroupMembersParams()
params.userIds = ["user1", "user2"]

let config = LeaveGroupConfig()
config.deleteMuteStatus = true
params.config = config

channel.kickMembers(params: params) { error in
if error == nil {
print("Members kicked.")
}
}

Leave a group

Call leave(config:completion:) to leave a group. All members receive onGroupOperation(_:) with type quit.

swift
import NexconnChatSDK

guard let channel = GroupChannel(channelId: "groupId") else {
return
}

channel.leave(config: nil) { error in
if error == nil {
print("Left the group.")
}
}

Dismiss a group

Call dismiss(completion:) to dismiss a group. Messages remain locally. All members receive onGroupOperation(_:) with type dismiss.

tip

Only the channel owner can dismiss a group.

swift
import NexconnChatSDK

guard let channel = GroupChannel(channelId: "groupId") else {
return
}

channel.dismiss { error in
if error == nil {
print("Group dismissed.")
}
}

Transfer ownership

Call transferOwner(params:completion:) to transfer ownership. All members receive onGroupOperation(_:) with type transfer.

tip

Only the channel owner can transfer ownership.

swift
import NexconnChatSDK

guard let channel = GroupChannel(channelId: "groupId") else {
return
}

let params = TransferGroupOwnerParams()
params.newOwnerId = "newOwnerId"
params.leaveAfterTransfer = true

channel.transferOwner(params: params) { error in
if error == nil {
print("Ownership transferred.")
}
}

Group nickname

Group nicknames are user-specific. When a new message arrives and the user is offline, the push notification title shows the group nickname if set, otherwise the group name.

Set a group nickname

Use setMemberInfo(params:completion:) on a group channel instance. Pass nil or "" as nickname to remove the nickname.

swift
import NexconnChatSDK

guard let channel = GroupChannel(channelId: "groupId") else {
return
}

let params = SetGroupMemberInfoParams()
params.userId = NCEngine.getCurrentUserId() ?? ""
params.nickname = "My Team"

channel.setMemberInfo(params: params) { errorKeys, error in
if error == nil {
print("Nickname set.")
} else {
print("Failed fields: \(errorKeys ?? [])")
}
}

Get group info (including nickname)

swift
import NexconnChatSDK

GroupChannel.getGroupsInfo(groupIds: ["groupId"]) { groupInfos, error in
guard let remark = groupInfos?.first?.remark, error == nil else {
return
}

print("Group nickname: \(remark)")
}