createGroupChat method

Future<String> createGroupChat({
  1. String? groupName,
  2. bool? enableEncryption,
  3. List<String>? invite,
  4. CreateRoomPreset preset = CreateRoomPreset.privateChat,
  5. List<StateEvent>? initialState,
  6. Visibility? visibility,
  7. bool waitForSync = true,
  8. bool groupCall = false,
  9. Map<String, dynamic>? powerLevelContentOverride,
})

Simplified method to create a new group chat. By default it is a private chat. The encryption is enabled if this client supports encryption and the preset is not a public chat.

Implementation

Future<String> createGroupChat({
  String? groupName,
  bool? enableEncryption,
  List<String>? invite,
  CreateRoomPreset preset = CreateRoomPreset.privateChat,
  List<StateEvent>? initialState,
  Visibility? visibility,
  bool waitForSync = true,
  bool groupCall = false,
  Map<String, dynamic>? powerLevelContentOverride,
}) async {
  enableEncryption ??=
      encryptionEnabled && preset != CreateRoomPreset.publicChat;
  if (enableEncryption) {
    initialState ??= [];
    if (!initialState.any((s) => s.type == EventTypes.Encryption)) {
      initialState.add(StateEvent(
        content: {
          'algorithm': supportedGroupEncryptionAlgorithms.first,
        },
        type: EventTypes.Encryption,
      ));
    }
  }
  if (groupCall) {
    powerLevelContentOverride ??= {};
    powerLevelContentOverride['events'] = <String, dynamic>{
      EventTypes.GroupCallMemberPrefix: 0,
      EventTypes.GroupCallPrefix: 0,
    };
  }
  final roomId = await createRoom(
      invite: invite,
      preset: preset,
      name: groupName,
      initialState: initialState,
      visibility: visibility,
      powerLevelContentOverride: powerLevelContentOverride);

  if (waitForSync) {
    if (getRoomById(roomId) == null) {
      // Wait for room actually appears in sync
      await waitForRoomInSync(roomId, join: true);
    }
  }
  return roomId;
}