Search in sources :

Example 1 with ExecuteAfter

use of im.actor.core.modules.sequence.internal.ExecuteAfter in project actor-platform by actorapp.

the class SequenceActor method checkRunnables.

private void checkRunnables() {
    if (pendingRunnables.size() > 0) {
        for (ExecuteAfter e : pendingRunnables.toArray(new ExecuteAfter[pendingRunnables.size()])) {
            if (e.getSeq() <= this.finishedSeq) {
                e.getRunnable().run();
                pendingRunnables.remove(e);
            }
        }
    }
}
Also used : ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter)

Example 2 with ExecuteAfter

use of im.actor.core.modules.sequence.internal.ExecuteAfter 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)

Example 3 with ExecuteAfter

use of im.actor.core.modules.sequence.internal.ExecuteAfter in project actor-platform by actorapp.

the class SequenceActor method onReceive.

//
// Messages
//
@Override
public void onReceive(Object message) {
    if (message instanceof Invalidate || message instanceof SeqUpdateTooLong || message instanceof ForceInvalidate) {
        if (!isValidated) {
            return;
        }
        invalidate();
    } else if (message instanceof SeqUpdate || message instanceof FatSeqUpdate) {
        if (!isValidated) {
            stash();
            return;
        }
        int seq;
        byte[] state;
        int type;
        byte[] body;
        List<ApiUser> users = null;
        List<ApiGroup> groups = null;
        if (message instanceof SeqUpdate) {
            seq = ((SeqUpdate) message).getSeq();
            state = ((SeqUpdate) message).getState();
            type = ((SeqUpdate) message).getUpdateHeader();
            body = ((SeqUpdate) message).getUpdate();
        } else {
            seq = ((FatSeqUpdate) message).getSeq();
            state = ((FatSeqUpdate) message).getState();
            type = ((FatSeqUpdate) message).getUpdateHeader();
            body = ((FatSeqUpdate) message).getUpdate();
            users = ((FatSeqUpdate) message).getUsers();
            groups = ((FatSeqUpdate) message).getGroups();
        }
        onUpdateReceived(seq, state, type, body, users, groups);
    } else if (message instanceof ExecuteAfter) {
        if (!isValidated) {
            stash();
            return;
        }
        onExecuteAfter((ExecuteAfter) message);
    } else if (message instanceof PushSeq) {
        if (!isValidated) {
            stash();
            return;
        }
        onPushSeqReceived(((PushSeq) message).seq, ((PushSeq) message).authId);
    } else if (message instanceof WeakUpdate) {
        WeakUpdate weakUpdate = (WeakUpdate) message;
        onWeakUpdateReceived(weakUpdate.getUpdateHeader(), weakUpdate.getUpdate(), weakUpdate.getDate());
    } else {
        super.onReceive(message);
    }
}
Also used : FatSeqUpdate(im.actor.core.api.base.FatSeqUpdate) FatSeqUpdate(im.actor.core.api.base.FatSeqUpdate) SeqUpdate(im.actor.core.api.base.SeqUpdate) WeakUpdate(im.actor.core.api.base.WeakUpdate) ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter) ArrayList(java.util.ArrayList) List(java.util.List) SeqUpdateTooLong(im.actor.core.api.base.SeqUpdateTooLong)

Aggregations

ExecuteAfter (im.actor.core.modules.sequence.internal.ExecuteAfter)3 SeqUpdate (im.actor.core.api.base.SeqUpdate)2 FatSeqUpdate (im.actor.core.api.base.FatSeqUpdate)1 SeqUpdateTooLong (im.actor.core.api.base.SeqUpdateTooLong)1 WeakUpdate (im.actor.core.api.base.WeakUpdate)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 RpcException (im.actor.core.network.RpcException)1 AvatarUploadState (im.actor.core.viewmodel.AvatarUploadState)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1