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(
onApplicationEvent: (info) {
print('Group application event: $info');
},
onRemarkChanged: (groupId, operationType, remark, operationTime) {
print('Group remark changed: $groupId, $remark');
},
onFavoritesChanged: (groupId, operationType, userIds, operationTime) {
print('Group favorites changed: $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.

GroupInfo properties

PropertyTypeRequiredDescription
groupIdStringYesGroup ID (max 64 characters, alphanumeric)
groupNameStringYesGroup name (max 64 characters)
portraitUriString?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)
Dart
await GroupChannel.createGroup(
CreateGroupParams(
info: GroupInfo(groupId: 'groupId', groupName: 'groupName'),
inviteeUserIds: ['userId1', 'userId2', 'userId3'],
),
(createdGroup, error) {
if (error == null) {
print('Group created');
}
},
);

Update group info

Call group.updateInfo() on the GroupChannel instance. Only groupId is required; the API updates only changed fields.

Dart
final group = GroupChannel('groupId');
await group.updateInfo(
GroupInfo(groupId: 'groupId', groupName: 'New Name'),
(error) {
if (error == null) {
print('Group info updated');
}
},
);

Remove members

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

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

Leave a group

Dart
await group.leaveGroup(
LeaveGroupConfig(),
(error) {
if (error == null) {
print('Left group');
}
},
);

Dismiss a group

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

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

Transfer ownership

Dart
await group.transferOwner(
TransferOwnerParams(newOwnerId: 'newOwnerUserId', config: LeaveGroupConfig()),
(error) {
if (error == null) {
print('Ownership transferred');
}
},
);

Group remark

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