Search in sources :

Example 1 with IThreePidProvider

use of io.kamax.mxisd.lookup.provider.IThreePidProvider in project mxisd by kamax-io.

the class RecursivePriorityLookupStrategy method find.

public Optional<SingleLookupReply> find(SingleLookupRequest request, List<IThreePidProvider> providers) {
    for (IThreePidProvider provider : providers) {
        Optional<SingleLookupReply> lookupDataOpt = provider.find(request);
        if (lookupDataOpt.isPresent()) {
            log.info("Found 3PID mapping: {medium: '{}', address: '{}', mxid: '{}'}", request.getType(), request.getThreePid(), lookupDataOpt.get().getMxid().getId());
            return lookupDataOpt;
        }
    }
    if (cfg.getBridge() != null && cfg.getBridge().getEnabled() && (!cfg.getBridge().getRecursiveOnly() || isAllowedForRecursive(request.getRequester()))) {
        log.info("Using bridge failover for lookup");
        Optional<SingleLookupReply> lookupDataOpt = bridge.find(request);
        log.info("Found 3PID mapping: {medium: '{}', address: '{}', mxid: '{}'}", request.getThreePid(), request.getId(), lookupDataOpt.get().getMxid().getId());
        return lookupDataOpt;
    }
    log.info("No 3PID mapping found");
    return Optional.empty();
}
Also used : IThreePidProvider(io.kamax.mxisd.lookup.provider.IThreePidProvider)

Example 2 with IThreePidProvider

use of io.kamax.mxisd.lookup.provider.IThreePidProvider in project mxisd by kamax-io.

the class RecursivePriorityLookupStrategy method listUsableProviders.

private List<IThreePidProvider> listUsableProviders(ALookupRequest request, boolean forceRecursive) {
    List<IThreePidProvider> usableProviders = new ArrayList<>();
    boolean canRecurse = forceRecursive || isAllowedForRecursive(request.getRequester());
    log.info("Host {} allowed for recursion: {}", request.getRequester(), canRecurse);
    for (IThreePidProvider provider : providers) {
        if (provider.isLocal() || canRecurse || forceRecursive) {
            usableProviders.add(provider);
        }
    }
    return usableProviders;
}
Also used : ArrayList(java.util.ArrayList) IThreePidProvider(io.kamax.mxisd.lookup.provider.IThreePidProvider)

Example 3 with IThreePidProvider

use of io.kamax.mxisd.lookup.provider.IThreePidProvider in project mxisd by kamax-io.

the class RecursivePriorityLookupStrategy method find.

@Override
public List<ThreePidMapping> find(BulkLookupRequest request) {
    List<ThreePidMapping> mapToDo = new ArrayList<>(request.getMappings());
    List<ThreePidMapping> mapFoundAll = new ArrayList<>();
    for (IThreePidProvider provider : listUsableProviders(request)) {
        if (mapToDo.isEmpty()) {
            log.info("No more mappings to lookup");
            break;
        } else {
            log.info("{} mappings remaining overall", mapToDo.size());
        }
        log.info("Using provider {} for remaining mappings", provider.getClass().getSimpleName());
        List<ThreePidMapping> mapFound = provider.populate(mapToDo);
        log.info("Provider {} returned {} mappings", provider.getClass().getSimpleName(), mapFound.size());
        mapFoundAll.addAll(mapFound);
        mapToDo.removeAll(mapFound);
    }
    return mapFoundAll;
}
Also used : ArrayList(java.util.ArrayList) IThreePidProvider(io.kamax.mxisd.lookup.provider.IThreePidProvider)

Aggregations

IThreePidProvider (io.kamax.mxisd.lookup.provider.IThreePidProvider)3 ArrayList (java.util.ArrayList)2