From c59aae4218c788f8c261b3bc991efcff11b90ccc Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 29 Mar 2019 23:30:07 +0000 Subject: [PATCH] Fixes --- src/danog/MadelineProto/MTProto.php | 23 +++++++++++--------- src/danog/MadelineProto/VoIPServerConfig.php | 5 ----- src/danog/MadelineProto/Wrappers/Login.php | 8 +++---- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 23109c2a..80a0d31d 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -839,18 +839,21 @@ class MTProto implements TLCallback } yield $dcs; yield $this->init_authorization_async(); - $this->phoneConfigWatcherId = Loop::repeat(24 * 3600 * 1000, function ($watcherId) { - if ($this->authorized === self::LOGGED_IN) { - $this->logger->logger("Fetching phone config..."); - VoIPServerConfig::updateDefault(yield $this->method_call_async_read('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc])); - } else { - $this->logger->logger("Not fetching phone config"); - } - }); - VoIPServerConfig::updateDefault(yield $this->method_call_async_read('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc])); + if (!$this->phoneConfigWatcherId) $this->phoneConfigWatcherId = Loop::repeat(24 * 3600 * 1000, [$this, 'get_phone_config_async']); + yield $this->get_phone_config_async(); $this->logger->logger("Started phone config fetcher"); } + public function get_phone_config_async($watcherId = null) + { + if ($this->authorized === self::LOGGED_IN && extension_loaded('libtgvoip')) { + $this->logger->logger("Fetching phone config..."); + VoIPServerConfig::updateDefault(yield $this->method_call_async_read('phone.getCallConfig', [], ['datacenter' => $this->settings['connection_settings']['default_dc']])); + } else { + $this->logger->logger("Not fetching phone config"); + } + } + public function get_config($config = [], $options = []) { return $this->wait($this->get_config_async($config, $options)); @@ -861,7 +864,7 @@ class MTProto implements TLCallback if ($this->config['expires'] > time()) { return $this->config; } - $this->config = empty($config) ? yield $this->method_call_async_read('help.getConfig', $config, empty($options) ? ['datacenter' => $this->datacenter->curdc] : $options) : $config; + $this->config = empty($config) ? yield $this->method_call_async_read('help.getConfig', $config, empty($options) ? ['datacenter' => $this->settings['connection_settings']['default_dc']] : $options) : $config; yield $this->parse_config(); return $this->config; diff --git a/src/danog/MadelineProto/VoIPServerConfig.php b/src/danog/MadelineProto/VoIPServerConfig.php index 325dc687..0ebdafee 100644 --- a/src/danog/MadelineProto/VoIPServerConfig.php +++ b/src/danog/MadelineProto/VoIPServerConfig.php @@ -89,9 +89,4 @@ if (class_exists('\\danog\\MadelineProto\\VoIPServerConfigInternal')) { return array_merge(self::$_configDefault, self::$_config); } } -} else { - class VoIPServerConfig - { - public static function update(array $config) {} - } } diff --git a/src/danog/MadelineProto/Wrappers/Login.php b/src/danog/MadelineProto/Wrappers/Login.php index c252fbcd..8d264538 100644 --- a/src/danog/MadelineProto/Wrappers/Login.php +++ b/src/danog/MadelineProto/Wrappers/Login.php @@ -123,7 +123,7 @@ trait Login $this->authorization = $authorization; $this->datacenter->sockets[$this->datacenter->curdc]->authorized = true; yield $this->init_authorization_async(); - VoIPServerConfig::updateDefault(yield $this->method_call_async_read('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc])); + yield $this->get_phone_config_async(); $this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE); @@ -154,7 +154,7 @@ trait Login $this->datacenter->sockets[$dc_id]->authorized = true; $this->authorized = self::LOGGED_IN; yield $this->init_authorization_async(); - VoIPServerConfig::updateDefault(yield $this->method_call_async_read('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc])); + yield $this->get_phone_config_async(); return yield $this->get_self_async(); } @@ -181,7 +181,7 @@ trait Login $this->authorized = self::LOGGED_IN; $this->datacenter->sockets[$this->datacenter->curdc]->authorized = true; yield $this->init_authorization_async(); - VoIPServerConfig::updateDefault(yield $this->method_call_async_read('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc])); + yield $this->get_phone_config_async(); $this->logger->logger(\danog\MadelineProto\Lang::$current_lang['signup_ok'], \danog\MadelineProto\Logger::NOTICE); @@ -202,7 +202,7 @@ trait Login $this->datacenter->sockets[$this->datacenter->curdc]->authorized = true; yield $this->init_authorization_async(); $this->logger->logger(\danog\MadelineProto\Lang::$current_lang['login_ok'], \danog\MadelineProto\Logger::NOTICE); - VoIPServerConfig::updateDefault(yield $this->method_call_async_read('phone.getCallConfig', [], ['datacenter' => $this->datacenter->curdc])); + yield $this->get_phone_config_async(); return $this->authorization; }