From d833b0cff8cd8aea46525ef94acdfa44ab40729c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 11 Mar 2018 17:36:32 +0000 Subject: [PATCH] Bugfixes to peer management --- src/danog/MadelineProto/API.php | 4 ++-- src/danog/MadelineProto/MTProtoTools/PeerHandler.php | 12 ++++++++++-- .../MadelineProto/MTProtoTools/ResponseHandler.php | 4 ---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 9a67c7da..fd55bbfb 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -18,6 +18,7 @@ class API extends APIFactory use \danog\Serializable; public $session; public $serialized = 0; + public $API; public function __magic_construct($params = []) { @@ -25,7 +26,6 @@ class API extends APIFactory if (is_string($params)) { $realpaths = Serialization::realpaths($params); if (file_exists($realpaths['file'])) { - $this->session = $realpaths['file']; if (!file_exists($realpaths['lockfile'])) { touch($realpaths['lockfile']); clearstatcache(); @@ -71,6 +71,7 @@ class API extends APIFactory if (isset($unserialized->API)) { $this->API = $unserialized->API; $this->APIFactory(); + $this->session = $realpaths['file']; } return; @@ -88,7 +89,6 @@ class API extends APIFactory public function __wakeup() { - //if (method_exists($this->API, 'wakeup')) $this->API = $this->API->wakeup(); $this->APIFactory(); } diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 6600d677..370c6dc4 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -35,7 +35,13 @@ trait PeerHandler foreach ($users as $key => $user) { if (!isset($user['access_hash'])) { if (isset($user['username']) && !isset($this->chats[$user['id']])) { - $this->get_pwr_chat($user['username'], false, true); + try { + $this->get_pwr_chat($user['username'], false, true); + } catch (\danog\MadelineProto\Exception $e) { + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); + } catch (\danog\MadelineProto\RPCErrorException $e) { + \danog\MadelineProto\Logger::log($e->getMessage(), \danog\MadelineProto\Logger::WARNING); + } } continue; } @@ -115,6 +121,8 @@ trait PeerHandler { try { return isset($this->chats[$this->get_info($id)['bot_api_id']]); + } catch (\danog\MadelineProto\Exception $e) { + return false; } catch (\danog\MadelineProto\RPCErrorException $e) { if ($e->rpc === 'CHAT_FORBIDDEN') { return true; @@ -656,7 +664,7 @@ trait PeerHandler $this->qres = []; $this->last_stored = time() + 10; } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log('======= COULD NOT STORE IN DB DUE TO '.$e->getMessage().' =============', \danog\MadelineProto\Logger::VERBOSE); + \danog\MadelineProto\Logger::log("======= COULD NOT STORE IN DB DUE TO ".$e->getMessage()." =============", \danog\MadelineProto\Logger::VERBOSE); } } diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index 30a758d3..b332c207 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -326,10 +326,6 @@ trait ResponseHandler return $only_updates; } - public function handle_messages_threaded() - { - } - public function handle_rpc_error($server_answer, &$aargs) { if (in_array($server_answer['error_message'], ['PERSISTENT_TIMESTAMP_EMPTY', 'PERSISTENT_TIMESTAMP_OUTDATED', 'PERSISTENT_TIMESTAMP_INVALID'])) {