1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-11 14:48:25 +01:00
MadelineProto/src/EventHandler/Update.php

50 lines
1.3 KiB
PHP
Raw Normal View History

2023-06-28 15:50:38 +02:00
<?php declare(strict_types=1);
namespace danog\MadelineProto\EventHandler;
use danog\MadelineProto\API;
use danog\MadelineProto\Ipc\Client;
use danog\MadelineProto\MTProto;
/**
* Represents a generic update.
*/
abstract class Update
{
private readonly string $session;
protected MTProto|Client|null $API;
/** @internal */
public static function fromRawUpdate(
MTProto $API,
array $rawUpdate
): ?self {
return match ($rawUpdate['_']) {
'updateNewMessage' => Message::fromRawUpdate($API, $rawUpdate['message']),
'updateNewChannelMessage' => $API->getType($rawUpdate) === API::PEER_TYPE_CHANNEL
? ChannelMessage::fromRawUpdate($API, $rawUpdate['message'])
: Message::fromRawUpdate($API, $rawUpdate['message']),
default => null
};
}
/** @internal */
protected function __construct(
MTProto $API,
public readonly array $rawUpdate
) {
$this->API = $API;
$this->session = $API->wrapper->getSession()->getSessionDirectoryPath();
}
public function __sleep()
{
$vars = \get_object_vars($this);
unset($vars['API']);
return \array_keys($vars);
}
public function __wakeup(): void
{
$this->API = Client::giveInstanceBySession($this->session);
}
}