2021-09-27 19:27:13 +02:00
|
|
|
package it.tdlight.client;
|
|
|
|
|
|
|
|
import it.tdlight.common.ExceptionHandler;
|
|
|
|
import it.tdlight.common.TelegramClient;
|
|
|
|
import it.tdlight.common.utils.ScannerUtils;
|
|
|
|
import it.tdlight.jni.TdApi;
|
|
|
|
import it.tdlight.jni.TdApi.AuthorizationStateWaitEncryptionKey;
|
2021-09-27 20:22:57 +02:00
|
|
|
import it.tdlight.jni.TdApi.AuthorizationStateWaitPhoneNumber;
|
2021-09-27 19:27:13 +02:00
|
|
|
import it.tdlight.jni.TdApi.CheckDatabaseEncryptionKey;
|
2021-09-27 20:22:57 +02:00
|
|
|
import it.tdlight.jni.TdApi.Error;
|
2021-09-27 19:27:13 +02:00
|
|
|
import it.tdlight.jni.TdApi.PhoneNumberAuthenticationSettings;
|
|
|
|
import it.tdlight.jni.TdApi.SetAuthenticationPhoneNumber;
|
|
|
|
import it.tdlight.jni.TdApi.UpdateAuthorizationState;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
final class AuthorizationStateWaitAuthenticationDataHandler implements GenericUpdateHandler<UpdateAuthorizationState> {
|
|
|
|
|
|
|
|
private final TelegramClient client;
|
|
|
|
private final Authenticable authenticable;
|
|
|
|
private final ExceptionHandler exceptionHandler;
|
|
|
|
|
|
|
|
public AuthorizationStateWaitAuthenticationDataHandler(TelegramClient client,
|
|
|
|
Authenticable authenticable,
|
|
|
|
ExceptionHandler exceptionHandler) {
|
|
|
|
this.client = client;
|
|
|
|
this.authenticable = authenticable;
|
|
|
|
this.exceptionHandler = exceptionHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(UpdateAuthorizationState update) {
|
|
|
|
if (update.authorizationState.getConstructor() == TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR) {
|
|
|
|
AuthenticationData authenticationData = authenticable.getAuthenticationData();
|
|
|
|
if (authenticationData.isBot()) {
|
|
|
|
String botToken = authenticationData.getBotToken();
|
|
|
|
TdApi.CheckAuthenticationBotToken response = new TdApi.CheckAuthenticationBotToken(botToken);
|
2021-09-27 20:22:57 +02:00
|
|
|
client.send(response, ok -> {
|
|
|
|
if (ok.getConstructor() == Error.CONSTRUCTOR) {
|
|
|
|
throw new TelegramError((Error) ok);
|
|
|
|
}
|
2021-09-27 21:44:24 +02:00
|
|
|
}, exceptionHandler);
|
2021-09-27 19:27:13 +02:00
|
|
|
} else {
|
|
|
|
PhoneNumberAuthenticationSettings phoneSettings = new PhoneNumberAuthenticationSettings(false, false, false);
|
|
|
|
|
|
|
|
String phoneNumber = String.valueOf(authenticationData.getUserPhoneNumber());
|
|
|
|
SetAuthenticationPhoneNumber response = new SetAuthenticationPhoneNumber(phoneNumber, phoneSettings);
|
2021-09-27 20:22:57 +02:00
|
|
|
client.send(response, ok -> {
|
|
|
|
if (ok.getConstructor() == Error.CONSTRUCTOR) {
|
|
|
|
throw new TelegramError((Error) ok);
|
|
|
|
}
|
2021-09-27 21:44:24 +02:00
|
|
|
}, exceptionHandler);
|
2021-09-27 19:27:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|