From 1e259ae6c84dcfcbd17afb4066cbeda2dd8951ce Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 27 Dec 2018 21:57:28 +0100 Subject: [PATCH] Improve update handling logic --- .../MadelineProto/MTProtoTools/PeerHandler.php | 1 + .../MadelineProto/MTProtoTools/ResponseHandler.php | 13 +++++-------- .../MadelineProto/MTProtoTools/UpdateHandler.php | 7 ++++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index ccc2cac4..06cd6c26 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -351,6 +351,7 @@ trait PeerHandler if (is_string($id)) { $id = \danog\MadelineProto\Magic::$bigint ? (float) $id : (int) $id; } + if (!isset($this->chats[$id])) { try { if ($id < 0) { diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index 5cd020da..34fd8e50 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -63,7 +63,6 @@ trait ResponseHandler //$n = $this->n++; $only_updates = true; foreach ($this->datacenter->sockets[$datacenter]->new_incoming as $current_msg_id) { - //var_dump($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]); $this->logger->logger((isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['from_container']) ? 'Inside of container, received ' : 'Received ').$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].' from DC '.$datacenter, \danog\MadelineProto\Logger::ULTRA_VERBOSE); switch ($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']) { @@ -305,7 +304,6 @@ trait ResponseHandler public function handle_response($request_id, $response_id, $datacenter) { - //var_dumP("Response ".bin2hex($request_id)); $response = &$this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content']; unset($this->datacenter->sockets[$datacenter]->incoming_messages[$response_id]['content']); $request = &$this->datacenter->sockets[$datacenter]->outgoing_messages[$request_id]; @@ -542,12 +540,10 @@ trait ResponseHandler } if (count($this->pending_updates)) { $this->logger->logger('Parsing pending updates...'); - foreach (array_keys($this->pending_updates) as $key) { - if (isset($this->pending_updates[$key])) { - $updates = $this->pending_updates[$key]; - unset($this->pending_updates[$key]); - $this->handle_updates($updates); - } + $updates = $this->pending_updates; + $this->pending_updates = []; + foreach ($updates as $update) { + $this->handle_updates($update); } } } @@ -579,6 +575,7 @@ trait ResponseHandler $opts[$key] = $updates[$key]; } } + switch ($updates['_']) { case 'updates': case 'updatesCombined': diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index 22faf863..e93eb4ab 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -405,7 +405,12 @@ trait UpdateHandler case 'updateEditMessage': case 'updateNewChannelMessage': case 'updateEditChannelMessage': - if (isset($update['message']['from_id']) && !$this->peer_isset($update['message']['from_id']) || !$this->peer_isset($update['message']['to_id']) || isset($update['message']['via_bot_id']) && !$this->peer_isset($update['message']['via_bot_id']) || isset($update['message']['entities']) && !$this->entities_peer_isset($update['message']['entities']) || isset($update['message']['fwd_from']) && !$this->fwd_peer_isset($update['message']['fwd_from'])) { + if ((isset($update['message']['from_id']) && !$this->peer_isset($update['message']['from_id'])) || + !$this->peer_isset($update['message']['to_id']) || + isset($update['message']['via_bot_id']) && !$this->peer_isset($update['message']['via_bot_id']) || + isset($update['message']['entities']) && !$this->entities_peer_isset($update['message']['entities']) // || + //isset($update['message']['fwd_from']) && !$this->fwd_peer_isset($update['message']['fwd_from']) + ) { $this->logger->logger('Not enough data for message update, getting difference...', \danog\MadelineProto\Logger::VERBOSE); if ($channel_id !== false && $this->peer_isset($this->to_supergroup($channel_id))) { $this->get_channel_difference($channel_id);