From d062ec44d0d76a072ff2fad9342ac9e5c1c5aa82 Mon Sep 17 00:00:00 2001 From: mjentsch Date: Sat, 23 Aug 2014 02:41:26 +0200 Subject: [PATCH] Switch to ready-state when the data center is already registered --- loop.c | 6 ------ telegram.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/loop.c b/loop.c index 90be491..9dfe044 100644 --- a/loop.c +++ b/loop.c @@ -567,12 +567,6 @@ int network_phone_is_registered() { } */ -/** - * Return whether the current client is registered. - */ -int network_client_is_registered(struct telegram *tg) { - return !(tg->auth.auth_state == 100 || !(telegram_get_working_dc(tg)->has_auth)); -} /** * Verify the phone number by providing the sms_code and the real name diff --git a/telegram.c b/telegram.c index fda4e58..ecaf2a0 100755 --- a/telegram.c +++ b/telegram.c @@ -74,6 +74,10 @@ void telegram_change_state (struct telegram *instance, int state, void *data) case STATE_AUTHORIZED: logprintf("requesting configuration\n"); telegram_change_state(instance, STATE_CONFIG_REQUESTED, NULL); + if (telegram_is_registered(instance)) { + telegram_change_state (instance, STATE_READY, NULL); + return; + } do_help_get_config (instance); break; @@ -102,6 +106,12 @@ void telegram_change_state (struct telegram *instance, int state, void *data) logprintf("client authentication, user needs to enter code"); // wait for user input ... break; + + case STATE_READY: + logprintf("telegram is registered and ready.\n"); + telegram_store_session (instance); + instance->config->on_ready (instance); + break; case STATE_DISCONNECTED_SWITCH_DC: { // telegram demands that we use a different data center, which caused