createGroup method

Future<void> createGroup()

Creates a Chat-group with SearchController.selectedRecent, SearchController.selectedContacts and SearchController.selectedUsers.

Implementation

Future<void> createGroup() async {
  creatingStatus.value = RxStatus.loading();

  try {
    final RxChat chat = await _chatService.createGroupChat(
      {
        ...search.value!.selectedRecent.map((e) => e.id),
        ...search.value!.selectedContacts.expand(
          (e) => e.contact.value.users.map((u) => u.id),
        ),
        ...search.value!.selectedUsers.map((e) => e.id),
      }.where((e) => e != me).toList(),
    );

    router.dialog(chat.chat.value, me);

    closeGroupCreating();
  } on CreateGroupChatException catch (e) {
    MessagePopup.error(e);
  } on FormatException catch (e) {
    MessagePopup.error(e);
  } catch (e) {
    MessagePopup.error(e);
    rethrow;
  } finally {
    creatingStatus.value = RxStatus.empty();
  }
}