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