1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 08:18:59 +01:00

fix Participants class

This commit is contained in:
َAhJ 2023-11-23 19:46:05 +03:30
parent 45358b0d6f
commit a078dd68a6
5 changed files with 49 additions and 54 deletions

View File

@ -17,15 +17,9 @@
namespace danog\MadelineProto\EventHandler\Message;
use AssertionError;
use danog\MadelineProto\MTProto;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\EventHandler\Participant\Admin;
use danog\MadelineProto\EventHandler\Participant\Banned;
use danog\MadelineProto\EventHandler\Participant\Creator;
use danog\MadelineProto\EventHandler\Participant\Left;
use danog\MadelineProto\EventHandler\Participant\Member;
use danog\MadelineProto\EventHandler\Participant\MySelf;
use danog\MadelineProto\MTProto;
/**
* Represents an incoming or outgoing channel message.
@ -87,16 +81,7 @@ final class ChannelMessage extends Message
'participant' => $member,
]
)['participant'];
return match ($result['_']) {
'channelParticipant' => new Member($result),
'channelParticipantLeft' => new Left($client, $result),
'channelParticipantSelf' => new MySelf($result),
'channelParticipantAdmin' => new Admin($result),
'channelParticipantBanned' => new Banned($client, $result),
'channelParticipantCreator' => new Creator($result),
default => throw new AssertionError("undefined Participant type: {$result['_']}")
};
return Participant::fromRawParticipant($result);
}
/**

View File

@ -17,20 +17,14 @@
namespace danog\MadelineProto\EventHandler\Message;
use AssertionError;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\Service\DialogTopicCreated;
use danog\MadelineProto\EventHandler\Message\Service\DialogTopicEdited;
use danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\EventHandler\Participant\Admin;
use danog\MadelineProto\EventHandler\Participant\Banned;
use danog\MadelineProto\EventHandler\Participant\Creator;
use danog\MadelineProto\EventHandler\Participant\Left;
use danog\MadelineProto\EventHandler\Participant\Member;
use danog\MadelineProto\EventHandler\Participant\MySelf;
use danog\MadelineProto\EventHandler\Topic\IconColor;
use danog\MadelineProto\MTProtoTools\DialogId;
use Webmozart\Assert\Assert;
use Webmozart\Assert\InvalidArgumentException;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\MTProtoTools\DialogId;
use danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\EventHandler\Topic\IconColor;
use danog\MadelineProto\EventHandler\Message\Service\DialogTopicCreated;
use danog\MadelineProto\EventHandler\Message\Service\DialogTopicEdited;
/**
* Represents an incoming or outgoing group message.
@ -54,16 +48,7 @@ final class GroupMessage extends Message
'participant' => $member,
]
)['participant'];
return match ($result['_']) {
'channelParticipant' => new Member($result),
'channelParticipantLeft' => new Left($client, $result),
'channelParticipantSelf' => new MySelf($result),
'channelParticipantAdmin' => new Admin($result),
'channelParticipantBanned' => new Banned($client, $result),
'channelParticipantCreator' => new Creator($result),
default => throw new AssertionError("undefined Participant type: {$result['_']}")
};
return Participant::fromRawParticipant($result);
}
/**

View File

@ -16,15 +16,36 @@
namespace danog\MadelineProto\EventHandler;
use JsonSerializable;
use AssertionError;
use ReflectionClass;
use ReflectionProperty;
use JsonSerializable;
use danog\MadelineProto\EventHandler\Participant\Left;
use danog\MadelineProto\EventHandler\Participant\Admin;
use danog\MadelineProto\EventHandler\Participant\Banned;
use danog\MadelineProto\EventHandler\Participant\Member;
use danog\MadelineProto\EventHandler\Participant\MySelf;
use danog\MadelineProto\EventHandler\Participant\Creator;
/**
* Info about a channel participant.
*/
abstract class Participant implements JsonSerializable
{
public static function fromRawParticipant(array $rawParticipant): self
{
return match ($rawParticipant['_'])
{
'channelParticipant' => new Member($rawParticipant),
'channelParticipantLeft' => new Left($rawParticipant),
'channelParticipantSelf' => new MySelf($rawParticipant),
'channelParticipantAdmin' => new Admin($rawParticipant),
'channelParticipantBanned' => new Banned($rawParticipant),
'channelParticipantCreator' => new Creator($rawParticipant),
default => throw new AssertionError("undefined Participant type: {$rawParticipant['_']}")
};
}
/** @internal */
public function jsonSerialize(): mixed
{

View File

@ -16,10 +16,9 @@
namespace danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\MTProtoTools\DialogId;
use danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\EventHandler\Participant\Rights\Banned as BannedRights;
use danog\MadelineProto\Ipc\Client;
use danog\MadelineProto\MTProto;
/**
* Banned/kicked user.
@ -42,14 +41,17 @@ final class Banned extends Participant
public readonly BannedRights $bannedRights;
/** @internal */
public function __construct(
MTProto|Client $API,
array $rawParticipant
) {
public function __construct(array $rawParticipant)
{
$peer = $rawParticipant['peer'];
$this->left = $rawParticipant['left'];
$this->peer = $API->getIdInternal($rawParticipant['peer']);
$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']),
};
}
}

View File

@ -16,9 +16,8 @@
namespace danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\MTProtoTools\DialogId;
use danog\MadelineProto\EventHandler\Participant;
use danog\MadelineProto\Ipc\Client;
use danog\MadelineProto\MTProto;
/**
* A participant that left the channel/supergroup.
@ -29,10 +28,13 @@ final class Left extends Participant
public readonly int $peer;
/** @internal */
public function __construct(
MTProto|Client $API,
array $rawParticipant
) {
$this->peer = $API->getIdInternal($rawParticipant['peer']);
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']),
};
}
}