From d87bc048edaea5149307e74eeb250fe6883ff42e Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Fri, 17 Aug 2018 18:36:11 +0300 Subject: [PATCH] Fix authorization --- .../osmand/telegram/helpers/TelegramHelper.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt index 299405c1c9..e787c6036c 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt @@ -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,31 +689,35 @@ 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 -> { - log.info("Init tdlib parameters") + if (!info) { + log.info("Init tdlib parameters") - val parameters = TdApi.TdlibParameters() - parameters.databaseDirectory = File(appDir, "tdlib").absolutePath - parameters.useMessageDatabase = true - parameters.useSecretChats = true - parameters.apiId = 293148 - parameters.apiHash = "d1942abd0f1364efe5020e2bfed2ed15" - parameters.systemLanguageCode = "en" - parameters.deviceModel = "Android" - parameters.systemVersion = "OsmAnd Telegram" - parameters.applicationVersion = "1.0" - parameters.enableStorageOptimizer = true + val parameters = TdApi.TdlibParameters() + parameters.databaseDirectory = File(appDir, "tdlib").absolutePath + parameters.useMessageDatabase = true + parameters.useSecretChats = true + parameters.apiId = 293148 + parameters.apiHash = "d1942abd0f1364efe5020e2bfed2ed15" + parameters.systemLanguageCode = "en" + parameters.deviceModel = "Android" + parameters.systemVersion = "OsmAnd Telegram" + parameters.applicationVersion = "1.0" + parameters.enableStorageOptimizer = true - client!!.send(TdApi.SetTdlibParameters(parameters), AuthorizationRequestHandler()) + client!!.send(TdApi.SetTdlibParameters(parameters), AuthorizationRequestHandler()) + } } TdApi.AuthorizationStateWaitEncryptionKey.CONSTRUCTOR -> { - client!!.send(TdApi.CheckDatabaseEncryptionKey(), AuthorizationRequestHandler()) + if (!info) { + client!!.send(TdApi.CheckDatabaseEncryptionKey(), AuthorizationRequestHandler()) + } } TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR -> { log.info("Request phone number")