Search in sources :

Example 1 with AvatarUploadState

use of im.actor.core.viewmodel.AvatarUploadState in project actor-platform by actorapp.

the class GroupAvatarChangeActor method avatarChanged.

public void avatarChanged(int gid, long rid) {
    if (!currentTasks.containsKey(gid)) {
        return;
    }
    if (currentTasks.get(gid) != rid) {
        return;
    }
    currentTasks.remove(gid);
    context().getGroupsModule().getAvatarVM(gid).getUploadState().change(new AvatarUploadState(null, false));
}
Also used : AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState)

Example 2 with AvatarUploadState

use of im.actor.core.viewmodel.AvatarUploadState in project actor-platform by actorapp.

the class GroupAvatarChangeActor method uploadError.

public void uploadError(long rid) {
    if (!tasksMap.containsKey(rid)) {
        return;
    }
    final int gid = tasksMap.get(rid);
    if (currentTasks.get(gid) != rid) {
        return;
    }
    currentTasks.remove(gid);
    tasksMap.remove(rid);
    context().getGroupsModule().getAvatarVM(gid).getUploadState().change(new AvatarUploadState(null, false));
}
Also used : AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState)

Example 3 with AvatarUploadState

use of im.actor.core.viewmodel.AvatarUploadState in project actor-platform by actorapp.

the class GroupAvatarChangeActor method changeAvatar.

public void changeAvatar(int gid, String descriptor) {
    if (currentTasks.containsKey(gid)) {
        context().getFilesModule().cancelUpload(currentTasks.get(gid));
        currentTasks.remove(gid);
    }
    long rid = RandomUtils.nextRid();
    currentTasks.put(gid, rid);
    tasksMap.put(rid, gid);
    context().getGroupsModule().getAvatarVM(gid).getUploadState().change(new AvatarUploadState(descriptor, true));
    context().getFilesModule().requestUpload(rid, descriptor, "avatar.jpg", self());
}
Also used : AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState)

Example 4 with AvatarUploadState

use of im.actor.core.viewmodel.AvatarUploadState in project actor-platform by actorapp.

the class GroupAvatarChangeActor method removeAvatar.

public void removeAvatar(final int gid) {
    if (currentTasks.containsKey(gid)) {
        context().getFilesModule().cancelUpload(currentTasks.get(gid));
        currentTasks.remove(gid);
    }
    final long rid = RandomUtils.nextRid();
    currentTasks.put(gid, rid);
    tasksMap.put(rid, gid);
    Group group = context().getGroupsModule().getGroups().getValue(gid);
    ApiGroupOutPeer outPeer = new ApiGroupOutPeer(gid, group.getAccessHash());
    context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, true));
    api(new RequestRemoveGroupAvatar(outPeer, rid, ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseSeqDate -> updates().applyUpdate(responseSeqDate.getSeq(), responseSeqDate.getState(), new UpdateGroupAvatarChangedObsolete(gid, rid, myUid(), null, responseSeqDate.getDate()))).then(aVoid -> avatarChanged(gid, rid)).failure(e -> {
        if (!tasksMap.containsKey(rid)) {
            return;
        }
        final int gid2 = tasksMap.get(rid);
        if (currentTasks.get(gid) != 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) Group(im.actor.core.entity.Group) UpdateGroupAvatarChangedObsolete(im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete) RequestRemoveGroupAvatar(im.actor.core.api.rpc.RequestRemoveGroupAvatar) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer)

Example 5 with AvatarUploadState

use of im.actor.core.viewmodel.AvatarUploadState in project actor-platform by actorapp.

the class OwnAvatarChangeActor method uploadError.

public void uploadError(long rid) {
    if (rid != currentChangeTask) {
        return;
    }
    currentChangeTask = 0;
    context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, false));
}
Also used : AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState)

Aggregations

AvatarUploadState (im.actor.core.viewmodel.AvatarUploadState)9 SeqUpdate (im.actor.core.api.base.SeqUpdate)3 ExecuteAfter (im.actor.core.modules.sequence.internal.ExecuteAfter)3 RpcException (im.actor.core.network.RpcException)3 ApiFileLocation (im.actor.core.api.ApiFileLocation)2 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)2 RequestEditGroupAvatar (im.actor.core.api.rpc.RequestEditGroupAvatar)2 RequestRemoveGroupAvatar (im.actor.core.api.rpc.RequestRemoveGroupAvatar)2 ResponseEditGroupAvatar (im.actor.core.api.rpc.ResponseEditGroupAvatar)2 ResponseSeqDate (im.actor.core.api.rpc.ResponseSeqDate)2 UpdateGroupAvatarChanged (im.actor.core.api.updates.UpdateGroupAvatarChanged)2 UpdateGroupAvatarChangedObsolete (im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete)2 FileReference (im.actor.core.entity.FileReference)2 Group (im.actor.core.entity.Group)2 ModuleActor (im.actor.core.modules.ModuleActor)2 ModuleContext (im.actor.core.modules.ModuleContext)2 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)2 UploadManager (im.actor.core.modules.file.UploadManager)2 RpcCallback (im.actor.core.network.RpcCallback)2 RandomUtils (im.actor.core.util.RandomUtils)2