diff --git a/src/API.php b/src/API.php index 34a71830b..86e586905 100644 --- a/src/API.php +++ b/src/API.php @@ -51,7 +51,7 @@ final class API extends AbstractAPI * * @var string */ - public const RELEASE = '8.0.0-beta176'; + public const RELEASE = '8.0.0-beta177'; /** * We're not logged in. * diff --git a/src/EventHandler/Participant/Banned.php b/src/EventHandler/Participant/Banned.php index a5eb7999d..cc2d710e0 100644 --- a/src/EventHandler/Participant/Banned.php +++ b/src/EventHandler/Participant/Banned.php @@ -18,7 +18,6 @@ namespace danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant\Rights\Banned as BannedRights; -use danog\MadelineProto\MTProtoTools\DialogId; /** * Banned/kicked user. @@ -48,10 +47,6 @@ final class Banned extends Participant $this->kickedBy = $rawParticipant['kicked_by']; $this->date = $rawParticipant['date']; $this->bannedRights = new BannedRights($rawParticipant['banned_rights']); - $this->peer = match ($peer['_']) { - 'peerUser' => $peer['user_id'], - 'peerChat' => -$peer['chat_id'], - 'peerChannel' => DialogId::fromSupergroupOrChannel($peer['channel_id']), - }; + $this->peer = $peer; } } diff --git a/src/EventHandler/Participant/Left.php b/src/EventHandler/Participant/Left.php index b448ddf96..d4ae832b0 100644 --- a/src/EventHandler/Participant/Left.php +++ b/src/EventHandler/Participant/Left.php @@ -17,7 +17,6 @@ namespace danog\MadelineProto\EventHandler\Participant; use danog\MadelineProto\EventHandler\Participant; -use danog\MadelineProto\MTProtoTools\DialogId; /** * A participant that left the channel/supergroup. @@ -31,10 +30,6 @@ final class Left extends Participant public function __construct(array $rawParticipant) { $rawParticipant = $rawParticipant['peer']; - $this->peer = match ($rawParticipant['_']) { - 'peerUser' => $rawParticipant['user_id'], - 'peerChat' => -$rawParticipant['chat_id'], - 'peerChannel' => DialogId::fromSupergroupOrChannel($rawParticipant['channel_id']), - }; + $this->peer = $rawParticipant['peer']; } } diff --git a/src/EventHandler/Typing/ChatUserTyping.php b/src/EventHandler/Typing/ChatUserTyping.php index e74349fca..cfb1770a0 100644 --- a/src/EventHandler/Typing/ChatUserTyping.php +++ b/src/EventHandler/Typing/ChatUserTyping.php @@ -31,6 +31,6 @@ final class ChatUserTyping extends Typing public function __construct(MTProto $API, array $rawTyping) { parent::__construct($API, $rawTyping); - $this->chatId = $rawTyping['chat_id']; + $this->chatId = -$rawTyping['chat_id']; } } diff --git a/src/MTProtoTools/PeerHandler.php b/src/MTProtoTools/PeerHandler.php index c03f0c5a6..ed5afeddf 100644 --- a/src/MTProtoTools/PeerHandler.php +++ b/src/MTProtoTools/PeerHandler.php @@ -855,7 +855,7 @@ trait PeerHandler } return $res; } - private function recurseAlphabetSearchParticipants($channel, $filter, $q, $total_count, &$res, int $depth) + private function recurseAlphabetSearchParticipants(int $channel, string $filter, string $q, int $total_count, array &$res, int $depth): array { if (!($this->fetchParticipants($channel, $filter, $q, $total_count, $res))) { return []; @@ -885,7 +885,7 @@ trait PeerHandler return []; } - private function fetchParticipants($channel, $filter, $q, $total_count, &$res) + private function fetchParticipants(int $channel, string $filter, string $q, int $total_count, array &$res): bool { $offset = 0; $limit = 200; @@ -907,6 +907,7 @@ trait PeerHandler } else { $this->storeParticipantsCache($gres, $channel, $filter, $q, $offset, $limit); } + \assert($gres !== null); if ($last_count !== -1 && $last_count !== $gres['count']) { $has_more = true; } else { @@ -959,7 +960,7 @@ trait PeerHandler }); } await($promises); - $h = $hash ? 'present' : 'absent'; + $h = $hash !== null ? 'present' : 'absent'; $this->logger->logger('Fetched '.\count($gres['participants'])." channel participants with filter {$filter}, query {$q}, offset {$offset}, limit {$limit}, hash {$h}: ".($cached ? 'cached' : 'not cached').', '.($offset + \count($gres['participants'])).' participants out of '.$gres['count'].', in total fetched '.\count($res['participants']).' out of '.$total_count); $offset += \count($gres['participants']); } while (\count($gres['participants'])); @@ -975,11 +976,11 @@ trait PeerHandler { return "$channelId'$filter'$q'$offset'$limit"; } - private function fetchParticipantsCache($channel, $filter, $q, $offset, $limit) + private function fetchParticipantsCache(int $channel, string $filter, string $q, int $offset, int $limit): ?array { - return $this->channelParticipants[$this->participantsKey($channel['channel_id'], $filter, $q, $offset, $limit)]; + return $this->channelParticipants[$this->participantsKey($channel, $filter, $q, $offset, $limit)]; } - private function storeParticipantsCache($gres, $channel, $filter, $q, $offset, $limit): void + private function storeParticipantsCache(array $gres, int $channel, string $filter, string $q, int $offset, int $limit): void { unset($gres['users']); $ids = []; @@ -990,10 +991,10 @@ trait PeerHandler } sort($ids, SORT_NUMERIC); $gres['hash'] = Tools::genVectorHash($ids); - $this->channelParticipants[$this->participantsKey($channel['channel_id'], $filter, $q, $offset, $limit)] = $gres; + $this->channelParticipants[$this->participantsKey($channel, $filter, $q, $offset, $limit)] = $gres; } - private function getParticipantsHash($channel, $filter, $q, $offset, $limit) + private function getParticipantsHash(int $channel, string $filter, string $q, int $offset, int $limit): ?string { - return ($this->channelParticipants[$this->participantsKey($channel['channel_id'], $filter, $q, $offset, $limit)])['hash'] ?? 0; + return $this->fetchParticipantsCache($channel, $filter, $q, $offset, $limit)['hash'] ?? null; } } diff --git a/src/MTProtoTools/UpdateHandler.php b/src/MTProtoTools/UpdateHandler.php index ccba81359..ffb7bbe3c 100644 --- a/src/MTProtoTools/UpdateHandler.php +++ b/src/MTProtoTools/UpdateHandler.php @@ -555,14 +555,14 @@ trait UpdateHandler $this, $message, $info, - $message['action']['channel_id'], + DialogId::fromSupergroupOrChannel($message['action']['channel_id']), ), 'messageActionChannelMigrateFrom' => new DialogChannelMigrateFrom( $this, $message, $info, $message['action']['title'], - $message['action']['chat_id'], + -$message['action']['chat_id'], ), 'messageActionGameScore' => new DialogGameScore( $this,