From d4405566eaf814aca46a78bed929fe9ba602b073 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 8 Mar 2018 22:19:03 +0100 Subject: [PATCH] Bugfixes --- docs/Chat.md | 2 +- src/danog/MadelineProto/MTProto.php | 2 +- .../MTProtoTools/CallHandler.php | 2 +- .../MTProtoTools/MessageHandler.php | 2 ++ .../MTProtoTools/PeerHandler.php | 21 +++++++++++++------ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/Chat.md b/docs/Chat.md index ea976dc1..4ce8ca34 100644 --- a/docs/Chat.md +++ b/docs/Chat.md @@ -28,7 +28,7 @@ description: chat attributes, type and example |phone\_calls\_available|[Bool](API_docs/types/Bool.md) | Optional|Are phone calls available for that user?| |phone\_calls\_private|[Bool](API_docs/types/Bool.md) | Optional|| |common\_chats\_count|[int](API_docs/types/int.md) | Optional|Number of chats in common with that user| -|photo|[string](API_docs/types/string.md) | Optional|bot API file id of the profile picture| +|photo|[string](API_docs/types/string.md) | Optional|bot API file object the profile picture| |title|[string](API_docs/types/string.md) | Optional|Chat title| |participants\_count|[int](API_docs/types/int.md) | Optional|Number of participants in the chat.| |kicked\_count|[int](API_docs/types/int.md) | Optional|Number of users kicked from the chat.| diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index becc7976..081d0380 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -47,7 +47,7 @@ class MTProto /* const V = 71; */ - const V = 92; + const V = 93; const NOT_LOGGED_IN = 0; const WAITING_CODE = 1; const WAITING_SIGNUP = -1; diff --git a/src/danog/MadelineProto/MTProtoTools/CallHandler.php b/src/danog/MadelineProto/MTProtoTools/CallHandler.php index 776a4001..eb018fb5 100644 --- a/src/danog/MadelineProto/MTProtoTools/CallHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/CallHandler.php @@ -177,7 +177,7 @@ trait CallHandler // This method receives data from the socket, and parses stuff } catch (\danog\MadelineProto\Exception $e) { $last_error = $e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine(); - if (in_array($e->getMessage(), ['I had to recreate the temporary authorization key', 'Got bad message notification']) || $e->getCode() === 404) { + if (in_array($e->getMessage(), ['Resend query', 'I had to recreate the temporary authorization key', 'Got bad message notification']) || $e->getCode() === 404) { continue 2; } \danog\MadelineProto\Logger::log('An error getting response of method '.$method.': '.$e->getMessage().' in '.basename($e->getFile(), '.php').' on line '.$e->getLine().'. Retrying...', \danog\MadelineProto\Logger::WARNING); diff --git a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php index b4f2ecb3..f17cfd9e 100644 --- a/src/danog/MadelineProto/MTProtoTools/MessageHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/MessageHandler.php @@ -87,6 +87,8 @@ trait MessageHandler $this->method_call('http_wait', ['max_wait' => 500, 'wait_after' => 150, 'max_delay' => 500], ['datacenter' => $datacenter]); } 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]); + } else { + throw new \danog\MadelineProto\Exception('Resend query'); } } $payload = $this->datacenter->sockets[$datacenter]->read_message(); diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 86a4fe7a..e9156350 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -233,7 +233,6 @@ trait PeerHandler $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 { @@ -466,12 +465,12 @@ trait PeerHandler if (!isset($res['participants']) && isset($res['can_view_participants']) && $res['can_view_participants'] && $fullfetch) { $res['participants'] = []; $limit = 200; - $filters = ['channelParticipantsRecent', 'channelParticipantsAdmins', 'channelParticipantsKicked', 'channelParticipantsBots', 'channelParticipantsBanned']; + $filters = ['channelParticipantsRecent', 'channelParticipantsSearch', 'channelParticipantsAdmins', 'channelParticipantsKicked', 'channelParticipantsBots', 'channelParticipantsBanned']; foreach ($filters as $filter) { - $offset = -$limit; + $offset = 0; try { - $gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => $filter, 'q' => ''], 'offset' => $offset += $limit, 'limit' => $limit, 'hash' => 0], ['datacenter' => $this->datacenter->curdc]); + $gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => $filter, 'q' => ''], 'offset' => $offset, 'limit' => $limit, 'hash' => $this->gen_participants_hash(array_keys($res['participants']))], ['datacenter' => $this->datacenter->curdc]); } catch (\danog\MadelineProto\RPCErrorException $e) { if ($e->rpc === 'CHAT_ADMIN_REQUIRED') { continue; @@ -479,7 +478,10 @@ trait PeerHandler throw $e; } } + + $count = $gres['count']; + while ($offset <= $count) { foreach ($gres['participants'] as $participant) { $newres = []; @@ -521,7 +523,8 @@ trait PeerHandler } $res['participants'][$participant['user_id']] = $newres; } - $gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => $filter, 'q' => ''], 'offset' => $offset += $limit, 'limit' => $limit, 'hash' => 0], ['datacenter' => $this->datacenter->curdc]); + //$gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => $filter, 'q' => ''], 'offset' => $offset += $limit, 'limit' => $limit, 'hash' => $this->gen_participants_hash(array_keys($res['participants']))], ['datacenter' => $this->datacenter->curdc]); + $gres = $this->method_call('channels.getParticipants', ['channel' => $full['InputChannel'], 'filter' => ['_' => $filter, 'q' => ''], 'offset' => $offset += count($gres['participants']), 'limit' => $limit, 'hash' => $this->gen_participants_hash(array_keys($res['participants']))], ['datacenter' => $this->datacenter->curdc]); if (empty($gres['participants'])) { break; } @@ -538,7 +541,13 @@ trait PeerHandler return $res; } - + public function gen_participants_hash($ids) { + $hash = 0; + foreach ($ids as $userID) { + $hash = (($hash * 20261) + 0x80000000 + $userID) % 0x80000000; + } + return $hash; + } public function store_db($res, $force = false) { $settings = isset($this->settings['connection_settings'][$this->datacenter->curdc]) ? $this->settings['connection_settings'][$this->datacenter->curdc] : $this->settings['connection_settings']['all'];