diff --git a/README.md b/README.md index 007d920ef..1d4e01f6a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ It can login with a phone number (MTProto API), or with a bot token (MTProto API ```php getInputClientProxy isHttp - refreshNext - refreshNext + refreshNextDisable + refreshNextEnable @@ -1713,10 +1713,6 @@ - - - - @@ -1751,9 +1747,6 @@ nextSent]]> - - - getUpdatesState loadUpdateState diff --git a/src/Broadcast/Action/ActionSend.php b/src/Broadcast/Action/ActionSend.php index 8b94c8507..ec17b8bea 100644 --- a/src/Broadcast/Action/ActionSend.php +++ b/src/Broadcast/Action/ActionSend.php @@ -40,8 +40,8 @@ public function act(int $broadcastId, int $peer, Cancellation $cancellation): vo return; } $id = $this->API->extractMessageId($this->API->methodCallAsyncRead( - isset($message['media']['_']) && - $message['media']['_'] !== 'messageMediaWebPage' + \is_string($message['media']) || (isset($message['media']['_']) && + $message['media']['_'] !== 'messageMediaWebPage') ? 'messages.sendMedia' : 'messages.sendMessage', array_merge($message, ['peer' => $peer, 'floodWaitLimit' => 2*86400, 'cancellation' => $cancellation]), diff --git a/src/Connection.php b/src/Connection.php index 9f409c268..539f20c68 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -555,16 +555,19 @@ public function sendMessage(MTProtoOutgoingMessage $message): void if (!$message->hasSerializedBody() || $message->shouldRefreshReferences()) { $body = $message->getBody(); if ($message->shouldRefreshReferences()) { - $this->API->referenceDatabase->refreshNext(true); + $this->API->referenceDatabase->refreshNextEnable(); } - if ($message->isMethod) { - $body = $this->API->getTL()->serializeMethod($message->constructor, $body); - } else { - $body['_'] = $message->constructor; - $body = $this->API->getTL()->serializeObject(['type' => ''], $body, $message->constructor); - } - if ($message->shouldRefreshReferences()) { - $this->API->referenceDatabase->refreshNext(false); + try { + if ($message->isMethod) { + $body = $this->API->getTL()->serializeMethod($message->constructor, $body); + } else { + $body['_'] = $message->constructor; + $body = $this->API->getTL()->serializeObject(['type' => ''], $body, $message->constructor); + } + } finally { + if ($message->shouldRefreshReferences()) { + $this->API->referenceDatabase->refreshNextDisable(); + } } $message->setSerializedBody($body); unset($body); diff --git a/src/MTProtoTools/Files.php b/src/MTProtoTools/Files.php index c6dfdfb64..bc82c829b 100644 --- a/src/MTProtoTools/Files.php +++ b/src/MTProtoTools/Files.php @@ -1110,7 +1110,7 @@ public function downloadToCallable(mixed $messageMedia, callable $callable, ?cal $origCb(100, 0, 0); return; } - $parallel_chunks = $seekable ? $parallel_chunks : 1; + $parallel_chunks = $seekable ? $parallel_chunks : 2; if ($params) { $previous_promise = true; $promises = []; diff --git a/src/MTProtoTools/ReferenceDatabase.php b/src/MTProtoTools/ReferenceDatabase.php index 1fc2bc325..e65b87863 100644 --- a/src/MTProtoTools/ReferenceDatabase.php +++ b/src/MTProtoTools/ReferenceDatabase.php @@ -441,19 +441,23 @@ private function storeReference(string $location, string $reference, int $origin EventLoop::queue($this->flush(...), $location); } - public function refreshNext(bool $refresh = false): void + public function refreshNextEnable(): void { - if ($this->refreshCount === 1 && !$refresh) { - $this->refreshed = []; - $this->refreshCount--; - $this->refresh = false; - } elseif ($this->refreshCount === 0 && $refresh) { + if ($this->refreshCount === 0) { $this->refreshed = []; $this->refreshCount++; $this->refresh = true; - } elseif ($this->refreshCount === 0 && !$refresh) { - } elseif ($refresh) { + } else { $this->refreshCount++; + } + } + public function refreshNextDisable(): void + { + if ($this->refreshCount === 1) { + $this->refreshed = []; + $this->refreshCount--; + $this->refresh = false; + } elseif ($this->refreshCount === 0) { } else { $this->refreshCount--; } diff --git a/src/TL/Conversion/BotAPI.php b/src/TL/Conversion/BotAPI.php index 9c9f8dc4d..60a188769 100644 --- a/src/TL/Conversion/BotAPI.php +++ b/src/TL/Conversion/BotAPI.php @@ -206,7 +206,7 @@ public function MTProtoToBotAPI(array $data): array if (isset($data['fwd_from']['from_id'])) { $newd['forward_from'] = ($this->getPwrChat($data['fwd_from']['from_id'], false)); } - if ($data['fwd_from'] < 0) { + if (isset($data['fwd_from']) && $data['fwd_from'] < 0) { try { $newd['forward_from_chat'] = $this->getPwrChat($data['fwd_from'], false); } catch (Throwable $e) {