Skip to main content

Manage group channels

tip

Groups created outside the managed hosting APIs require importing managed hosting data (setting the channel owner and default permissions) before using managed group features.

Prerequisites

The managed hosting service is enabled by default.

Group event listeners

Register a GroupChannelHandler to receive group application and other events:

Dart
NCEngine.addGroupChannelHandler('group-handler', GroupChannelHandler(
onGroupApplicationEvent: (event) {
print('Group application event: ${event.info}');
},
onGroupInfoChanged: (event) {
print('Group info changed: ${event.fullGroupInfo?.groupName}');
},
onGroupFavoritesChangedSync: (event) {
print('Group favorites changed: ${event.groupId}');
},
));

Remove the handler when it is no longer needed:

Dart
NCEngine.removeGroupChannelHandler('group-handler');

Create a group

Call GroupChannel.createGroup() to create a new group channel.

CreateGroupParams properties

PropertyTypeRequiredDescription
groupIdStringYesGroup ID (max 64 characters, alphanumeric)
groupNameString?NoGroup name (max 64 characters)
avatarUrlString?NoAvatar URL (max 128 characters)
introductionString?NoDescription (max 512 characters)
noticeString?NoAnnouncement (max 1024 characters)
extProfileMap?NoCustom properties (max 10, configure in console first)
joinPermissionGroupJoinPermissionNoJoin permission (default: owner approval required)
removeMemberPermissionGroupOperationPermissionNoRemove permission (default: owner only)
invitePermissionGroupOperationPermissionNoInvite permission (default: owner only)
inviteHandlePermissionGroupInviteHandlePermissionNoInvitee approval (default: not required)
groupInfoEditPermissionGroupOperationPermissionNoEdit permission (default: owner only)
memberInfoEditPermissionGroupMemberInfoEditPermissionNoMember profile edit permission
inviteeUserIdsList<String>YesInitial users to invite into the group
Dart
await GroupChannel.createGroup(
CreateGroupParams(
groupId: 'groupId',
groupName: 'groupName',
inviteeUserIds: ['userId1', 'userId2', 'userId3'],
),
(errorKeys, processCode, error) {
if (error == null) {
print('Group created, processCode: $processCode');
} else {
print('Create failed: ${error.code}, errorKeys: $errorKeys');
}
},
);

GroupChannel.createGroup() uses OperationWithProcessCodeHandler<List<String>>, not ErrorHandler. For this callback type:

  • Success: processCode is available, while errorKeys and error are null
  • Failure: error is not null, and errorKeys may contain the native-layer field keys that failed validation or update

The remaining instance methods on this page use ErrorHandler instead. For those callbacks, success means error?.isSuccess == true (error.code == 0).

If you need the created group's full details after a successful create call, follow up with GroupChannel.getGroupsInfo([groupId], ...).

Update group info

Call group.updateInfo() on the GroupChannel instance. The target group ID comes from the current GroupChannel.channelId, so UpdateGroupInfoParams only contains editable fields.

Dart
final group = GroupChannel('groupId');
await group.updateInfo(
UpdateGroupInfoParams(groupName: 'New Name'),
(errorInfo, error) {
if (error?.isSuccess == true) {
print('Group info updated');
} else {
print('Update failed: $errorInfo');
}
},
);

Remove members

Call group.kickMembers() to remove members (up to 100 per call).

Dart
await group.kickMembers(
KickGroupMembersParams(
userIds: ['userId1', 'userId2'],
config: LeaveGroupConfig(),
),
(error) {
if (error?.isSuccess == true) {
print('Members removed');
}
},
);

Leave a group

Dart
await group.leave(
LeaveGroupConfig(),
(error) {
if (error?.isSuccess == true) {
print('Left group');
}
},
);

Dismiss a group

Call group.dismiss(). Only the channel owner can dismiss.

Dart
await group.dismiss((error) {
if (error?.isSuccess == true) {
print('Group dismissed');
}
});

Transfer ownership

Dart
await group.transferOwner(
TransferGroupOwnerParams(
newOwnerId: 'newOwnerUserId',
config: LeaveGroupConfig(),
),
(error) {
if (error?.isSuccess == true) {
print('Ownership transferred');
}
},
);

Group remark

Dart
await group.setRemark(
'My Group',
(error) {
if (error?.isSuccess == true) {
print('Remark set');
}
},
);