75 lines
2.6 KiB
Java
75 lines
2.6 KiB
Java
package io.kamax.mxisd.backend.firebase;
|
|
|
|
import io.kamax.matrix.MatrixID;
|
|
import io.kamax.matrix.ThreePidMedium;
|
|
import io.kamax.mxisd.config.MxisdConfig;
|
|
import io.kamax.mxisd.lookup.SingleLookupReply;
|
|
import io.kamax.mxisd.lookup.SingleLookupRequest;
|
|
import io.kamax.mxisd.lookup.ThreePidMapping;
|
|
import io.kamax.mxisd.lookup.provider.IThreePidProvider;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
public class GoogleFirebaseProvider extends GoogleFirebaseBackend implements IThreePidProvider {
|
|
|
|
private final Logger log = LoggerFactory.getLogger(GoogleFirebaseProvider.class);
|
|
private String domain;
|
|
|
|
public GoogleFirebaseProvider(MxisdConfig cfg) {
|
|
// Assuming GoogleFirebaseBackend can be initialized without Firebase specifics.
|
|
super(cfg.getFirebase().isEnabled(), cfg.getFirebase().getCredentials(), cfg.getFirebase().getDatabase(), cfg.getMatrix().getDomain());
|
|
this.domain = cfg.getMatrix().getDomain();
|
|
}
|
|
|
|
private String getMxid(String uid) {
|
|
// Mock UID to MXID conversion
|
|
return MatrixID.asAcceptable(uid, domain).getId();
|
|
}
|
|
|
|
@Override
|
|
public boolean isLocal() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int getPriority() {
|
|
return 25;
|
|
}
|
|
|
|
private Optional<String> findInternal(String medium, String address) {
|
|
CompletableFuture<Optional<String>> future = new CompletableFuture<>();
|
|
|
|
// Directly complete with empty to simulate no user found
|
|
future.complete(Optional.empty());
|
|
|
|
return future.join(); // Using join to avoid handling InterruptedException
|
|
}
|
|
|
|
@Override
|
|
public Optional<SingleLookupReply> find(SingleLookupRequest request) {
|
|
Optional<String> uidOpt = findInternal(request.getType(), request.getThreePid());
|
|
return uidOpt.map(uid -> new SingleLookupReply(request, getMxid(uid)));
|
|
}
|
|
|
|
@Override
|
|
public List<ThreePidMapping> populate(List<ThreePidMapping> mappings) {
|
|
List<ThreePidMapping> results = new ArrayList<>();
|
|
mappings.forEach(o -> {
|
|
Optional<String> uidOpt = findInternal(o.getMedium(), o.getValue());
|
|
uidOpt.ifPresent(uid -> {
|
|
ThreePidMapping result = new ThreePidMapping();
|
|
result.setMedium(o.getMedium());
|
|
result.setValue(o.getValue());
|
|
result.setMxid(getMxid(uid));
|
|
results.add(result);
|
|
});
|
|
});
|
|
return results;
|
|
}
|
|
}
|