public Mono<DeleteResult> deleteUsers(
            @NotEmpty Set<Long> userIds,
            @Nullable Boolean deleteLogically) {
        try {
            Validator.notEmpty(userIds, "userIds");
        } catch (ResponseException e) {
            return Mono.error(e);
        }
        Mono<DeleteResult> deleteOrUpdateMono;
        if (deleteLogically == null) {
            deleteLogically = deleteUserLogically;
        }
        if (deleteLogically) {
            deleteOrUpdateMono = userRepository.updateUsersDeletionDate(userIds)
                    .map(OperationResultConvertor::update2delete);
            // For logical deletion, we don't need to update the user doc in Elasticsearch.
        } else {
            Boolean deleteEsDocInTransaction = elasticsearchManager.isUserUseCaseEnabled()
                    ? elasticsearchManager.isTransactionWithMongoEnabledForUser()
                    : null;
            deleteOrUpdateMono = userRepository
                    .inTransaction(session -> userRepository.deleteByIds(userIds, session)
                            .flatMap(result -> {
                                // TODO: Remove data on Redis
                                return (Boolean.TRUE.equals(deleteEsDocInTransaction)
                                        ? elasticsearchManager.deleteUserDocs(userIds)
                                        : Mono.empty())
                                        .then(userRelationshipService
                                                .deleteAllRelationships(userIds, session, false))
                                        .then(userRelationshipGroupService
                                                .deleteAllRelationshipGroups(userIds,
                                                        session,
                                                        false))
                                        .then(userSettingsService.deleteSettings(userIds, session))
                                        .then(conversationService
                                                .deletePrivateConversations(userIds, session))
                                        .then(conversationService
                                                .deleteGroupMemberConversations(userIds, session))
                                        .then(conversationSettingsService.deleteSettings(userIds,
                                                session))
                                        .then(userVersionService.delete(userIds, session)
                                                .onErrorResume(t -> {
                                                    LOGGER.error(
                                                            "Caught an error while deleting the version for the users {} after deleting the users",
                                                            userIds,
                                                            t);
                                                    return Mono.empty();
                                                }))
                                        .then(messageService
                                                .deletePrivateMessageSequenceIds(userIds)
                                                .doOnError(t -> LOGGER.error(
                                                        "Failed to remove the message sequence IDs of the users: "
                                                                + userIds,
                                                        t)))
                                        .thenReturn(result);
                            }))
                    .retryWhen(TRANSACTION_RETRY)
                    .doOnSuccess(result -> {
                        long count = result.getDeletedCount();
                        if (count > 0) {
                            deletedUsersCounter.increment(count);
                        }
                    });
            if (Boolean.FALSE.equals(deleteEsDocInTransaction)) {
                deleteOrUpdateMono = deleteOrUpdateMono.doOnSuccess(result -> elasticsearchManager
                        .deleteUserDocs(userIds)
                        .subscribe(null,
                                t -> LOGGER.error(
                                        "Caught an error while deleting the docs of the users: "
                                                + userIds,
                                        t)));
            }
        }
        return deleteOrUpdateMono.doOnNext(ignored -> sessionService
                .disconnect(userIds, SessionCloseStatus.USER_IS_DELETED_OR_INACTIVATED)
                .subscribe(null,
                        t -> LOGGER.error(
                                "Caught an error while closing the user session of the users: "
                                        + userIds,
                                t)));
    }
@return Possible codes: {@link ResponseStatusCode#OK}
        {@link ResponseStatusCode#NOT_FRIEND_TO_QUERY_USER_PROFILE}
        {@link ResponseStatusCode#BLOCKED_USER_TO_QUERY_USER_PROFILE}
        {@link ResponseStatusCode#SERVER_INTERNAL_ERROR}
        {@link ResponseStatusCode#RESOURCE_NOT_FOUND}
turms-service/src/main/java/im/turms/service/domain/user/service/UserService.java