Search in sources :

Example 1 with ApiFileUrlDescription

use of im.actor.core.api.ApiFileUrlDescription in project actor-platform by actorapp.

the class FileUrlLoader method checkQueue.

public void checkQueue() {
    if (isExecuting) {
        return;
    }
    if (pendingFiles.size() == 0) {
        return;
    }
    final ArrayList<RequestedFile> destFiles = new ArrayList<>(pendingFiles);
    pendingFiles.clear();
    isExecuting = true;
    ArrayList<ApiFileLocation> locations = new ArrayList<>();
    for (RequestedFile f : destFiles) {
        Log.d("FileUrlLoader", "api: " + f.getFileId());
        locations.add(new ApiFileLocation(f.getFileId(), f.getAccessHash()));
    }
    api(new RequestGetFileUrls(locations)).then(responseGetFileUrls -> {
        outer: for (RequestedFile f : destFiles) {
            for (ApiFileUrlDescription urlDescription : responseGetFileUrls.getFileUrls()) {
                if (f.getFileId() == urlDescription.getFileId()) {
                    Log.d("FileUrlLoader", "resp: " + f.getFileId());
                    // TODO: Implement Timeouts
                    f.getResolver().result(urlDescription.getUrl());
                    continue outer;
                }
            }
        }
        isExecuting = false;
        scheduleCheck();
    }).failure(e -> {
        for (RequestedFile f : destFiles) {
            f.getResolver().error(e);
        }
        isExecuting = false;
        scheduleCheck();
    });
}
Also used : ApiFileUrlDescription(im.actor.core.api.ApiFileUrlDescription) ModuleContext(im.actor.core.modules.ModuleContext) ActorCancellable(im.actor.runtime.actors.ActorCancellable) RequestGetFileUrls(im.actor.core.api.rpc.RequestGetFileUrls) Promise(im.actor.runtime.promise.Promise) AskMessage(im.actor.runtime.actors.ask.AskMessage) HashMap(java.util.HashMap) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ArrayList(java.util.ArrayList) ModuleActor(im.actor.core.modules.ModuleActor) Consumer(im.actor.runtime.function.Consumer) PromiseResolver(im.actor.runtime.promise.PromiseResolver) ApiFileLocation(im.actor.core.api.ApiFileLocation) Log(im.actor.runtime.Log) NotNull(org.jetbrains.annotations.NotNull) ResponseGetFileUrls(im.actor.core.api.rpc.ResponseGetFileUrls) RequestGetFileUrls(im.actor.core.api.rpc.RequestGetFileUrls) ArrayList(java.util.ArrayList) ApiFileLocation(im.actor.core.api.ApiFileLocation) ApiFileUrlDescription(im.actor.core.api.ApiFileUrlDescription)

Aggregations

ApiFileLocation (im.actor.core.api.ApiFileLocation)1 ApiFileUrlDescription (im.actor.core.api.ApiFileUrlDescription)1 RequestGetFileUrls (im.actor.core.api.rpc.RequestGetFileUrls)1 ResponseGetFileUrls (im.actor.core.api.rpc.ResponseGetFileUrls)1 ModuleActor (im.actor.core.modules.ModuleActor)1 ModuleContext (im.actor.core.modules.ModuleContext)1 Log (im.actor.runtime.Log)1 ActorCancellable (im.actor.runtime.actors.ActorCancellable)1 AskMessage (im.actor.runtime.actors.ask.AskMessage)1 Consumer (im.actor.runtime.function.Consumer)1 Promise (im.actor.runtime.promise.Promise)1 PromiseFunc (im.actor.runtime.promise.PromiseFunc)1 PromiseResolver (im.actor.runtime.promise.PromiseResolver)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 NotNull (org.jetbrains.annotations.NotNull)1