Search in sources :

Example 6 with RpcException

use of im.actor.core.network.RpcException in project actor-platform by actorapp.

the class CursorReceiverActor method perform.

@Override
protected void perform(final Peer peer, final long date) {
    ApiOutPeer outPeer = buidOutPeer(peer);
    if (outPeer == null) {
        return;
    }
    request(new RequestMessageReceived(outPeer, date), new RpcCallback<ResponseVoid>() {

        @Override
        public void onResult(ResponseVoid response) {
            onCompleted(peer, date);
        }

        @Override
        public void onError(RpcException e) {
            CursorReceiverActor.this.onError(peer, date);
        }
    });
}
Also used : ResponseVoid(im.actor.core.api.rpc.ResponseVoid) RpcException(im.actor.core.network.RpcException) ApiOutPeer(im.actor.core.api.ApiOutPeer) RequestMessageReceived(im.actor.core.api.rpc.RequestMessageReceived)

Example 7 with RpcException

use of im.actor.core.network.RpcException 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 8 with RpcException

use of im.actor.core.network.RpcException in project actor-platform by actorapp.

the class ChatFragment method onTextSent.

@Override
public void onTextSent(String sequence) {
    if (sequence.trim().length() > 0) {
        if (editRid == 0) {
            if (currentQuote != null) {
                messenger().sendMessage(peer, currentQuote + sequence);
                currentQuote = null;
                hideQuote();
            } else {
                messenger().sendMessage(peer, sequence);
            }
        } else {
            messenger().updateMessage(peer, sequence, editRid).failure(e -> {
                Activity activity = getActivity();
                if (activity != null) {
                    RpcException re = (RpcException) e;
                    String error;
                    if (re.getTag().equals("NOT_IN_TIME_WINDOW")) {
                        error = getString(R.string.edit_message_error_slowpoke);
                    } else if (re.getTag().equals("NOT_LAST_MESSAGE")) {
                        error = getString(R.string.edit_message_error_not_last);
                    } else {
                        error = re.getMessage();
                    }
                    Toast.makeText(activity, error, Toast.LENGTH_LONG).show();
                }
            });
            editRid = 0;
            hideQuote();
        }
        findInputBar().setText("");
    }
}
Also used : RpcException(im.actor.core.network.RpcException) Activity(android.app.Activity)

Example 9 with RpcException

use of im.actor.core.network.RpcException in project actor-platform by actorapp.

the class Authentication method requestCompleteOauth.

@Deprecated
public Command<AuthState> requestCompleteOauth(final String code) {
    return callback -> request(new RequestCompleteOAuth2(modules.getPreferences().getString(KEY_TRANSACTION_HASH), code), new RpcCallback<ResponseAuth>() {

        @Override
        public void onResult(ResponseAuth response) {
            onLoggedIn(callback, response);
        }

        @Override
        public void onError(final RpcException e) {
            if ("EMAIL_EXPIRED".equals(e.getTag())) {
                resetAuth();
            } else if ("EMAIL_UNOCCUPIED".equals(e.getTag())) {
                state = AuthState.SIGN_UP;
                callback.onResult(AuthState.SIGN_UP);
                return;
            }
            Runtime.postToMainThread(() -> {
                Log.e(TAG, e);
                callback.onError(e);
            });
        }
    });
}
Also used : ApiPhoneActivationType(im.actor.core.api.ApiPhoneActivationType) ResponseStartEmailAuth(im.actor.core.api.rpc.ResponseStartEmailAuth) RequestSendCodeByPhoneCall(im.actor.core.api.rpc.RequestSendCodeByPhoneCall) RequestSignUp(im.actor.core.api.rpc.RequestSignUp) Promise(im.actor.runtime.promise.Promise) Request(im.actor.core.network.parser.Request) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ResponseStartPhoneAuth(im.actor.core.api.rpc.ResponseStartPhoneAuth) ArrayList(java.util.ArrayList) AbsModule(im.actor.core.modules.AbsModule) AuthCodeRes(im.actor.core.entity.AuthCodeRes) User(im.actor.core.entity.User) RequestGetOAuth2Params(im.actor.core.api.rpc.RequestGetOAuth2Params) Response(im.actor.core.network.parser.Response) Modules(im.actor.core.modules.Modules) im.actor.runtime(im.actor.runtime) RequestValidateCode(im.actor.core.api.rpc.RequestValidateCode) RpcCallback(im.actor.core.network.RpcCallback) ApiEmailActivationType(im.actor.core.api.ApiEmailActivationType) CommandCallback(im.actor.core.viewmodel.CommandCallback) Sex(im.actor.core.entity.Sex) RequestStartEmailAuth(im.actor.core.api.rpc.RequestStartEmailAuth) Command(im.actor.core.viewmodel.Command) AuthRes(im.actor.core.entity.AuthRes) ResponseStartUsernameAuth(im.actor.core.api.rpc.ResponseStartUsernameAuth) ApiConfiguration(im.actor.core.ApiConfiguration) ResponseGetOAuth2Params(im.actor.core.api.rpc.ResponseGetOAuth2Params) AuthStartRes(im.actor.core.entity.AuthStartRes) ResponseAuth(im.actor.core.api.rpc.ResponseAuth) IOException(java.io.IOException) AuthState(im.actor.core.AuthState) Runtime(im.actor.runtime.Runtime) RequestStartUsernameAuth(im.actor.core.api.rpc.RequestStartUsernameAuth) RpcException(im.actor.core.network.RpcException) ConnectionEndpoint(im.actor.runtime.mtproto.ConnectionEndpoint) TrustedKey(im.actor.core.network.TrustedKey) RequestStartPhoneAuth(im.actor.core.api.rpc.RequestStartPhoneAuth) ApiSex(im.actor.core.api.ApiSex) Endpoints(im.actor.core.network.Endpoints) ConnectionEndpointArray(im.actor.runtime.mtproto.ConnectionEndpointArray) ResponseVoid(im.actor.core.api.rpc.ResponseVoid) RequestCompleteOAuth2(im.actor.core.api.rpc.RequestCompleteOAuth2) RequestValidatePassword(im.actor.core.api.rpc.RequestValidatePassword) RequestStartAnonymousAuth(im.actor.core.api.rpc.RequestStartAnonymousAuth) AuthMode(im.actor.core.entity.AuthMode) RequestCompleteOAuth2(im.actor.core.api.rpc.RequestCompleteOAuth2) ResponseAuth(im.actor.core.api.rpc.ResponseAuth) RpcException(im.actor.core.network.RpcException)

Example 10 with RpcException

use of im.actor.core.network.RpcException in project actor-platform by actorapp.

the class I18nEngine method formatErrorText.

@ObjectiveCName("formatErrorTextWithError:")
public String formatErrorText(Object o) {
    if (o instanceof RpcException) {
        RpcException e = (RpcException) o;
        String res = Errors.mapError(e.getTag(), null);
        if (res != null) {
            return get(res);
        } else {
            if (e.getMessage().equals("")) {
                return e.getTag();
            } else {
                return e.getMessage();
            }
        }
    } else if (o instanceof Exception) {
        return ((Exception) o).getMessage();
    } else {
        return "" + o;
    }
}
Also used : RpcException(im.actor.core.network.RpcException) JSONException(im.actor.runtime.json.JSONException) RpcException(im.actor.core.network.RpcException) ObjectiveCName(com.google.j2objc.annotations.ObjectiveCName)

Aggregations

RpcException (im.actor.core.network.RpcException)17 RpcCallback (im.actor.core.network.RpcCallback)8 ApiOutPeer (im.actor.core.api.ApiOutPeer)6 ArrayList (java.util.ArrayList)6 SeqUpdate (im.actor.core.api.base.SeqUpdate)5 User (im.actor.core.entity.User)5 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)5 ApiUser (im.actor.core.api.ApiUser)4 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)4 ResponseVoid (im.actor.core.api.rpc.ResponseVoid)4 IOException (java.io.IOException)4 ResponseSeq (im.actor.core.api.rpc.ResponseSeq)3 AbsModule (im.actor.core.modules.AbsModule)3 ModuleActor (im.actor.core.modules.ModuleActor)3 ModuleContext (im.actor.core.modules.ModuleContext)3 Modules (im.actor.core.modules.Modules)3 Command (im.actor.core.viewmodel.Command)3 Log (im.actor.runtime.Log)3 Void (im.actor.runtime.actors.messages.Void)3 Promise (im.actor.runtime.promise.Promise)3