Fix authorization
This commit is contained in:
parent
ae20adac9f
commit
d87bc048ed
1 changed files with 20 additions and 16 deletions
|
@ -291,7 +291,7 @@ class TelegramHelper private constructor() {
|
||||||
fun requestAuthorizationState() {
|
fun requestAuthorizationState() {
|
||||||
client?.send(TdApi.GetAuthorizationState()) { obj ->
|
client?.send(TdApi.GetAuthorizationState()) { obj ->
|
||||||
if (obj is TdApi.AuthorizationState) {
|
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()
|
val prevAuthState = getTelegramAuthorizationState()
|
||||||
if (authorizationState != null) {
|
if (authorizationState != null) {
|
||||||
this.authorizationState = authorizationState
|
this.authorizationState = authorizationState
|
||||||
}
|
}
|
||||||
when (this.authorizationState?.constructor) {
|
when (this.authorizationState?.constructor) {
|
||||||
TdApi.AuthorizationStateWaitTdlibParameters.CONSTRUCTOR -> {
|
TdApi.AuthorizationStateWaitTdlibParameters.CONSTRUCTOR -> {
|
||||||
log.info("Init tdlib parameters")
|
if (!info) {
|
||||||
|
log.info("Init tdlib parameters")
|
||||||
|
|
||||||
val parameters = TdApi.TdlibParameters()
|
val parameters = TdApi.TdlibParameters()
|
||||||
parameters.databaseDirectory = File(appDir, "tdlib").absolutePath
|
parameters.databaseDirectory = File(appDir, "tdlib").absolutePath
|
||||||
parameters.useMessageDatabase = true
|
parameters.useMessageDatabase = true
|
||||||
parameters.useSecretChats = true
|
parameters.useSecretChats = true
|
||||||
parameters.apiId = 293148
|
parameters.apiId = 293148
|
||||||
parameters.apiHash = "d1942abd0f1364efe5020e2bfed2ed15"
|
parameters.apiHash = "d1942abd0f1364efe5020e2bfed2ed15"
|
||||||
parameters.systemLanguageCode = "en"
|
parameters.systemLanguageCode = "en"
|
||||||
parameters.deviceModel = "Android"
|
parameters.deviceModel = "Android"
|
||||||
parameters.systemVersion = "OsmAnd Telegram"
|
parameters.systemVersion = "OsmAnd Telegram"
|
||||||
parameters.applicationVersion = "1.0"
|
parameters.applicationVersion = "1.0"
|
||||||
parameters.enableStorageOptimizer = true
|
parameters.enableStorageOptimizer = true
|
||||||
|
|
||||||
client!!.send(TdApi.SetTdlibParameters(parameters), AuthorizationRequestHandler())
|
client!!.send(TdApi.SetTdlibParameters(parameters), AuthorizationRequestHandler())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TdApi.AuthorizationStateWaitEncryptionKey.CONSTRUCTOR -> {
|
TdApi.AuthorizationStateWaitEncryptionKey.CONSTRUCTOR -> {
|
||||||
client!!.send(TdApi.CheckDatabaseEncryptionKey(), AuthorizationRequestHandler())
|
if (!info) {
|
||||||
|
client!!.send(TdApi.CheckDatabaseEncryptionKey(), AuthorizationRequestHandler())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR -> {
|
TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR -> {
|
||||||
log.info("Request phone number")
|
log.info("Request phone number")
|
||||||
|
|
Loading…
Reference in a new issue