Search in sources :

Example 1 with ApiFileLocation

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

the class FileReference method parse.

@Override
public void parse(BserValues values) throws IOException {
    // Is Old layout
    if (!values.getBool(5, false)) {
        long fileId = values.getLong(1);
        long accessHash = values.getLong(2);
        setWrapped(new ApiFileLocation(fileId, accessHash));
    }
    // Deserialize new layout
    super.parse(values);
    fileSize = values.getInt(3);
    fileName = values.getString(4);
}
Also used : ApiFileLocation(im.actor.core.api.ApiFileLocation)

Example 2 with ApiFileLocation

use of im.actor.core.api.ApiFileLocation 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)

Example 3 with ApiFileLocation

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

the class GroupAvatarChangeActor method uploadCompleted.

public void uploadCompleted(final long rid, FileReference fileReference) {
    if (!tasksMap.containsKey(rid)) {
        return;
    }
    final int gid = tasksMap.get(rid);
    long accessHash = getGroup(gid).getAccessHash();
    if (currentTasks.get(gid) != rid) {
        return;
    }
    api(new RequestEditGroupAvatar(new ApiGroupOutPeer(gid, accessHash), rid, new ApiFileLocation(fileReference.getFileId(), fileReference.getAccessHash()), ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseEditGroupAvatar -> updates().applyUpdate(responseEditGroupAvatar.getSeq(), responseEditGroupAvatar.getState(), new UpdateGroupAvatarChanged(gid, responseEditGroupAvatar.getAvatar()))).then(v -> avatarChanged(gid, rid)).failure(e -> {
        if (!tasksMap.containsKey(rid)) {
            return;
        }
        final int gid2 = tasksMap.get(rid);
        if (currentTasks.get(gid2) != rid) {
            return;
        }
        currentTasks.remove(gid2);
        tasksMap.remove(rid);
        context().getGroupsModule().getAvatarVM(gid2).getUploadState().change(new AvatarUploadState(null, false));
    });
}
Also used : ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ResponseEditGroupAvatar(im.actor.core.api.rpc.ResponseEditGroupAvatar) ModuleContext(im.actor.core.modules.ModuleContext) ResponseSeqDate(im.actor.core.api.rpc.ResponseSeqDate) ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter) Void(im.actor.runtime.actors.messages.Void) RequestEditGroupAvatar(im.actor.core.api.rpc.RequestEditGroupAvatar) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) RandomUtils(im.actor.core.util.RandomUtils) HashMap(java.util.HashMap) Group(im.actor.core.entity.Group) RpcException(im.actor.core.network.RpcException) RequestRemoveGroupAvatar(im.actor.core.api.rpc.RequestRemoveGroupAvatar) ModuleActor(im.actor.core.modules.ModuleActor) Consumer(im.actor.runtime.function.Consumer) FileReference(im.actor.core.entity.FileReference) ApiFileLocation(im.actor.core.api.ApiFileLocation) UpdateGroupAvatarChangedObsolete(im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete) RpcCallback(im.actor.core.network.RpcCallback) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) UploadManager(im.actor.core.modules.file.UploadManager) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) SeqUpdate(im.actor.core.api.base.SeqUpdate) RequestEditGroupAvatar(im.actor.core.api.rpc.RequestEditGroupAvatar) ApiFileLocation(im.actor.core.api.ApiFileLocation) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer)

Aggregations

ApiFileLocation (im.actor.core.api.ApiFileLocation)3 ModuleActor (im.actor.core.modules.ModuleActor)2 ModuleContext (im.actor.core.modules.ModuleContext)2 Consumer (im.actor.runtime.function.Consumer)2 HashMap (java.util.HashMap)2 ApiFileUrlDescription (im.actor.core.api.ApiFileUrlDescription)1 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)1 SeqUpdate (im.actor.core.api.base.SeqUpdate)1 RequestEditGroupAvatar (im.actor.core.api.rpc.RequestEditGroupAvatar)1 RequestGetFileUrls (im.actor.core.api.rpc.RequestGetFileUrls)1 RequestRemoveGroupAvatar (im.actor.core.api.rpc.RequestRemoveGroupAvatar)1 ResponseEditGroupAvatar (im.actor.core.api.rpc.ResponseEditGroupAvatar)1 ResponseGetFileUrls (im.actor.core.api.rpc.ResponseGetFileUrls)1 ResponseSeqDate (im.actor.core.api.rpc.ResponseSeqDate)1 UpdateGroupAvatarChanged (im.actor.core.api.updates.UpdateGroupAvatarChanged)1 UpdateGroupAvatarChangedObsolete (im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete)1 FileReference (im.actor.core.entity.FileReference)1 Group (im.actor.core.entity.Group)1 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)1 UploadManager (im.actor.core.modules.file.UploadManager)1