public Mono<Boolean> deleteOneSidedRelationship(
            @NotNull Long ownerId,
            @NotNull Long relatedUserId,
            @Nullable Integer groupIndex,
            @Nullable ClientSession session) {
        try {
            Validator.notNull(ownerId, "ownerId");
            Validator.notNull(relatedUserId, "relatedUserId");
        } catch (ResponseException e) {
            return Mono.error(e);
        }
        if (session == null) {
            return userRelationshipRepository
                    .inTransaction(newSession -> deleteOneSidedRelationship(ownerId,
                            relatedUserId,
                            groupIndex,
                            newSession))
                    .retryWhen(TRANSACTION_RETRY);
        }
        UserRelationship.Key key = new UserRelationship.Key(ownerId, relatedUserId);
        if (groupIndex == null) {
            return userRelationshipGroupService
                    .deleteRelatedUserFromAllRelationshipGroups(ownerId,
                            relatedUserId,
                            session,
                            false)
                    .flatMap(deleteResult -> {
                        // because every relationship should exist in a relationship group at least,
                        // return immediately if no relationship found in any group.
                        if (deleteResult.getDeletedCount() == 0) {
                            return PublisherPool.FALSE;
                        }
                        return userRelationshipRepository.deleteById(key, session)
                                .then(userVersionService
                                        .updateSpecificVersion(ownerId,
                                                null,
                                                UserVersion.Fields.RELATIONSHIP_GROUP_MEMBERS,
                                                UserVersion.Fields.RELATIONSHIPS)
                                        .onErrorResume(t -> {
                                            LOGGER.error(
                                                    "Caught an error while updating the relationships version and relationship groups members version of "
                                                            + "the owner ({}) after deleting the relationship with the user ({})",
                                                    ownerId,
                                                    relatedUserId,
                                                    t);
                                            return Mono.empty();
                                        }))
                                .then(Mono.fromCallable(() -> {
                                    invalidateRelationshipCache(ownerId, relatedUserId);
                                    return true;
                                }));
                    });
        }
        return userRelationshipGroupService
                .deleteRelatedUserFromRelationshipGroup(ownerId,
                        relatedUserId,
                        groupIndex,
                        session,
                        false)
                .flatMap(deleteResult -> {
                    if (deleteResult.getDeletedCount() == 0) {
                        return PublisherPool.FALSE;
                    }
                    return userRelationshipGroupService
                            .countRelationshipGroups(Set.of(ownerId), Set.of(relatedUserId))
                            .flatMap(relationshipGroupCount -> {
                                if (relationshipGroupCount > 0) {
                                    return userVersionService
                                            .updateSpecificVersion(ownerId,
                                                    null,
                                                    UserVersion.Fields.RELATIONSHIP_GROUP_MEMBERS)
                                            .onErrorResume(t -> {
                                                LOGGER.error(
                                                        "Caught an error while updating the relationship groups members version of "
                                                                + "the owner ({}) after deleting the relationship with the user ({}) from the group ({})",
                                                        ownerId,
                                                        relatedUserId,
                                                        groupIndex,
                                                        t);
                                                return Mono.empty();
                                            })
                                            .thenReturn(false);
                                }
                                return userRelationshipRepository.deleteById(key, session)
                                        .then(Mono.defer(() -> {
                                            invalidateRelationshipCache(ownerId, relatedUserId);
                                            return userVersionService.updateSpecificVersion(ownerId,
                                                    null,
                                                    UserVersion.Fields.RELATIONSHIP_GROUP_MEMBERS,
                                                    UserVersion.Fields.RELATIONSHIPS)
                                                    .onErrorResume(t -> {
                                                        LOGGER.error(
                                                                "Caught an error while updating the relationships version and relationship group members version of "
                                                                        + "the owner ({}) after deleting the relationship with the user ({}) from the group ({})",
                                                                ownerId,
                                                                relatedUserId,
                                                                groupIndex,
                                                                t);
                                                        return Mono.empty();
                                                    });
                                        }))
                                        .thenReturn(true);
                            });
                });
    }
@return true if the relationship existed and has been deleted;
        <p>
        false if the relationship does not exist, or still exists and has been deleted from a
        relationship group.
turms-service/src/main/java/im/turms/service/domain/user/service/UserRelationshipService.java