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:
parent
45358b0d6f
commit
a078dd68a6
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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']),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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']),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user