1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-12-12 12:07:21 +01:00

More fixes and works on Media classes!

This commit is contained in:
Mahdi 2023-09-07 00:30:41 +03:30
parent 0799a8a52f
commit fcb5c8ba95
8 changed files with 43 additions and 45 deletions

View File

@ -27,12 +27,12 @@ use danog\MadelineProto\TL\Types\Bytes;
final class Document extends Media final class Document extends Media
{ {
/** Content of thumbnail file (JPEGfile, quality 55, set in a square 90x90) only for secret chats. */ /** 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. */ /** Thumbnail height only for secret chats. */
public readonly int $thumbHeight; public readonly ?int $thumbHeight;
/** Thumbnail width only for secret chats. */ /** Thumbnail width only for secret chats. */
public readonly int $thumbWidth; public readonly ?int $thumbWidth;
/** Caption only for secret chats. */ /** Caption. */
public readonly ?string $caption; public readonly ?string $caption;
/** @internal */ /** @internal */
@ -42,7 +42,7 @@ final class Document extends Media
bool $protected bool $protected
) { ) {
parent::__construct($API, $rawMedia, $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->thumbHeight = $rawMedia['thumb_h'] ?? null;
$this->thumbWidth = $rawMedia['thumb_w'] ?? null; $this->thumbWidth = $rawMedia['thumb_w'] ?? null;
$this->caption = $rawMedia['caption'] ?? null; $this->caption = $rawMedia['caption'] ?? null;

View File

@ -27,13 +27,13 @@ use danog\MadelineProto\TL\Types\Bytes;
final class Photo extends Media final class Photo extends Media
{ {
/** If true; the current media has attached mask stickers. */ /** 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. */ /** 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. */ /** Thumbnail height only for secret chats. */
public readonly int $thumbHeight; public readonly ?int $thumbHeight;
/** Thumbnail width only for secret chats. */ /** Thumbnail width only for secret chats. */
public readonly int $thumbWidth; public readonly ?int $thumbWidth;
/** @internal */ /** @internal */
public function __construct( public function __construct(
@ -42,19 +42,9 @@ final class Photo extends Media
bool $protected, bool $protected,
) { ) {
parent::__construct($API, $rawMedia, $protected); parent::__construct($API, $rawMedia, $protected);
$this->hasStickers = $rawMedia['photo']['has_stickers'] ?? null; $this->hasStickers = $rawMedia['photo']['has_stickers'] ?? false;
$this->thumb = (string) $rawMedia['thumb'] ?? null; $this->thumb = new Bytes($rawMedia['thumb']) ?? null;
$this->thumbHeight = $rawMedia['thumb_h'] ?? null; $this->thumbHeight = $rawMedia['thumb_h'] ?? null;
$this->thumbWidth = $rawMedia['thumb_w'] ?? 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;
}
} }

View File

@ -27,11 +27,11 @@ final class Video extends AbstractVideo
/** If true; the current media has attached mask stickers. */ /** 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. */ /** 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. */ /** Thumbnail height only for secret chats. */
public readonly int $thumbHeight; public readonly ?int $thumbHeight;
/** Thumbnail width only for secret chats. */ /** Thumbnail width only for secret chats. */
public readonly int $thumbWidth; public readonly ?int $thumbWidth;
/** @internal */ /** @internal */
public function __construct( public function __construct(
@ -49,18 +49,8 @@ final class Video extends AbstractVideo
} }
} }
$this->hasStickers = $hasStickers; $this->hasStickers = $hasStickers;
$this->thumb = (string) $rawMedia['thumb'] ?? null; $this->thumb = new Bytes($rawMedia['thumb']) ?? null;
$this->thumbHeight = $rawMedia['thumb_h'] ?? null; $this->thumbHeight = $rawMedia['thumb_h'] ?? null;
$this->thumbWidth = $rawMedia['thumb_w'] ?? 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;
}
} }

View File

@ -118,7 +118,7 @@ abstract class Message extends AbstractMessage
$this->entities = MessageEntity::fromRawEntities($rawMessage['entities'] ?? []); $this->entities = MessageEntity::fromRawEntities($rawMessage['entities'] ?? []);
$this->message = $rawMessage['message']; $this->message = $rawMessage['message'];
$this->fromScheduled = $rawMessage['from_scheduled']; $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->editDate = $rawMessage['edit_date'] ?? null;
$this->keyboard = isset($rawMessage['reply_markup']) $this->keyboard = isset($rawMessage['reply_markup'])

View File

@ -16,6 +16,8 @@
namespace danog\MadelineProto\EventHandler\Message; namespace danog\MadelineProto\EventHandler\Message;
use AssertionError;
use danog\MadelineProto\EventHandler\AbstractMessage;
use danog\MadelineProto\EventHandler\AbstractPrivateMessage; use danog\MadelineProto\EventHandler\AbstractPrivateMessage;
use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto;
@ -28,14 +30,27 @@ class SecretMessage extends AbstractPrivateMessage
public readonly ?bool $noWebpage; public readonly ?bool $noWebpage;
/** Random message ID of the message this message replies to (parameter added in layer 45) */ /** Random message ID of the message this message replies to (parameter added in layer 45) */
public readonly ?int $replyToRandomId; 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 */ /** @internal */
public function __construct(MTProto $API, array $rawMessage, array $info) public function __construct(MTProto $API, array $rawMessage, array $info)
{ {
parent::__construct($API, $decryptedMessage = $rawMessage['decrypted_message'], $info); parent::__construct($API, $decryptedMessage = $rawMessage['decrypted_message'], $info);
$this->noWebpage = $decryptedMessage['no_webpage'] ?? null; $this->noWebpage = $decryptedMessage['no_webpage'] ?? null;
$this->replyToRandomId = $decryptedMessage['reply_to_random_id'] ?? 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;
}
}*/
} }

View File

@ -17,13 +17,13 @@
namespace danog\MadelineProto\EventHandler\Message\Service\SecretChat; namespace danog\MadelineProto\EventHandler\Message\Service\SecretChat;
use danog\MadelineProto\EventHandler\Action; use danog\MadelineProto\EventHandler\Action;
use danog\MadelineProto\EventHandler\Message\ServiceMessage; use danog\MadelineProto\EventHandler\Typing;
use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto;
/** /**
* User is preparing a message: typing, recording, uploading, etc. * User is preparing a message: typing, recording, uploading, etc.
*/ */
class ActionTyping extends ServiceMessage class SecretUserTyping extends Typing
{ {
public function __construct( public function __construct(
MTProto $API, MTProto $API,
@ -33,6 +33,6 @@ class ActionTyping extends ServiceMessage
/** Type of action */ /** Type of action */
public readonly Action $action public readonly Action $action
) { ) {
parent::__construct($API, $rawMessage, $info); parent::__construct($API, $rawMessage);
} }
} }

View File

@ -58,12 +58,15 @@ trait FilesAbstraction
*/ */
public function wrapMedia(array $media, bool $protected = false): ?Media public function wrapMedia(array $media, bool $protected = false): ?Media
{ {
if ($media['_'] === 'messageMediaPhoto' || $media['_'] == 'decryptedMessageMediaPhoto') { if ($media['_'] === 'messageMediaPhoto') {
if (!isset($media['photo'])) { if (!isset($media['photo'])) {
return null; return null;
} }
return new Photo($this, $media, $protected); return new Photo($this, $media, $protected);
} }
if ($media['_'] == 'decryptedMessageMediaPhoto') {
return new Photo($this, $media, $protected);
}
if ($media['_'] !== 'messageMediaDocument' && $media['_'] !== 'decryptedMessageMediaExternalDocument') { if ($media['_'] !== 'messageMediaDocument' && $media['_'] !== 'decryptedMessageMediaExternalDocument') {
return null; return null;
} }

View File

@ -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\ActionReadMessages;
use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionScreenshotMessages; use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionScreenshotMessages;
use danog\MadelineProto\EventHandler\Message\Service\SecretChat\ActionSetMessageTTL; 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\Privacy;
use danog\MadelineProto\EventHandler\Query\ChatButtonQuery; use danog\MadelineProto\EventHandler\Query\ChatButtonQuery;
use danog\MadelineProto\EventHandler\Query\ChatGameQuery; use danog\MadelineProto\EventHandler\Query\ChatGameQuery;
@ -656,7 +656,7 @@ trait UpdateHandler
$message, $message,
$info $info
), ),
'decryptedMessageActionTyping' => new ActionTyping( 'decryptedMessageActionTyping' => new SecretUserTyping(
$this, $this,
$message, $message,
$info, $info,