diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 89be10a0..38156cc4 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -90,10 +90,7 @@ trait PeerHandler public function peer_isset($id) { - try { - - return isset($this->chats[$this->get_info($id)['bot_api_id']]); } catch (\danog\MadelineProto\Exception $e) { return false; @@ -137,7 +134,6 @@ trait PeerHandler public function get_info($id, $recursive = true) { - if (is_array($id)) { switch ($id['_']) { case 'inputUserSelf': @@ -185,7 +181,6 @@ trait PeerHandler } } - if (preg_match('/^channel#/', $id)) { $id = preg_replace('|\D+|', '-100', $id); } diff --git a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php index af1fa451..59e49d38 100644 --- a/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/ResponseHandler.php @@ -290,7 +290,7 @@ trait ResponseHandler } break; } - + if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users'])) { $this->add_users($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['users']); } diff --git a/src/danog/MadelineProto/MTProtoTools/SeqNoHandler.php b/src/danog/MadelineProto/MTProtoTools/SeqNoHandler.php index 9bb7e201..b56cd866 100644 --- a/src/danog/MadelineProto/MTProtoTools/SeqNoHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/SeqNoHandler.php @@ -25,17 +25,20 @@ trait SeqNoHandler return ($value * 2) + $in; } - public function check_in_seq_no($datacenter, $current_msg_id) { - - if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) && ($seq_no = $this->generate_in_seq_no($datacenter, $this->content_related($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']))) !== $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) { - \danog\MadelineProto\Logger::log(['Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')'], \danog\MadelineProto\Logger::ERROR); - } + + public function check_in_seq_no($datacenter, $current_msg_id) + { + if (isset($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) && ($seq_no = $this->generate_in_seq_no($datacenter, $this->content_related($this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_']))) !== $this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no']) { + \danog\MadelineProto\Logger::log(['Seqno mismatch (should be '.$seq_no.', is '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['seq_no'].', '.$this->datacenter->sockets[$datacenter]->incoming_messages[$current_msg_id]['content']['_'].')'], \danog\MadelineProto\Logger::ERROR); + } } + public function generate_in_seq_no($datacenter, $content_related) { $in = $content_related ? 1 : 0; $value = $this->datacenter->sockets[$datacenter]->session_in_seq_no; $this->datacenter->sockets[$datacenter]->session_in_seq_no += $in; + return ($value * 2) + $in; } diff --git a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php index da244820..27bea618 100644 --- a/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/UpdateHandler.php @@ -308,7 +308,7 @@ 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'])) || diff --git a/tests/testing.php b/tests/testing.php index 1da3033c..deae733d 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -70,7 +70,6 @@ echo 'Serializing MadelineProto to session.madeline...'.PHP_EOL; echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL; echo 'Size of MadelineProto instance is '.strlen(serialize($MadelineProto)).' bytes'.PHP_EOL; - $mention = $MadelineProto->get_info(getenv('TEST_USERNAME')); // Returns an array with all of the constructors that can be extracted from a username or an id $mention = $mention['user_id']; // Selects only the numeric user id @@ -117,7 +116,6 @@ foreach (json_decode(getenv('TEST_DESTINATION_GROUPS'), true) as $peer) { \danog\MadelineProto\Logger::log([$sentMessage], \danog\MadelineProto\Logger::NOTICE); foreach ($media as $type => $inputMedia) { $type = $MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $inputMedia]); - } }