mirror of
https://github.com/danog/MadelineProto.git
synced 2024-12-03 14:27:47 +01:00
More fixes and works on Media classes!
This commit is contained in:
parent
0799a8a52f
commit
fcb5c8ba95
@ -27,12 +27,12 @@ use danog\MadelineProto\TL\Types\Bytes;
|
||||
final class Document extends Media
|
||||
{
|
||||
/** Content of thumbnail file (JPEGfile, quality 55, set in a square 90x90) only for secret chats. */
|
||||
public readonly string $thumb;
|
||||
public readonly ?Bytes $thumb;
|
||||
/** Thumbnail height only for secret chats. */
|
||||
public readonly int $thumbHeight;
|
||||
public readonly ?int $thumbHeight;
|
||||
/** Thumbnail width only for secret chats. */
|
||||
public readonly int $thumbWidth;
|
||||
/** Caption only for secret chats. */
|
||||
public readonly ?int $thumbWidth;
|
||||
/** Caption. */
|
||||
public readonly ?string $caption;
|
||||
|
||||
/** @internal */
|
||||
@ -42,7 +42,7 @@ final class Document extends Media
|
||||
bool $protected
|
||||
) {
|
||||
parent::__construct($API, $rawMedia, $protected);
|
||||
$this->thumb = (string) $rawMedia['thumb'] ?? null;
|
||||
$this->thumb = new Bytes($rawMedia['thumb']) ?? null;
|
||||
$this->thumbHeight = $rawMedia['thumb_h'] ?? null;
|
||||
$this->thumbWidth = $rawMedia['thumb_w'] ?? null;
|
||||
$this->caption = $rawMedia['caption'] ?? null;
|
||||
|
@ -27,13 +27,13 @@ use danog\MadelineProto\TL\Types\Bytes;
|
||||
final class Photo extends Media
|
||||
{
|
||||
/** If true; the current media has attached mask stickers. */
|
||||
public readonly ?bool $hasStickers;
|
||||
public readonly bool $hasStickers;
|
||||
/** Content of thumbnail file (JPEGfile, quality 55, set in a square 90x90) only for secret chats. */
|
||||
public readonly string $thumb;
|
||||
public readonly ?Bytes $thumb;
|
||||
/** Thumbnail height only for secret chats. */
|
||||
public readonly int $thumbHeight;
|
||||
public readonly ?int $thumbHeight;
|
||||
/** Thumbnail width only for secret chats. */
|
||||
public readonly int $thumbWidth;
|
||||
public readonly ?int $thumbWidth;
|
||||
|
||||
/** @internal */
|
||||
public function __construct(
|
||||
@ -42,19 +42,9 @@ final class Photo extends Media
|
||||
bool $protected,
|
||||
) {
|
||||
parent::__construct($API, $rawMedia, $protected);
|
||||
$this->hasStickers = $rawMedia['photo']['has_stickers'] ?? null;
|
||||
$this->thumb = (string) $rawMedia['thumb'] ?? null;
|
||||
$this->hasStickers = $rawMedia['photo']['has_stickers'] ?? false;
|
||||
$this->thumb = new Bytes($rawMedia['thumb']) ?? null;
|
||||
$this->thumbHeight = $rawMedia['thumb_h'] ?? null;
|
||||
$this->thumbWidth = $rawMedia['thumb_w'] ?? null;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
$v = \get_object_vars($this);
|
||||
unset($v['API'], $v['session'], $v['location']);
|
||||
$v['_'] = static::class;
|
||||
$v['thumb'] = new Bytes($v['thumb']);
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ final class Video extends AbstractVideo
|
||||
/** If true; the current media has attached mask stickers. */
|
||||
public readonly bool $hasStickers;
|
||||
/** Content of thumbnail file (JPEGfile, quality 55, set in a square 90x90) only for secret chats. */
|
||||
public readonly string $thumb;
|
||||
public readonly ?Bytes $thumb;
|
||||
/** Thumbnail height only for secret chats. */
|
||||
public readonly int $thumbHeight;
|
||||
public readonly ?int $thumbHeight;
|
||||
/** Thumbnail width only for secret chats. */
|
||||
public readonly int $thumbWidth;
|
||||
public readonly ?int $thumbWidth;
|
||||
|
||||
/** @internal */
|
||||
public function __construct(
|
||||
@ -49,18 +49,8 @@ final class Video extends AbstractVideo
|
||||
}
|
||||
}
|
||||
$this->hasStickers = $hasStickers;
|
||||
$this->thumb = (string) $rawMedia['thumb'] ?? null;
|
||||
$this->thumb = new Bytes($rawMedia['thumb']) ?? null;
|
||||
$this->thumbHeight = $rawMedia['thumb_h'] ?? null;
|
||||
$this->thumbWidth = $rawMedia['thumb_w'] ?? null;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
$v = \get_object_vars($this);
|
||||
unset($v['API'], $v['session'], $v['location']);
|
||||
$v['_'] = static::class;
|
||||
$v['thumb'] = new Bytes($v['thumb']);
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ abstract class Message extends AbstractMessage
|
||||
$this->entities = MessageEntity::fromRawEntities($rawMessage['entities'] ?? []);
|
||||
$this->message = $rawMessage['message'];
|
||||
$this->fromScheduled = $rawMessage['from_scheduled'];
|
||||
$this->viaBotId = $rawMessage['via_bot_id'] ?? null;
|
||||
$this->viaBotId = $rawMessage['via_bot_id'] ?? $this->getClient()->getIdInternal($rawMessage['via_bot_name']) ?? null;
|
||||
$this->editDate = $rawMessage['edit_date'] ?? null;
|
||||
|
||||
$this->keyboard = isset($rawMessage['reply_markup'])
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
namespace danog\MadelineProto\EventHandler\Message;
|
||||
|
||||
use AssertionError;
|
||||
use danog\MadelineProto\EventHandler\AbstractMessage;
|
||||
use danog\MadelineProto\EventHandler\AbstractPrivateMessage;
|
||||
use danog\MadelineProto\MTProto;
|
||||
|
||||
@ -28,14 +30,27 @@ class SecretMessage extends AbstractPrivateMessage
|
||||
public readonly ?bool $noWebpage;
|
||||
/** Random message ID of the message this message replies to (parameter added in layer 45) */
|
||||
public readonly ?int $replyToRandomId;
|
||||
/** Specifies the ID of the inline bot that generated the message (parameter added in layer 45) */
|
||||
public readonly ?string $viaBotName;
|
||||
/** @internal */
|
||||
public function __construct(MTProto $API, array $rawMessage, array $info)
|
||||
{
|
||||
parent::__construct($API, $decryptedMessage = $rawMessage['decrypted_message'], $info);
|
||||
$this->noWebpage = $decryptedMessage['no_webpage'] ?? null;
|
||||
$this->replyToRandomId = $decryptedMessage['reply_to_random_id'] ?? null;
|
||||
$this->viaBotName = $decryptedMessage['via_bot_name'] ?? null;
|
||||
}
|
||||
//TODO implement it using getSecretChat
|
||||
/*public function getReply(string $class = AbstractMessage::class) : ?AbstractMessage
|
||||
{
|
||||
if ($class !== AbstractMessage::class && !\is_subclass_of($class, AbstractMessage::class)) {
|
||||
throw new AssertionError("A class that extends AbstractMessage was expected.");
|
||||
}
|
||||
if ($this->replyToMsgId === null) {
|
||||
return null;
|
||||
}
|
||||
if ($this->replyCached) {
|
||||
if (!$this->replyCache instanceof $class) {
|
||||
return null;
|
||||
}
|
||||
return $this->replyCache;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -17,13 +17,13 @@
|
||||
namespace danog\MadelineProto\EventHandler\Message\Service\SecretChat;
|
||||
|
||||
use danog\MadelineProto\EventHandler\Action;
|
||||
use danog\MadelineProto\EventHandler\Message\ServiceMessage;
|
||||
use danog\MadelineProto\EventHandler\Typing;
|
||||
use danog\MadelineProto\MTProto;
|
||||
|
||||
/**
|
||||
* User is preparing a message: typing, recording, uploading, etc.
|
||||
*/
|
||||
class ActionTyping extends ServiceMessage
|
||||
class SecretUserTyping extends Typing
|
||||
{
|
||||
public function __construct(
|
||||
MTProto $API,
|
||||
@ -33,6 +33,6 @@ class ActionTyping extends ServiceMessage
|
||||
/** Type of action */
|
||||
public readonly Action $action
|
||||
) {
|
||||
parent::__construct($API, $rawMessage, $info);
|
||||
parent::__construct($API, $rawMessage);
|
||||
}
|
||||
}
|
@ -58,12 +58,15 @@ trait FilesAbstraction
|
||||
*/
|
||||
public function wrapMedia(array $media, bool $protected = false): ?Media
|
||||
{
|
||||
if ($media['_'] === 'messageMediaPhoto' || $media['_'] == 'decryptedMessageMediaPhoto') {
|
||||
if ($media['_'] === 'messageMediaPhoto') {
|
||||
if (!isset($media['photo'])) {
|
||||
return null;
|
||||
}
|
||||
return new Photo($this, $media, $protected);
|
||||
}
|
||||
if ($media['_'] == 'decryptedMessageMediaPhoto') {
|
||||
return new Photo($this, $media, $protected);
|
||||
}
|
||||
if ($media['_'] !== 'messageMediaDocument' && $media['_'] !== 'decryptedMessageMediaExternalDocument') {
|
||||
return null;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionFlushHisto
|
||||
use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionReadMessages;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionScreenshotMessages;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionSetMessageTTL;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionTyping;
|
||||
use danog\MadelineProto\EventHandler\Message\Service\SecretChat\SecretUserTyping;
|
||||
use danog\MadelineProto\EventHandler\Privacy;
|
||||
use danog\MadelineProto\EventHandler\Query\ChatButtonQuery;
|
||||
use danog\MadelineProto\EventHandler\Query\ChatGameQuery;
|
||||
@ -656,7 +656,7 @@ trait UpdateHandler
|
||||
$message,
|
||||
$info
|
||||
),
|
||||
'decryptedMessageActionTyping' => new ActionTyping(
|
||||
'decryptedMessageActionTyping' => new SecretUserTyping(
|
||||
$this,
|
||||
$message,
|
||||
$info,
|
||||
|
Loading…
Reference in New Issue
Block a user