use of im.actor.core.network.parser.Response in project actor-platform by actorapp.
the class Authentication method requestStartEmailAuth.
@Deprecated
public Command<AuthState> requestStartEmailAuth(final String email) {
return callback -> {
ArrayList<String> langs1 = new ArrayList<>();
for (String s : modules.getConfiguration().getPreferredLanguages()) {
langs1.add(s);
}
request(new RequestStartEmailAuth(email, apiConfiguration.getAppId(), apiConfiguration.getAppKey(), deviceHash, apiConfiguration.getDeviceTitle(), modules.getConfiguration().getTimeZone(), langs1), new RpcCallback<ResponseStartEmailAuth>() {
@Override
public void onResult(ResponseStartEmailAuth response) {
modules.getPreferences().putString(KEY_EMAIL, email);
modules.getPreferences().putString(KEY_TRANSACTION_HASH, response.getTransactionHash());
ApiEmailActivationType emailActivationType = response.getActivationType();
if (emailActivationType.equals(ApiEmailActivationType.OAUTH2)) {
state = AuthState.GET_OAUTH_PARAMS;
} else if (emailActivationType.equals(ApiEmailActivationType.CODE)) {
state = AuthState.CODE_VALIDATION_EMAIL;
} else if (emailActivationType.equals(ApiEmailActivationType.PASSWORD)) {
state = AuthState.PASSWORD_VALIDATION;
} else {
state = AuthState.CODE_VALIDATION_EMAIL;
}
Runtime.postToMainThread(() -> callback.onResult(state));
}
@Override
public void onError(final RpcException e) {
Runtime.postToMainThread(() -> {
Log.e(TAG, e);
callback.onError(e);
});
}
});
};
}
use of im.actor.core.network.parser.Response in project actor-platform by actorapp.
the class ApiBroker method processResponse.
private void processResponse(long authId, long mid, byte[] content) {
if (authId != currentAuthId) {
return;
}
ProtoStruct protoStruct;
try {
protoStruct = ProtoSerializer.readRpcResponsePayload(content);
} catch (IOException e) {
e.printStackTrace();
Log.w(TAG, "Broken response mid#" + mid);
return;
}
// Log.w(TAG, protoStruct + " mid#" + mid);
long rid;
if (idMap.containsKey(mid)) {
rid = idMap.get(mid);
} else {
return;
}
CommonTimer timer = timeouts.get(rid);
if (timer != null) {
timer.cancel();
timeouts.remove(rid);
}
RequestHolder holder;
if (requests.containsKey(rid)) {
holder = requests.get(rid);
} else {
return;
}
if (protoStruct instanceof RpcOk) {
RpcOk ok = (RpcOk) protoStruct;
requests.remove(rid);
if (holder.protoId != 0) {
idMap.remove(holder.protoId);
}
Response response;
try {
response = (Response) parserConfig.parseRpc(ok.responseType, ok.payload);
} catch (IOException e) {
e.printStackTrace();
requests.remove(rid);
if (holder.protoId != 0) {
idMap.remove(holder.protoId);
}
holder.callback.onError(new RpcInternalException());
return;
}
Log.d(TAG, "<- response#" + holder.publicId + ": " + response + " in " + (Runtime.getCurrentTime() - holder.requestTime) + " ms");
holder.callback.onResult(response);
} else if (protoStruct instanceof RpcError) {
RpcError e = (RpcError) protoStruct;
requests.remove(rid);
if (holder.protoId != 0) {
idMap.remove(holder.protoId);
}
Log.w(TAG, "<- error#" + holder.publicId + ": " + e.errorTag + " " + e.errorCode + " " + e.userMessage + " in " + (Runtime.getCurrentTime() - holder.requestTime) + " ms");
holder.callback.onError(new RpcException(e.errorTag, e.errorCode, e.userMessage, e.canTryAgain, e.relatedData));
} else if (protoStruct instanceof RpcInternalError) {
RpcInternalError e = ((RpcInternalError) protoStruct);
Log.d(TAG, "<- internal_error#" + holder.publicId + " " + e.getTryAgainDelay() + " sec" + " in " + (Runtime.getCurrentTime() - holder.requestTime) + " ms");
if (e.isCanTryAgain()) {
schedule(new ForceResend(rid), e.getTryAgainDelay() * 1000L);
} else {
requests.remove(rid);
if (holder.protoId != 0) {
idMap.remove(holder.protoId);
}
holder.callback.onError(new RpcInternalException());
}
} else if (protoStruct instanceof RpcFloodWait) {
RpcFloodWait f = (RpcFloodWait) protoStruct;
Log.d(TAG, "<- flood_wait#" + holder.publicId + " " + f.getDelay() + " sec" + " in " + (Runtime.getCurrentTime() - holder.requestTime) + " ms");
schedule(new ForceResend(rid), f.getDelay() * 1000L);
} else {
Log.d(TAG, "<- unknown_package#" + holder.publicId + " in " + (Runtime.getCurrentTime() - holder.requestTime) + " ms");
}
}
use of im.actor.core.network.parser.Response 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())) {
// modules.getPreferences().putString(KEY_CODE, code);
state = AuthState.SIGN_UP;
callback.onResult(AuthState.SIGN_UP);
return;
}
Runtime.postToMainThread(() -> {
Log.e(TAG, e);
callback.onError(e);
});
}
});
}
Aggregations