diff --git a/CHANGELOG.md b/CHANGELOG.md index b444db11..5de7893a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,8 @@ * 2fa+++++ * improved callfork * split acks - +* TL callabck +* channel state Things to expect in the next releases: Document async apis optional max_id and min_id diff --git a/src/danog/MadelineProto/Loop/Connection/CheckLoop.php b/src/danog/MadelineProto/Loop/Connection/CheckLoop.php index a0feb411..82c7aa51 100644 --- a/src/danog/MadelineProto/Loop/Connection/CheckLoop.php +++ b/src/danog/MadelineProto/Loop/Connection/CheckLoop.php @@ -58,69 +58,71 @@ class CheckLoop extends ResumableSignalLoop if ($connection->hasPendingCalls()) { $last_recv = $connection->get_max_id(true); if ($connection->temp_auth_key !== null) { - $message_ids = $connection->getPendingCalls(); //array_values($connection->new_outgoing); - $deferred = new Deferred(); - $deferred->promise()->onResolve( - function ($e, $result) use ($message_ids, $API, $connection, $datacenter) { - if ($e) { - $API->logger("Got exception in check loop for DC $datacenter"); - $API->logger((string) $e); - return; - } - $reply = []; - foreach (str_split($result['info']) as $key => $chr) { - $message_id = $message_ids[$key]; - if (!isset($connection->outgoing_messages[$message_id])) { - $API->logger->logger('Already got response for and forgot about message ID '.($message_id)); - continue; + $full_message_ids = $connection->getPendingCalls(); //array_values($connection->new_outgoing); + foreach (array_chunk($full_message_ids, 8192) as $message_ids) { + $deferred = new Deferred(); + $deferred->promise()->onResolve( + function ($e, $result) use ($message_ids, $API, $connection, $datacenter) { + if ($e) { + $API->logger("Got exception in check loop for DC $datacenter"); + $API->logger((string) $e); + return; } - if (!isset($connection->new_outgoing[$message_id])) { - $API->logger->logger('Already got response for '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id)); - continue; - } - $chr = ord($chr); - switch ($chr & 7) { - case 0: - $API->logger->logger('Wrong message status 0 for '.$connection->outgoing_messages[$message_id]['_'], \danog\MadelineProto\Logger::FATAL_ERROR); - break; - case 1: - case 2: - case 3: - if ($connection->outgoing_messages[$message_id]['_'] === 'msgs_state_req') { - $API->got_response_for_outgoing_message_id($message_id, $datacenter); + $reply = []; + foreach (str_split($result['info']) as $key => $chr) { + $message_id = $message_ids[$key]; + if (!isset($connection->outgoing_messages[$message_id])) { + $API->logger->logger('Already got response for and forgot about message ID '.($message_id)); + continue; + } + if (!isset($connection->new_outgoing[$message_id])) { + $API->logger->logger('Already got response for '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id)); + continue; + } + $chr = ord($chr); + switch ($chr & 7) { + case 0: + $API->logger->logger('Wrong message status 0 for '.$connection->outgoing_messages[$message_id]['_'], \danog\MadelineProto\Logger::FATAL_ERROR); break; - } - $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' not received by server, resending...', \danog\MadelineProto\Logger::ERROR); - $API->method_recall('watcherId', ['message_id' => $message_id, 'datacenter' => $datacenter, 'postpone' => true]); - break; - case 4: - if ($chr & 32) { - $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server and is being processed, waiting...', \danog\MadelineProto\Logger::ERROR); - } elseif ($chr & 64) { - $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server and was already processed, requesting reply...', \danog\MadelineProto\Logger::ERROR); - $reply[] = $message_id; - } elseif ($chr & 128) { - $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server and was already sent, requesting reply...', \danog\MadelineProto\Logger::ERROR); - $reply[] = $message_id; - } else { - $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server, requesting reply...', \danog\MadelineProto\Logger::ERROR); - $reply[] = $message_id; - } + case 1: + case 2: + case 3: + if ($connection->outgoing_messages[$message_id]['_'] === 'msgs_state_req') { + $API->got_response_for_outgoing_message_id($message_id, $datacenter); + break; + } + $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' not received by server, resending...', \danog\MadelineProto\Logger::ERROR); + $API->method_recall('watcherId', ['message_id' => $message_id, 'datacenter' => $datacenter, 'postpone' => true]); + break; + case 4: + if ($chr & 32) { + $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server and is being processed, waiting...', \danog\MadelineProto\Logger::ERROR); + } elseif ($chr & 64) { + $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server and was already processed, requesting reply...', \danog\MadelineProto\Logger::ERROR); + $reply[] = $message_id; + } elseif ($chr & 128) { + $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server and was already sent, requesting reply...', \danog\MadelineProto\Logger::ERROR); + $reply[] = $message_id; + } else { + $API->logger->logger('Message '.$connection->outgoing_messages[$message_id]['_'].' with message ID '.($message_id).' received by server, requesting reply...', \danog\MadelineProto\Logger::ERROR); + $reply[] = $message_id; + } + } } + if ($reply) { + $this->callFork($API->object_call_async('msg_resend_ans_req', ['msg_ids' => $reply], ['datacenter' => $datacenter, 'postpone' => true])); + } + $connection->writer->resume(); } - if ($reply) { - $this->callFork($API->object_call_async('msg_resend_ans_req', ['msg_ids' => $reply], ['datacenter' => $datacenter, 'postpone' => true])); - } - $connection->writer->resume(); + ); + $list = ''; + // Don't edit this here pls + foreach ($message_ids as $message_id) { + $list .= $connection->outgoing_messages[$message_id]['_'].', '; } - ); - $list = ''; - // Don't edit this here pls - foreach ($message_ids as $message_id) { - $list .= $connection->outgoing_messages[$message_id]['_'].', '; + $API->logger->logger("Still missing $list on DC $datacenter, sending state request", \danog\MadelineProto\Logger::ERROR); + yield $API->object_call_async('msgs_state_req', ['msg_ids' => $message_ids], ['datacenter' => $datacenter, 'promise' => $deferred]); } - $API->logger->logger("Still missing $list on DC $datacenter, sending state request", \danog\MadelineProto\Logger::ERROR); - yield $API->object_call_async('msgs_state_req', ['msg_ids' => $message_ids], ['datacenter' => $datacenter, 'promise' => $deferred]); } else { foreach ($connection->new_outgoing as $message_id) { if (isset($connection->outgoing_messages[$message_id]['sent']) diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 7de65a58..fb352938 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -404,7 +404,7 @@ class MTProto extends AsyncConstruct implements TLCallback } if (!$this->settings['updates']['handle_old_updates']) { - $this->channels_state = new CombinedUpdatesState([false => new UpdatesState()]); + $this->channels_state = new CombinedUpdatesState(); $this->got_state = false; } yield $this->connect_to_all_dcs_async(); diff --git a/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php b/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php index aa95a732..d84ac7cf 100644 --- a/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php +++ b/src/danog/MadelineProto/MTProtoTools/CombinedUpdatesState.php @@ -27,10 +27,10 @@ class CombinedUpdatesState private $states = []; public function __construct($init = []) { + $this->states[false] = new UpdatesState(); if (!is_array($init)) { return; } - $this->states[false] = new UpdatesState(); foreach ($init as $channel => $state) { if (is_array($state)) { $state = new UpdatesState($state, $channel); diff --git a/src/danog/MadelineProto/Wrappers/ApiTemplates.php b/src/danog/MadelineProto/Wrappers/ApiTemplates.php index 03d3ded9..735d1034 100644 --- a/src/danog/MadelineProto/Wrappers/ApiTemplates.php +++ b/src/danog/MadelineProto/Wrappers/ApiTemplates.php @@ -73,7 +73,7 @@ trait ApiTemplates
  • Click on create application
  • ', '')); } else { - yield $stdout->write($this->web_api_echo_template('Enter your phone number
    '.$message.'', '')); + yield $stdout->write($this->web_api_echo_template('Enter a phone number that is already registered on telegram to get the API ID
    '.$message.'', '')); } } else { if ($message) {