From ea360c3d4d285bcfcead6edcc87634c6b98b0a9c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 8 Mar 2018 12:28:03 +0100 Subject: [PATCH] Beta features (#326) * Experimental performance improvements * Apply fixes from StyleCI * Support passing numeric ids instead of InputMessage objects, support using t.me links for sendMessage and other methods * Apply fixes from StyleCI --- src/danog/MadelineProto/Connection.php | 2 +- src/danog/MadelineProto/MTProto.php | 2 +- .../MadelineProto/MTProtoTools/MessageHandler.php | 2 +- .../MadelineProto/MTProtoTools/PeerHandler.php | 13 +++++++++++++ .../MadelineProto/MTProtoTools/ResponseHandler.php | 3 +++ src/danog/MadelineProto/TL/TL.php | 3 +++ src/danog/MadelineProto/Wrappers/Login.php | 2 +- 7 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/danog/MadelineProto/Connection.php b/src/danog/MadelineProto/Connection.php index 5dae2bf9..6cb1c352 100644 --- a/src/danog/MadelineProto/Connection.php +++ b/src/danog/MadelineProto/Connection.php @@ -47,7 +47,7 @@ class Connection public $object_queue = []; public $ack_queue = []; public $i = []; - public $must_open = false; + public $must_open = true; public $last_recv = 0; public function __magic_construct($proxy, $extra, $ip, $port, $protocol, $timeout, $ipv6) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 6228bf93..becc7976 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -266,7 +266,7 @@ class MTProto $this->channels_state = []; $this->got_state = false; } - $this->connect_to_all_dcs(); + //$this->connect_to_all_dcs(); //datacenter->__construct($this->settings['connection'], $this->settings['connection_settings']); foreach ($this->calls as $id => $controller) { if (!is_object($controller)) { diff --git a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php index 884eef27..b4f2ecb3 100644 --- a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php @@ -85,7 +85,7 @@ trait MessageHandler \danog\MadelineProto\Logger::log('Trying to read from closed socket, sending initial ping'); if ($this->is_http($datacenter)) { $this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]); - } else { + } elseif (isset($this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) && $this->datacenter->sockets[$datacenter]->temp_auth_key['connection_inited']) { $this->method_call('ping', ['ping_id' => 0], ['datacenter' => $datacenter]); } } diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index fab9b2b0..86a4fe7a 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -228,6 +228,19 @@ trait PeerHandler throw new \danog\MadelineProto\Exception('This peer is not present in the internal peer database'); } + if (preg_match('@(?:t|telegram)\.(?:me|dog)/(joinchat/)?([a-z0-9_-]*)@i', $id, $matches)) { + if ($matches[1] === '') { + $id = $matches[2]; + } else { + $invite = $this->method_call('messages.checkChatInvite', ['hash' => $matches[2]], ['datacenter' => $this->datacenter->curdc]); + var_dump($invite); + if (isset($invite['chat'])) { + return $this->get_info($invite['chat']); + } else { + throw new \danog\MadelineProto\Exception('You have not joined this chat'); + } + } + } $id = strtolower(str_replace('@', '', $id)); foreach ($this->chats as $chat) { if (isset($chat['username']) && strtolower($chat['username']) === $id) { diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index 800b62b9..c63166e2 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -298,6 +298,9 @@ trait ResponseHandler if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats'])) { $this->add_chats($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chats']); } + if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat'])) { + $this->add_chats([$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['chat']]); + } if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users'])) { $this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['result']['users']); } diff --git a/src/danog/MadelineProto/TL/TL.php b/src/danog/MadelineProto/TL/TL.php index 026d3f6b..a518b6ef 100644 --- a/src/danog/MadelineProto/TL/TL.php +++ b/src/danog/MadelineProto/TL/TL.php @@ -332,6 +332,9 @@ trait TL } } $auto = false; + if (!is_array($object) && $type['type'] === 'InputMessage') { + $object = ['_' => 'inputMessageID', 'id' => $object]; + } if ((!is_array($object) || isset($object['_']) && $this->constructors->find_by_predicate($object['_'])['type'] !== $type['type']) && in_array($type['type'], ['User', 'InputUser', 'Chat', 'InputChannel', 'Peer', 'InputPeer'])) { $object = $this->get_info($object); if (!isset($object[$type['type']])) { diff --git a/src/danog/MadelineProto/Wrappers/Login.php b/src/danog/MadelineProto/Wrappers/Login.php index 66e874f6..bdea0656 100644 --- a/src/danog/MadelineProto/Wrappers/Login.php +++ b/src/danog/MadelineProto/Wrappers/Login.php @@ -89,7 +89,7 @@ trait Login \danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_user'], \danog\MadelineProto\Logger::NOTICE); try { - $authorization = $this->method_call('auth.signIn', ['phone_number' => $this->authorization['phone_number'], 'phone_code_hash' => $this->authorization['phone_code_hash'], 'phone_code' => $code], ['datacenter' => $this->datacenter->curdc]); + $authorization = $this->method_call('auth.signIn', ['phone_number' => $this->authorization['phone_number'], 'phone_code_hash' => $this->authorization['phone_code_hash'], 'phone_code' => (string) $code], ['datacenter' => $this->datacenter->curdc]); } catch (\danog\MadelineProto\RPCErrorException $e) { if ($e->rpc === 'SESSION_PASSWORD_NEEDED') { \danog\MadelineProto\Logger::log(\danog\MadelineProto\Lang::$current_lang['login_2fa_enabled'], \danog\MadelineProto\Logger::NOTICE);