1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 15:51:15 +01:00

Peer improvements

This commit is contained in:
Daniil Gentili 2023-12-15 14:58:28 +01:00
parent 211404665c
commit 1dde960b95
6 changed files with 16 additions and 25 deletions

View File

@ -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.
*

View File

@ -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;
}
}

View File

@ -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'];
}
}

View File

@ -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'];
}
}

View File

@ -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;
}
}

View File

@ -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,