1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 16:51:16 +01:00

Add some fixes and stuff

- Force getSecretMessage method to return SecretMessage
- Implement last Todo (getReply method inside SecretMessage class)
- Add private file field into media class for supporting download medias from secret chats
- Run composer cs-fix
This commit is contained in:
Mahdi 2023-09-25 13:39:00 +03:30
parent 284f4e8554
commit e0129cd407
13 changed files with 34 additions and 8 deletions

View File

@ -80,7 +80,9 @@ abstract class AbstractMessage extends Update implements SimpleFilters
$this->mentioned = $rawMessage['mentioned'] ?? false;
$this->silent = $rawMessage['silent'] ?? $decryptedMessage['silent'];
$this->ttlPeriod = $rawMessage['ttl_period'] ?? $decryptedMessage['ttl'] ?? null;
if ($this instanceof SecretMessage && isset($decryptedMessage['reply_to_random_id'])) {
$this->replyToMsgId = $decryptedMessage['reply_to_random_id'];
}
if (isset($rawMessage['reply_to']) && $rawMessage['reply_to']['_'] === 'messageReplyHeader') {
$replyTo = $rawMessage['reply_to'];
$this->replyToScheduled = $replyTo['reply_to_scheduled'];

View File

@ -61,6 +61,8 @@ abstract class Media extends IpcCapable implements JsonSerializable
/** @internal Media location */
public readonly array $location;
/** Encrypted file (only for secret chats). */
private readonly ?array $file;
/** @internal */
public function __construct(
@ -88,6 +90,7 @@ abstract class Media extends IpcCapable implements JsonSerializable
$this->creationDate = ($rawMedia['document'] ?? $rawMedia['photo'])['date'];
$this->ttl = $rawMedia['ttl_seconds'] ?? null;
$this->spoiler = $rawMedia['spoiler'] ?? false;
$this->file = $rawMedia['file'];
}
/**

View File

@ -116,7 +116,7 @@ abstract class Message extends AbstractMessage
$this->forwards = $rawMessage['forwards'] ?? null;
$this->signature = $rawMessage['post_author'] ?? null;
$this->entities = MessageEntity::fromRawEntities($rawMessage['entities'] ?? []);
$this->entities = MessageEntity::fromRawEntities($rawMessage['entities'] ?? $decryptedMessage['entities']?? []);
$this->message = $rawMessage['message'] ?? $decryptedMessage['message'];
$this->fromScheduled = $rawMessage['from_scheduled'] ?? false;
$this->viaBotId = $rawMessage['via_bot_id'] ?? $this->getClient()->getIdInternal($rawMessage['via_bot_name']) ?? null;
@ -150,6 +150,7 @@ abstract class Message extends AbstractMessage
$this->protected = $this instanceof SecretMessage ? true : $rawMessage['noforwards'];
$media = $rawMessage['media'] ?? $decryptedMessage['media'] ?? null;
$media['file'] = $rawMessage['file'] ?? null;
$this->media = isset($media)
? $API->wrapMedia($media, $this->protected)
: null;

View File

@ -38,8 +38,7 @@ class SecretMessage extends AbstractPrivateMessage
$this->noWebpage = $decryptedMessage['no_webpage'] ?? null;
$this->replyToRandomId = $decryptedMessage['reply_to_random_id'] ?? null;
}
//TODO implement it using getSecretChat
/*public function getReply(string $class = AbstractMessage::class) : ?AbstractMessage
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.");
@ -53,5 +52,16 @@ class SecretMessage extends AbstractPrivateMessage
}
return $this->replyCache;
}
}*/
$message = $this->getClient()->getSecretMessage(
chatId: $this->chatId,
randomId: $this->id
);
/** @psalm-suppress InaccessibleProperty */
$this->replyCache = $message;
$this->replyCached = true;
if (!$this->replyCache instanceof $class) {
return null;
}
return $this->replyCache;
}
}

View File

@ -24,6 +24,7 @@ use danog\MadelineProto\MTProto;
*/
class ActionDeleteMessages extends ServiceMessage
{
/** @internal */
public function __construct(
MTProto $API,
array $rawMessage,

View File

@ -24,6 +24,7 @@ use danog\MadelineProto\MTProto;
*/
class ActionFlushHistory extends ServiceMessage
{
/** @internal */
public function __construct(MTProto $API, array $rawMessage, array $info)
{
parent::__construct($API, $rawMessage, $info);

View File

@ -24,6 +24,7 @@ use danog\MadelineProto\MTProto;
*/
class ActionReadMessages extends ServiceMessage
{
/** @internal */
public function __construct(
MTProto $API,
array $rawMessage,

View File

@ -24,6 +24,7 @@ use danog\MadelineProto\MTProto;
*/
class ActionScreenshotMessages extends ServiceMessage
{
/** @internal */
public function __construct(
MTProto $API,
array $rawMessage,

View File

@ -27,6 +27,7 @@ use danog\MadelineProto\MTProto;
*/
class ActionSetMessageTTL extends ServiceMessage
{
/** @internal */
public function __construct(
MTProto $API,
array $rawMessage,

View File

@ -25,6 +25,7 @@ use danog\MadelineProto\MTProto;
*/
class SecretUserTyping extends Typing
{
/** @internal */
public function __construct(
MTProto $API,
array $rawMessage,

View File

@ -35,6 +35,7 @@ use danog\MadelineProto\EventHandler\Message\Entities\Phone;
use danog\MadelineProto\EventHandler\Message\Entities\Pre;
use danog\MadelineProto\EventHandler\Message\Entities\Spoiler;
use danog\MadelineProto\EventHandler\Message\Entities\Url;
use danog\MadelineProto\EventHandler\Message\SecretMessage;
use danog\MadelineProto\EventHandler\Participant\Admin;
use danog\MadelineProto\EventHandler\Participant\Member;
use danog\MadelineProto\EventHandler\Update;
@ -1027,7 +1028,7 @@ abstract class InternalDoc
* @param integer $chatId Secret chat ID.
* @param integer $randomId Secret chat message ID.
*/
public function getSecretMessage(int $chatId, int $randomId): array
public function getSecretMessage(int $chatId, int $randomId): SecretMessage
{
return $this->wrapper->getAPI()->getSecretMessage($chatId, $randomId);
}

View File

@ -33,6 +33,7 @@ use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\EventHandler\Message\ChannelMessage;
use danog\MadelineProto\EventHandler\Message\GroupMessage;
use danog\MadelineProto\EventHandler\Message\PrivateMessage;
use danog\MadelineProto\EventHandler\Message\SecretMessage;
use danog\MadelineProto\EventHandler\Message\Service\DialogChannelCreated;
use danog\MadelineProto\EventHandler\Message\Service\DialogChannelMigrateFrom;
use danog\MadelineProto\EventHandler\Message\Service\DialogChatJoinedByLink;
@ -669,6 +670,7 @@ trait UpdateHandler
return null;
}
return match ($info['type']) {
API::PEER_TYPE_USER && $message['_'] === 'encryptedMessage' => new SecretMessage($this, $message, $info),
API::PEER_TYPE_BOT, API::PEER_TYPE_USER => new PrivateMessage($this, $message, $info),
API::PEER_TYPE_GROUP, API::PEER_TYPE_SUPERGROUP => new GroupMessage($this, $message, $info),
API::PEER_TYPE_CHANNEL => new ChannelMessage($this, $message, $info),

View File

@ -21,6 +21,7 @@ declare(strict_types=1);
namespace danog\MadelineProto\SecretChats;
use AssertionError;
use danog\MadelineProto\EventHandler\Message\SecretMessage;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Loop\Update\UpdateLoop;
use danog\MadelineProto\MTProtoTools\Crypt;
@ -157,9 +158,9 @@ trait AuthKeyHandler
* @param integer $chatId Secret chat ID.
* @param integer $randomId Secret chat message ID.
*/
public function getSecretMessage(int $chatId, int $randomId): array
public function getSecretMessage(int $chatId, int $randomId): SecretMessage
{
return $this->getSecretChatController($chatId)->getMessage($randomId);
return $this->wrapMessage($this->getSecretChatController($chatId)->getMessage($randomId)['message']);
}
/**