public Mono<List<GroupMember>> authAndAddGroupMembers(
            @NotNull Long requesterId,
            @NotNull Long groupId,
            @NotNull Set<Long> userIds,
            @Nullable @ValidGroupMemberRole GroupMemberRole groupMemberRole,
            @Nullable String name,
            @Nullable Date muteEndDate,
            @Nullable ClientSession session) {
        boolean onlyAddRequesterToGroup = userIds.contains(requesterId);
        try {
            Validator.notNull(userIds, "userIds");
            // TODO: configurable
            Validator.maxSize(userIds, "userIds", 100);
            if (onlyAddRequesterToGroup) {
                if (userIds.size() > 1) {
                    return Mono.error(ResponseException.get(ResponseStatusCode.ILLEGAL_ARGUMENT,
                            "Cannot add oneself and other users to a group in one request"));
                }
                if (groupMemberRole == null) {
                    groupMemberRole = GroupMemberRole.MEMBER;
                } else if (groupMemberRole != GroupMemberRole.MEMBER) {
                    return Mono.error(ResponseException.get(ResponseStatusCode.ILLEGAL_ARGUMENT,
                            "The role of the new group member for the requester must be MEMBER"));
                }
            }
            Validator.notNull(groupMemberRole, "groupMemberRole");
            DataValidator.validGroupMemberRole(groupMemberRole);
        } catch (ResponseException e) {
            return Mono.error(e);
        }
        if (groupMemberRole == GroupMemberRole.OWNER) {
            return Mono.error(ResponseException.get(ResponseStatusCode.ILLEGAL_ARGUMENT,
                    "The role of the new member must not be OWNER"));
        }
        if (groupMemberRole == GroupMemberRole.GUEST) {
            return Mono.error(ResponseException.get(ResponseStatusCode.ILLEGAL_ARGUMENT,
                    "The role of the new member must not be GUEST"));
        }
        if (userIds.isEmpty()) {
            return PublisherPool.EMPTY_LIST;
        }
        GroupMemberRole finalGroupMemberRole = groupMemberRole;
        return groupService.queryGroupTypeIfActiveAndNotDeleted(groupId)
                .switchIfEmpty(Mono.error(
                        ResponseException.get(ResponseStatusCode.ADD_USER_TO_INACTIVE_GROUP)))
                .flatMap(groupType -> {
                    Mono<Void> check;
                    if (onlyAddRequesterToGroup) {
                        check = switch (groupType.getJoinStrategy()) {
                            case MEMBERSHIP_REQUEST -> Mono.empty();
                            case INVITATION -> Mono.error(ResponseException.get(
                                    ResponseStatusCode.USER_JOIN_GROUP_WITHOUT_ACCEPTING_GROUP_INVITATION));
                            case QUESTION -> Mono.error(ResponseException.get(
                                    ResponseStatusCode.USER_JOIN_GROUP_WITHOUT_ANSWERING_GROUP_QUESTION));
                            case JOIN_REQUEST -> Mono.error(ResponseException.get(
                                    ResponseStatusCode.USER_JOIN_GROUP_WITHOUT_SENDING_GROUP_JOIN_REQUEST));
                        };
                    } else {
                        GroupInvitationStrategy invitationStrategy =
                                groupType.getInvitationStrategy();
                        if (invitationStrategy.requiresApproval()) {
                            return Mono.error(ResponseException.get(
                                    ResponseStatusCode.ADD_USER_TO_GROUP_REQUIRING_USERS_APPROVAL));
                        }
                        check = queryGroupMemberRole(requesterId, groupId, false)
                                .defaultIfEmpty(GroupMemberRole.UNRECOGNIZED)
                                .flatMap(requesterRole -> {
                                    if (finalGroupMemberRole == GroupMemberRole.MANAGER
                                            && requesterRole != GroupMemberRole.OWNER) {
                                        return Mono.error(ResponseException.get(
                                                ResponseStatusCode.NOT_GROUP_OWNER_TO_ADD_GROUP_MANAGER));
                                    }
                                    return switch (invitationStrategy) {
                                        case ALL, ALL_REQUIRING_APPROVAL -> Mono.empty();
                                        case OWNER_MANAGER_MEMBER,
                                                OWNER_MANAGER_MEMBER_REQUIRING_APPROVAL ->
                                            requesterRole == GroupMemberRole.OWNER
                                                    || requesterRole == GroupMemberRole.MANAGER
                                                    || requesterRole == GroupMemberRole.MEMBER
                                                            ? Mono.empty()
                                                            : Mono.error(ResponseException.get(
                                                                    ResponseStatusCode.NOT_GROUP_MEMBER_TO_ADD_GROUP_MEMBER));
                                        case OWNER_MANAGER, OWNER_MANAGER_REQUIRING_APPROVAL ->
                                            requesterRole == GroupMemberRole.OWNER
                                                    || requesterRole == GroupMemberRole.MANAGER
                                                            ? Mono.empty()
                                                            : Mono.error(ResponseException.get(
                                                                    ResponseStatusCode.NOT_GROUP_OWNER_OR_MANAGER_TO_ADD_GROUP_MEMBER));
                                        case OWNER, OWNER_REQUIRING_APPROVAL ->
                                            requesterRole == GroupMemberRole.OWNER
                                                    ? Mono.empty()
                                                    : Mono.error(ResponseException.get(
                                                            ResponseStatusCode.NOT_GROUP_OWNER_TO_ADD_GROUP_MEMBER));
                                    };
                                });
                    }
                    return check
                            .then(Mono.defer(
                                    () -> groupBlocklistService.findBlockedUserIds(groupId, userIds)
                                            .collect(CollectorUtil.toList(userIds.size()))))
                            .flatMap(blockedUserIds -> {
                                if (!blockedUserIds.isEmpty()) {
                                    blockedUserIds = CollectionUtil.sort(blockedUserIds);
                                    String ids = StringUtil.joinLatin1(", ", blockedUserIds);
                                    return Mono.error(ResponseException.get(
                                            ResponseStatusCode.ADD_BLOCKED_USER_TO_GROUP,
                                            "The blocked user IDs: "
                                                    + ids));
                                }
                                // Put the logic to check the member limit last
                                // to reduce the gap between checking count and adding members
                                return groupMemberRepository.countMembers(groupId)
                                        .flatMap(memberCount -> {
                                            if (memberCount + userIds.size() > groupType
                                                    .getGroupSizeLimit()) {
                                                return Mono.error(ResponseException.get(
                                                        ResponseStatusCode.ADD_USER_TO_GROUP_WITH_SIZE_LIMIT_REACHED));
                                            }
                                            return addGroupMembers(groupId,
                                                    userIds,
                                                    finalGroupMemberRole,
                                                    name,
                                                    new Date(),
                                                    muteEndDate,
                                                    session);
                                        });
                            });
                });
    }
If the users for group members are already group members, the method will return an error
turms-service/src/main/java/im/turms/service/domain/group/service/GroupMemberService.java