addMembers method

Future<void> addMembers(
  1. List<UserId> ids
)

Adds the Users identified by the provided UserIds to this chat.

If this chat is a dialog, then transforms the _call into a Chat-group call.

Implementation

Future<void> addMembers(List<UserId> ids) async {
  status.value = RxStatus.loading();

  try {
    if (chat.value?.chat.value.isGroup ?? true) {
      final Iterable<Future> futures = ids.map(
        (id) => _chatService
            .addChatMember(chatId.value, id)
            .onError<AddChatMemberException>((e, _) async {
              final FutureOr<RxUser?> userOrFuture = _userService.get(id);
              final User? user =
                  (userOrFuture is RxUser?
                          ? userOrFuture
                          : await userOrFuture)
                      ?.user
                      .value;

              if (user != null) {
                await MessagePopup.error(
                  'err_blocked_by'.l10nfmt({
                    'user': '${user.name ?? user.num}',
                  }),
                );
              }
            }, test: (e) => e.code == AddChatMemberErrorCode.blocked),
      );

      await Future.wait(futures);
    } else {
      await _callService.transformDialogCallIntoGroupCall(chatId.value, ids);
    }

    stage.value = ParticipantsFlowStage.participants;
  } on AddChatMemberException catch (e) {
    MessagePopup.error(e);
  } on TransformDialogCallIntoGroupCallException catch (e) {
    MessagePopup.error(e);
  } catch (e) {
    MessagePopup.error(e);
    rethrow;
  } finally {
    status.value = RxStatus.empty();
  }
}