Search in sources :

Example 1 with UpdateUserAvatarChanged

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

the class OwnAvatarChangeActor method removeAvatar.

public void removeAvatar() {
    if (currentChangeTask != 0) {
        context().getFilesModule().cancelUpload(currentChangeTask);
        currentChangeTask = 0;
    }
    currentChangeTask = RandomUtils.nextRid();
    context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, true));
    final long currentRid = currentChangeTask;
    request(new RequestRemoveAvatar(), new RpcCallback<ResponseSeq>() {

        @Override
        public void onResult(ResponseSeq response) {
            updates().onUpdateReceived(new SeqUpdate(response.getSeq(), response.getState(), UpdateUserAvatarChanged.HEADER, new UpdateUserAvatarChanged(myUid(), null).toByteArray()));
            // After update applied turn of uploading state
            updates().onUpdateReceived(new ExecuteAfter(response.getSeq(), () -> self().send(new AvatarChanged(currentRid))));
        }

        @Override
        public void onError(RpcException e) {
            if (currentRid != currentChangeTask) {
                return;
            }
            currentChangeTask = 0;
            context().getProfileModule().getOwnAvatarVM().getUploadState().change(new AvatarUploadState(null, false));
        }
    });
}
Also used : SeqUpdate(im.actor.core.api.base.SeqUpdate) ResponseSeq(im.actor.core.api.rpc.ResponseSeq) UpdateUserAvatarChanged(im.actor.core.api.updates.UpdateUserAvatarChanged) RpcException(im.actor.core.network.RpcException) ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter) UpdateUserAvatarChanged(im.actor.core.api.updates.UpdateUserAvatarChanged) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) RequestRemoveAvatar(im.actor.core.api.rpc.RequestRemoveAvatar)

Aggregations

SeqUpdate (im.actor.core.api.base.SeqUpdate)1 RequestRemoveAvatar (im.actor.core.api.rpc.RequestRemoveAvatar)1 ResponseSeq (im.actor.core.api.rpc.ResponseSeq)1 UpdateUserAvatarChanged (im.actor.core.api.updates.UpdateUserAvatarChanged)1 ExecuteAfter (im.actor.core.modules.sequence.internal.ExecuteAfter)1 RpcException (im.actor.core.network.RpcException)1 AvatarUploadState (im.actor.core.viewmodel.AvatarUploadState)1