Fix authorization

This commit is contained in:
Alex Sytnyk 2018-08-17 18:36:11 +03:00
parent ae20adac9f
commit d87bc048ed

View file

@ -291,7 +291,7 @@ class TelegramHelper private constructor() {
fun requestAuthorizationState() {
client?.send(TdApi.GetAuthorizationState()) { obj ->
if (obj is TdApi.AuthorizationState) {
onAuthorizationStateUpdated(obj)
onAuthorizationStateUpdated(obj, true)
}
}
}
@ -689,13 +689,14 @@ class TelegramHelper private constructor() {
}
}
private fun onAuthorizationStateUpdated(authorizationState: AuthorizationState?) {
private fun onAuthorizationStateUpdated(authorizationState: AuthorizationState?, info: Boolean = false) {
val prevAuthState = getTelegramAuthorizationState()
if (authorizationState != null) {
this.authorizationState = authorizationState
}
when (this.authorizationState?.constructor) {
TdApi.AuthorizationStateWaitTdlibParameters.CONSTRUCTOR -> {
if (!info) {
log.info("Init tdlib parameters")
val parameters = TdApi.TdlibParameters()
@ -712,9 +713,12 @@ class TelegramHelper private constructor() {
client!!.send(TdApi.SetTdlibParameters(parameters), AuthorizationRequestHandler())
}
}
TdApi.AuthorizationStateWaitEncryptionKey.CONSTRUCTOR -> {
if (!info) {
client!!.send(TdApi.CheckDatabaseEncryptionKey(), AuthorizationRequestHandler())
}
}
TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR -> {
log.info("Request phone number")
telegramAuthorizationRequestHandler?.telegramAuthorizationRequestListener?.onRequestTelegramAuthenticationParameter(PHONE_NUMBER)