createGroup method

Future<ChatGroup> createGroup({
  1. String? groupName,
  2. String? desc,
  3. List<String>? inviteMembers,
  4. String? inviteReason,
  5. required ChatGroupOptions options,
})

~english Creates a group instance.

After the group is created, the data in the cache and database will be updated and multiple devices will receive the notification event and update the group data to the cache and database. You can set ChatMultiDeviceEventHandler to listen for the event. If an event occurs, the callback function ChatMultiDeviceEventHandler.onGroupEvent is triggered, where the first parameter is the event which is ChatMultiDevicesEvent.GROUP_CREATE for a group creation event.

Param groupName The group name.

Param desc The group description.

Param inviteMembers The group member array. The group owner ID is optional.

Param inviteReason The group joining invitation.

Param options The options for creating a group. See ChatGroupOptions. The options are as follows:

  • The maximum number of group members. The default value is 200.
  • The group style. See ChatGroupStyle. The default value is ChatGroupStyle.PrivateOnlyOwnerInvite.
  • Whether to ask for permission when inviting a user to join the group. The default value is false, indicating that invitees are automatically added to the group without their permission.
  • The group detail extensions.

Return The created group instance.

Throws A description of the exception. See ChatError. ~end

~chinese 创建群组。

群组创建成功后,会更新内存及数据库中的数据,多端多设备会收到相应的通知事件,将群组更新到内存及数据库中。 可通过设置 ChatClient.addMultiDeviceEventHandler 监听相关事件,事件回调函数为 ChatMultiDeviceEventHandler.onGroupEvent,第一个参数为事件,创建群组事件为 ChatMultiDevicesEvent.GROUP_CREATE

Param groupName 群组名称。

Param desc 群组描述。

Param inviteMembers 群成员数组。群主 ID 可选。

Param inviteReason 用户入群邀请信息。

Param options 群组的其他选项。请参见 ChatGroupOptions。 群组的其他选项。

Return 创建成功的群对象。

Throws 如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError。 ~end

Implementation

Future<ChatGroup> createGroup({
  String? groupName,
  String? desc,
  List<String>? inviteMembers,
  String? inviteReason,
  required ChatGroupOptions options,
}) async {
  Map req = {'options': options.toJson()};
  req.putIfNotNull("groupName", groupName);
  req.putIfNotNull("desc", desc);
  req.putIfNotNull("inviteMembers", inviteMembers);
  req.putIfNotNull("inviteReason", inviteReason);

  Map result = await _channel.invokeMethod(ChatMethodKeys.createGroup, req);
  try {
    ChatError.hasErrorFromResult(result);
    return ChatGroup.fromJson(result[ChatMethodKeys.createGroup]);
  } on ChatError catch (e) {
    throw e;
  }
}