From 0df07f3a37d8a533ddcb3264071a0c0648570270 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 2 Mar 2024 19:32:18 +0100 Subject: [PATCH] Fix #1490 --- src/EventHandler/AbstractMessage.php | 15 +++++++++++++-- src/Magic.php | 2 -- tools/TL/Builder.php | 17 ++++++++++------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/EventHandler/AbstractMessage.php b/src/EventHandler/AbstractMessage.php index 17fbc975d..0b495abc6 100644 --- a/src/EventHandler/AbstractMessage.php +++ b/src/EventHandler/AbstractMessage.php @@ -389,14 +389,25 @@ abstract class AbstractMessage extends Update implements SimpleFilters */ public function read(bool $readAll = false): bool { - return $this->getClient()->methodCallAsyncRead( - DialogId::isSupergroupOrChannel($this->chatId) ? 'channels.readHistory':'messages.readHistory', + if (DialogId::isSupergroupOrChannel($this->chatId)) { + return $this->getClient()->methodCallAsyncRead( + 'channels.readHistory', + [ + 'peer' => $this->chatId, + 'channel' => $this->chatId, + 'max_id' => $readAll ? 0 : $this->id, + ] + ); + } + $this->getClient()->methodCallAsyncRead( + 'messages.readHistory', [ 'peer' => $this->chatId, 'channel' => $this->chatId, 'max_id' => $readAll ? 0 : $this->id, ] ); + return true; } /** diff --git a/src/Magic.php b/src/Magic.php index 6873c26c4..2ad5a6e81 100644 --- a/src/Magic.php +++ b/src/Magic.php @@ -31,8 +31,6 @@ use const DIRECTORY_SEPARATOR; use const E_ALL; use const MADELINE_WORKER_TYPE; use const PHP_INT_SIZE; -use const PHP_MAJOR_VERSION; -use const PHP_MINOR_VERSION; use const PHP_SAPI; use const SIG_DFL; diff --git a/tools/TL/Builder.php b/tools/TL/Builder.php index f636a159b..70060d6de 100644 --- a/tools/TL/Builder.php +++ b/tools/TL/Builder.php @@ -76,7 +76,8 @@ final class Builder } private array $methodsCalled = []; private array $methodsCreated = []; - private function methodCall(string $method): string { + private function methodCall(string $method): string + { $this->methodsCalled[$method] = true; return $this->methodsCreated[$method] ? "\$this->$method(\$stream)" @@ -104,7 +105,7 @@ final class Builder 'int128' => 'stream_get_contents($stream, 16)', 'int256' => 'stream_get_contents($stream, 32)', 'int512' => 'stream_get_contents($stream, 64)', - 'string', 'bytes', 'waveform', 'random_bytes' => + 'string', 'bytes', 'waveform', 'random_bytes' => $this->methodCall("deserialize_$type"), default => \in_array($type, self::RECURSIVE_TYPES, true) || isset($param['subtype']) ? $this->methodCall("deserialize_type_{$this->escapeTypeName($type)}") @@ -121,7 +122,7 @@ final class Builder } $superBare = $this->typeByPredicate[$predicate] === 'JSONValue' || $this->typeByPredicate[$predicate] === 'Peer'; - + $result = ''; if (!$superBare) { $result .= "[\n"; @@ -231,10 +232,12 @@ final class Builder return $result; ', 'array', static: $type === 'JSONValue'); } - private function w(string $data): void { + private function w(string $data): void + { fwrite($this->output, $data); } - public function m(string $methodName, string $body, string $returnType = 'mixed', bool $public = false, bool $static = true): void { + public function m(string $methodName, string $body, string $returnType = 'mixed', bool $public = false, bool $static = true): void + { $this->methodsCreated[$methodName] = $static; $public = $public ? 'public' : 'private'; $static = $static ? 'static' : ''; @@ -339,7 +342,7 @@ final class Builder $initial_constructors = array_filter( $this->TL->getConstructors()->by_id, - fn (array $arr) => $arr['type'] === 'Update' + static fn (array $arr) => $arr['type'] === 'Update' || $arr['predicate'] === 'rpc_result' || !$arr['encrypted'] ); @@ -369,7 +372,7 @@ final class Builder continue; } $this->m( - "deserialize_type_{$this->escapeTypeName($type)}", + "deserialize_type_{$this->escapeTypeName($type)}", "return {$this->buildTypes($constructors, $type)};", static: $type === 'JSONValue' );