mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-26 23:14:38 +01:00
Move all dialog ID-related methods to DialogId enum
This commit is contained in:
parent
472844bbff
commit
26823cc46d
@ -604,6 +604,7 @@ Want to add your own open-source project to this list? [Click here!](https://doc
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getParticipants.html" name="channels.getParticipants">Get the participants of a supergroup/channel: channels.getParticipants</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getcallbypeer" name="getCallByPeer">Get the phone call with the specified user ID: getCallByPeer</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getbroadcastprogress" name="getBroadcastProgress">Get the progress of a currently running broadcast: getBroadcastProgress</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#getdialogidtype" name="getDialogIdType">Get the type of a dialog using just its bot API ID: getDialogIdType</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/account.getTheme.html" name="account.getTheme">Get theme information: account.getTheme</a>
|
||||
* <a href="https://docs.madelineproto.xyz/API_docs/methods/channels.getForumTopics.html" name="channels.getForumTopics">Get topics of a forum: channels.getForumTopics</a>
|
||||
* <a href="https://docs.madelineproto.xyz/PHP/danog/MadelineProto/API.html#gettype" name="getType">Get type of peer: getType</a>
|
||||
|
@ -535,7 +535,7 @@ final class Blacklist {
|
||||
\fwrite($handle, "use Amp\\Cancellation;\n");
|
||||
\fwrite($handle, "use Amp\\Http\\Server\\Request as ServerRequest;\n");
|
||||
\fwrite($handle, "use danog\\MadelineProto\\Broadcast\\Action;\n");
|
||||
\fwrite($handle, "use danog\\MadelineProto\\MTProtoTools\\DialogIdType;\n");
|
||||
\fwrite($handle, "use danog\\MadelineProto\\MTProtoTools\\DialogId;\n");
|
||||
$had = [];
|
||||
foreach (ClassFinder::getClassesInNamespace(\danog\MadelineProto\EventHandler::class, ClassFinder::RECURSIVE_MODE) as $class) {
|
||||
$name = \basename(\str_replace('\\', '//', $class));
|
||||
|
@ -18,6 +18,7 @@ namespace danog\MadelineProto\EventHandler;
|
||||
|
||||
use AssertionError;
|
||||
use danog\MadelineProto\MTProto;
|
||||
use danog\MadelineProto\MTProtoTools\DialogId;
|
||||
use danog\MadelineProto\ParseMode;
|
||||
|
||||
/**
|
||||
@ -145,7 +146,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters
|
||||
return $this->replyCache;
|
||||
}
|
||||
$messages = $this->getClient()->methodCallAsyncRead(
|
||||
MTProto::isSupergroupOrChannel($this->chatId) ? 'channels.getMessages' : 'messages.getMessages',
|
||||
DialogId::getType($this->chatId) === DialogId::CHANNEL_OR_SUPERGROUP ? 'channels.getMessages' : 'messages.getMessages',
|
||||
[
|
||||
'channel' => $this->chatId,
|
||||
'id' => [['_' => 'inputMessageReplyTo', 'id' => $this->id]]
|
||||
@ -168,7 +169,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters
|
||||
public function delete(bool $revoke = true): void
|
||||
{
|
||||
$this->getClient()->methodCallAsyncRead(
|
||||
MTProto::isSupergroupOrChannel($this->chatId) ? 'channels.deleteMessages' : 'messages.deleteMessages',
|
||||
DialogId::getType($this->chatId) === DialogId::CHANNEL_OR_SUPERGROUP ? 'channels.deleteMessages' : 'messages.deleteMessages',
|
||||
[
|
||||
'channel' => $this->chatId,
|
||||
'id' => [$this->id],
|
||||
|
@ -32,6 +32,7 @@ use danog\MadelineProto\EventHandler\Media\Voice;
|
||||
use danog\MadelineProto\EventHandler\Message\Entities\MessageEntity;
|
||||
use danog\MadelineProto\EventHandler\Message\ReportReason;
|
||||
use danog\MadelineProto\MTProto;
|
||||
use danog\MadelineProto\MTProtoTools\DialogId;
|
||||
use danog\MadelineProto\ParseMode;
|
||||
use danog\MadelineProto\StrTools;
|
||||
|
||||
@ -392,7 +393,7 @@ abstract class Message extends AbstractMessage
|
||||
public function read(?int $maxId = null): bool
|
||||
{
|
||||
return $this->getClient()->methodCallAsyncRead(
|
||||
API::isSupergroupOrChannel($this->chatId) ? 'channels.readHistory':'messages.readHistory',
|
||||
DialogId::getType($this->chatId) === DialogId::CHANNEL_OR_SUPERGROUP ? 'channels.readHistory':'messages.readHistory',
|
||||
[
|
||||
'peer' => $this->chatId,
|
||||
'channel' => $this->chatId,
|
||||
|
@ -138,17 +138,6 @@ abstract class InternalDoc
|
||||
{
|
||||
return $this->wrapper->getAPI()->MTProtoToBotAPI($data);
|
||||
}
|
||||
/**
|
||||
* Convert MTProto secret chat ID to bot API secret chat ID.
|
||||
*
|
||||
* @param int $id MTProto secret chat ID
|
||||
*
|
||||
* @return int Bot API secret chat ID
|
||||
*/
|
||||
public static function MTProtoToBotAPISecretChatId(int $id): int
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::MTProtoToBotAPISecretChatId($id);
|
||||
}
|
||||
/**
|
||||
* MTProto to TD params.
|
||||
*
|
||||
@ -219,17 +208,6 @@ abstract class InternalDoc
|
||||
{
|
||||
return $this->wrapper->getAPI()->botAPIToMTProto($arguments);
|
||||
}
|
||||
/**
|
||||
* Convert bot API secret chat ID to MTProto secret chat ID.
|
||||
*
|
||||
* @param int $id Bot API secret chat ID
|
||||
*
|
||||
* @return int MTProto secret chat ID
|
||||
*/
|
||||
public static function botAPIToMTProtoSecretChatId(int $id): int
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::botAPIToMTProtoSecretChatId($id);
|
||||
}
|
||||
/**
|
||||
* Login as bot.
|
||||
*
|
||||
@ -618,15 +596,6 @@ abstract class InternalDoc
|
||||
{
|
||||
return \danog\MadelineProto\AsyncTools::flock($file, $operation, $polling, $token, $failureCb);
|
||||
}
|
||||
/**
|
||||
* Convert bot API channel ID to MTProto channel ID.
|
||||
*
|
||||
* @param int $id Bot API channel ID
|
||||
*/
|
||||
public static function fromSupergroup(int $id): int
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::fromSupergroup($id);
|
||||
}
|
||||
/**
|
||||
* When was full info for this chat last cached.
|
||||
*
|
||||
@ -758,17 +727,6 @@ abstract class InternalDoc
|
||||
{
|
||||
return $this->wrapper->getAPI()->getDhConfig();
|
||||
}
|
||||
/**
|
||||
* Get the type of a dialog using just its bot API ID.
|
||||
*
|
||||
* For more detailed types, use getType, instead.
|
||||
*
|
||||
* @param integer $id Bot API ID.
|
||||
*/
|
||||
public static function getDialogIdType(int $id): \danog\MadelineProto\MTProtoTools\DialogIdType
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::getDialogIdType($id);
|
||||
}
|
||||
/**
|
||||
* Get dialog IDs.
|
||||
*
|
||||
@ -1287,15 +1245,6 @@ abstract class InternalDoc
|
||||
{
|
||||
return $this->wrapper->getAPI()->isPremium();
|
||||
}
|
||||
/**
|
||||
* Check whether provided bot API ID is a secret chat.
|
||||
*
|
||||
* @param int $id Bot API ID
|
||||
*/
|
||||
public static function isSecretChat(int $id): bool
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::isSecretChat($id);
|
||||
}
|
||||
/**
|
||||
* Returns whether the current user is a bot.
|
||||
*/
|
||||
@ -1310,15 +1259,6 @@ abstract class InternalDoc
|
||||
{
|
||||
return $this->wrapper->getAPI()->isSelfUser();
|
||||
}
|
||||
/**
|
||||
* Check whether provided bot API ID is a channel or supergroup.
|
||||
*
|
||||
* @param int $id Bot API ID
|
||||
*/
|
||||
public static function isSupergroupOrChannel(int $id): bool
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::isSupergroupOrChannel($id);
|
||||
}
|
||||
/**
|
||||
* Whether we're currently connected to the test DCs.
|
||||
*
|
||||
@ -1906,15 +1846,6 @@ abstract class InternalDoc
|
||||
{
|
||||
return \danog\MadelineProto\StrTools::toSnakeCase($input);
|
||||
}
|
||||
/**
|
||||
* Convert MTProto channel ID to bot API channel ID.
|
||||
*
|
||||
* @param int $id MTProto channel ID
|
||||
*/
|
||||
public static function toSupergroup(int $id): int
|
||||
{
|
||||
return \danog\MadelineProto\MTProto::toSupergroup($id);
|
||||
}
|
||||
/**
|
||||
* Unpack binary double.
|
||||
*
|
||||
|
@ -25,6 +25,7 @@ use danog\MadelineProto\AsyncTools;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Loop\InternalLoop;
|
||||
use danog\MadelineProto\MTProto;
|
||||
use danog\MadelineProto\MTProtoTools\DialogId;
|
||||
use danog\MadelineProto\MTProtoTools\UpdatesState;
|
||||
|
||||
/**
|
||||
@ -232,7 +233,7 @@ final class FeedLoop extends Loop
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($channelId && !($this->API->peerIsset($this->API->toSupergroup($channelId)))) {
|
||||
if ($channelId && !($this->API->peerIsset(DialogId::toSupergroupOrChannel($channelId)))) {
|
||||
$this->API->logger->logger('Skipping update, I do not have the channel id '.$channelId, Logger::ERROR);
|
||||
return false;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ use danog\MadelineProto\Exception;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Loop\InternalLoop;
|
||||
use danog\MadelineProto\MTProto;
|
||||
use danog\MadelineProto\MTProtoTools\DialogId;
|
||||
use danog\MadelineProto\PeerNotInDbException;
|
||||
use danog\MadelineProto\PTSException;
|
||||
use danog\MadelineProto\RPCErrorException;
|
||||
@ -93,7 +94,7 @@ final class UpdateLoop extends Loop
|
||||
}
|
||||
$request_pts = $state->pts();
|
||||
try {
|
||||
$difference = $this->API->methodCallAsyncRead('updates.getChannelDifference', ['channel' => $this->API->toSupergroup($this->channelId), 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['FloodWaitLimit' => 86400]);
|
||||
$difference = $this->API->methodCallAsyncRead('updates.getChannelDifference', ['channel' => DialogId::toSupergroupOrChannel($this->channelId), 'filter' => ['_' => 'channelMessagesFilterEmpty'], 'pts' => $request_pts, 'limit' => $limit, 'force' => true], ['FloodWaitLimit' => 86400]);
|
||||
} catch (RPCErrorException $e) {
|
||||
if ($e->rpc === '-503') {
|
||||
delay(1.0);
|
||||
|
@ -1,14 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace danog\MadelineProto\MTProtoTools;
|
||||
|
||||
/**
|
||||
* Represents the type of a bot API dialog ID.
|
||||
*/
|
||||
enum DialogIdType
|
||||
{
|
||||
case USER;
|
||||
case CHAT;
|
||||
case CHANNEL_OR_SUPERGROUP;
|
||||
case SECRET_CHAT;
|
||||
}
|
@ -150,7 +150,7 @@ final class MinDatabase implements TLCallback
|
||||
$peers[$this->API->getIdInternal($location['from_id'])] = true;
|
||||
}
|
||||
if (isset($location['channel_id'])) {
|
||||
$peers[$this->API->toSupergroup($location['channel_id'])] = true;
|
||||
$peers[DialogId::toSupergroupOrChannel($location['channel_id'])] = true;
|
||||
}
|
||||
break;
|
||||
case 'messageActionChatCreate':
|
||||
|
@ -460,7 +460,7 @@ final class PeerDatabase implements TLCallback
|
||||
} else {
|
||||
$this->pendingDb[$chat] = [
|
||||
'_' => 'channel',
|
||||
'id' => MTProto::fromSupergroup($chat),
|
||||
'id' => DialogId::fromSupergroupOrChannel($chat),
|
||||
];
|
||||
$this->processChat($chat);
|
||||
}
|
||||
@ -528,7 +528,7 @@ final class PeerDatabase implements TLCallback
|
||||
if ($chat['_'] !== 'channel' && $chat['_'] !== 'channelForbidden') {
|
||||
throw new InvalidArgumentException('Invalid chat type '.$chat['_']);
|
||||
}
|
||||
$bot_api_id = MTProto::toSupergroup($chat['id']);
|
||||
$bot_api_id = DialogId::toSupergroupOrChannel($chat['id']);
|
||||
$existingChat = $this->db[$bot_api_id];
|
||||
if (!isset($chat['access_hash']) && !($chat['min'] ?? false)) {
|
||||
if (isset($existingChat['access_hash'])) {
|
||||
|
@ -26,8 +26,6 @@ use danog\Decoder\PhotoSizeSource\PhotoSizeSourceDialogPhoto;
|
||||
use danog\MadelineProto\API;
|
||||
use danog\MadelineProto\Exception;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Magic;
|
||||
use danog\MadelineProto\MTProto;
|
||||
use danog\MadelineProto\PeerNotInDbException;
|
||||
use danog\MadelineProto\RPCErrorException;
|
||||
use danog\MadelineProto\SecretPeerNotInDbException;
|
||||
@ -54,88 +52,6 @@ use function Amp\Future\await;
|
||||
*/
|
||||
trait PeerHandler
|
||||
{
|
||||
/**
|
||||
* Convert MTProto channel ID to bot API channel ID.
|
||||
*
|
||||
* @param int $id MTProto channel ID
|
||||
*/
|
||||
public static function toSupergroup(int $id): int
|
||||
{
|
||||
return Magic::ZERO_CHANNEL_ID - $id;
|
||||
}
|
||||
/**
|
||||
* Convert bot API channel ID to MTProto channel ID.
|
||||
*
|
||||
* @param int $id Bot API channel ID
|
||||
*/
|
||||
public static function fromSupergroup(int $id): int
|
||||
{
|
||||
return (-$id) + Magic::ZERO_CHANNEL_ID;
|
||||
}
|
||||
/**
|
||||
* Get the type of a dialog using just its bot API ID.
|
||||
*
|
||||
* For more detailed types, use getType, instead.
|
||||
*
|
||||
* @param integer $id Bot API ID.
|
||||
*/
|
||||
public static function getDialogIdType(int $id): DialogIdType
|
||||
{
|
||||
if ($id < 0) {
|
||||
if (-Magic::MAX_CHAT_ID <= $id) {
|
||||
return DialogIdType::CHAT;
|
||||
}
|
||||
if (Magic::ZERO_CHANNEL_ID - Magic::MAX_CHANNEL_ID <= $id && $id !== Magic::ZERO_CHANNEL_ID) {
|
||||
return DialogIdType::CHANNEL_OR_SUPERGROUP;
|
||||
}
|
||||
if (Magic::ZERO_SECRET_CHAT_ID + Magic::MIN_INT32 <= $id && $id !== Magic::ZERO_SECRET_CHAT_ID) {
|
||||
return DialogIdType::SECRET_CHAT;
|
||||
}
|
||||
} elseif (0 < $id && $id <= Magic::MAX_USER_ID) {
|
||||
return DialogIdType::USER;
|
||||
}
|
||||
throw new AssertionError("Invalid ID $id provided!");
|
||||
}
|
||||
/**
|
||||
* Check whether provided bot API ID is a channel or supergroup.
|
||||
*
|
||||
* @param int $id Bot API ID
|
||||
*/
|
||||
public static function isSupergroupOrChannel(int $id): bool
|
||||
{
|
||||
return self::getDialogIdType($id) === DialogIdType::CHANNEL_OR_SUPERGROUP;
|
||||
}
|
||||
/**
|
||||
* Convert MTProto secret chat ID to bot API secret chat ID.
|
||||
*
|
||||
* @param int $id MTProto secret chat ID
|
||||
*
|
||||
* @return int Bot API secret chat ID
|
||||
*/
|
||||
public static function MTProtoToBotApiSecretChatId(int $id): int
|
||||
{
|
||||
return Magic::ZERO_SECRET_CHAT_ID + $id;
|
||||
}
|
||||
/**
|
||||
* Convert bot API secret chat ID to MTProto secret chat ID.
|
||||
*
|
||||
* @param int $id Bot API secret chat ID
|
||||
*
|
||||
* @return int MTProto secret chat ID
|
||||
*/
|
||||
public static function botApiToMTProtoSecretChatId(int $id): int
|
||||
{
|
||||
return $id - Magic::ZERO_SECRET_CHAT_ID;
|
||||
}
|
||||
/**
|
||||
* Check whether provided bot API ID is a secret chat.
|
||||
*
|
||||
* @param int $id Bot API ID
|
||||
*/
|
||||
public static function isSecretChat(int $id): bool
|
||||
{
|
||||
return self::getDialogIdType($id) === DialogIdType::SECRET_CHAT;
|
||||
}
|
||||
/**
|
||||
* Set support info.
|
||||
*
|
||||
@ -221,7 +137,7 @@ trait PeerHandler
|
||||
if (isset($fwd['user_id']) && !($this->peerIsset($fwd['user_id']))) {
|
||||
return false;
|
||||
}
|
||||
if (isset($fwd['channel_id']) && !($this->peerIsset($this->toSupergroup($fwd['channel_id'])))) {
|
||||
if (isset($fwd['channel_id']) && !($this->peerIsset(DialogId::toSupergroupOrChannel($fwd['channel_id'])))) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
@ -288,7 +204,7 @@ trait PeerHandler
|
||||
case 'inputChannelFromMessage':
|
||||
case 'inputPeerChannelFromMessage':
|
||||
case 'updateChannelParticipant':
|
||||
return $this->toSupergroup($id['channel_id']);
|
||||
return DialogId::toSupergroupOrChannel($id['channel_id']);
|
||||
case 'inputUserSelf':
|
||||
case 'inputPeerSelf':
|
||||
return $this->authorization['user']['id'];
|
||||
@ -314,11 +230,11 @@ trait PeerHandler
|
||||
case 'channelForbidden':
|
||||
case 'channel':
|
||||
case 'channelFull':
|
||||
return $this->toSupergroup($id['id']);
|
||||
return DialogId::toSupergroupOrChannel($id['id']);
|
||||
case 'inputPeerChannel':
|
||||
case 'inputChannel':
|
||||
case 'peerChannel':
|
||||
return $this->toSupergroup($id['channel_id']);
|
||||
return DialogId::toSupergroupOrChannel($id['channel_id']);
|
||||
case 'message':
|
||||
case 'messageService':
|
||||
if (!isset($id['from_id']) // No other option
|
||||
@ -340,7 +256,7 @@ trait PeerHandler
|
||||
case 'updateDeleteChannelMessages':
|
||||
case 'updateChannelPinnedMessage':
|
||||
case 'updateChannelTooLong':
|
||||
return $this->toSupergroup($id['channel_id']);
|
||||
return DialogId::toSupergroupOrChannel($id['channel_id']);
|
||||
case 'updateChatParticipants':
|
||||
$id = $id['participants'];
|
||||
// no break
|
||||
@ -386,7 +302,7 @@ trait PeerHandler
|
||||
if (\is_string($id)) {
|
||||
if (\strpos($id, '#') !== false) {
|
||||
if (\preg_match('/^channel#(\\d*)/', $id, $matches)) {
|
||||
return $this->toSupergroup((int) $matches[1]);
|
||||
return DialogId::toSupergroupOrChannel((int) $matches[1]);
|
||||
}
|
||||
if (\preg_match('/^chat#(\\d*)/', $id, $matches)) {
|
||||
$id = '-'.$matches[1];
|
||||
@ -491,13 +407,13 @@ trait PeerHandler
|
||||
if (\is_numeric($id)) {
|
||||
$id = (int) $id;
|
||||
Assert::true($id !== 0, "An invalid ID was specified!");
|
||||
if (self::isSecretChat($id)) {
|
||||
return $this->getSecretChat(self::botApiToMTProtoSecretChatId($id));
|
||||
if (DialogId::getType($id) === DialogId::SECRET_CHAT) {
|
||||
return $this->getSecretChat(DialogId::toSecretChatId($id));
|
||||
}
|
||||
if (!$this->peerDatabase->isset($id)) {
|
||||
try {
|
||||
$this->logger->logger("Try fetching {$id} with access hash 0");
|
||||
if (self::isSupergroupOrChannel($id)) {
|
||||
if (DialogId::getType($id) === DialogId::CHANNEL_OR_SUPERGROUP) {
|
||||
$this->peerDatabase->addChatBlocking($id);
|
||||
} elseif ($id < 0) {
|
||||
$this->methodCallAsyncRead('messages.getChats', ['id' => [-$id]]);
|
||||
@ -622,7 +538,7 @@ trait PeerHandler
|
||||
return $constructor['id'];
|
||||
}
|
||||
if ($constructor['_'] === 'channel') {
|
||||
return $this->toSupergroup($constructor['id']);
|
||||
return DialogId::toSupergroupOrChannel($constructor['id']);
|
||||
}
|
||||
if ($constructor['_'] === 'chat' || $constructor['_'] === 'chatForbidden') {
|
||||
return -$constructor['id'];
|
||||
@ -689,7 +605,7 @@ trait PeerHandler
|
||||
$res['InputNotifyPeer'] = ['_' => 'inputNotifyPeer', 'peer' => $res['InputPeer']];
|
||||
$res['InputChannel'] = ['_' => 'inputChannel', 'channel_id' => $constructor['id'], 'access_hash' => $constructor['access_hash'], 'min' => $constructor['min'] ?? false];
|
||||
$res['channel_id'] = $constructor['id'];
|
||||
$res['bot_api_id'] = $this->toSupergroup($constructor['id']);
|
||||
$res['bot_api_id'] = DialogId::toSupergroupOrChannel($constructor['id']);
|
||||
$res['type'] = $constructor['megagroup'] ?? false ? 'supergroup' : 'channel';
|
||||
break;
|
||||
case 'channelForbidden':
|
||||
@ -747,12 +663,18 @@ trait PeerHandler
|
||||
}
|
||||
$id = $this->getIdInternal($id);
|
||||
Assert::notNull($id);
|
||||
if (self::isSupergroupOrChannel($id)) {
|
||||
$supergroups []= $id;
|
||||
} elseif ($id < 0) {
|
||||
$chats []= $id;
|
||||
} else {
|
||||
$users []= $id;
|
||||
switch (DialogId::getType($id)) {
|
||||
case DialogId::CHANNEL_OR_SUPERGROUP:
|
||||
$supergroups []= $id;
|
||||
break;
|
||||
case DialogId::CHAT:
|
||||
$chats []= $id;
|
||||
break;
|
||||
case DialogId::USER:
|
||||
$users []= $id;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Invalid ID $id!");
|
||||
}
|
||||
}
|
||||
if ($supergroups) {
|
||||
@ -783,7 +705,7 @@ trait PeerHandler
|
||||
public function getFullInfo(mixed $id): array
|
||||
{
|
||||
$partial = $this->getInfo($id);
|
||||
if (self::isSecretChat($partial['bot_api_id'])) {
|
||||
if (DialogId::getType($partial['bot_api_id']) === DialogId::SECRET_CHAT) {
|
||||
return $partial;
|
||||
}
|
||||
$full = $this->peerDatabase->getFull($partial['bot_api_id']);
|
||||
|
@ -308,7 +308,7 @@ final class ReferenceDatabase implements TLCallback
|
||||
break;
|
||||
case 'channelFull':
|
||||
case 'channel':
|
||||
$origin['peer'] = MTProto::toSupergroup($data['id']);
|
||||
$origin['peer'] = DialogId::toSupergroupOrChannel($data['id']);
|
||||
break;
|
||||
case 'document':
|
||||
foreach ($data['attributes'] as $attribute) {
|
||||
|
@ -70,7 +70,6 @@ use danog\MadelineProto\Lang;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\Loop\Update\FeedLoop;
|
||||
use danog\MadelineProto\Loop\Update\UpdateLoop;
|
||||
use danog\MadelineProto\MTProto;
|
||||
use danog\MadelineProto\ParseMode;
|
||||
use danog\MadelineProto\PeerNotInDbException;
|
||||
use danog\MadelineProto\ResponseException;
|
||||
@ -846,10 +845,10 @@ trait UpdateHandler
|
||||
public function subscribeToUpdates(mixed $channel): bool
|
||||
{
|
||||
$channelId = $this->getInfo($channel, API::INFO_TYPE_ID);
|
||||
if (!MTProto::isSupergroupOrChannel($channelId)) {
|
||||
if (DialogId::getType($channelId) !== DialogId::CHANNEL_OR_SUPERGROUP) {
|
||||
throw new Exception("You can only subscribe to channels or supergroups!");
|
||||
}
|
||||
$channelId = MTProto::fromSupergroup($channelId);
|
||||
$channelId = DialogId::fromSupergroupOrChannel($channelId);
|
||||
if (!$this->getChannelStates()->has($channelId)) {
|
||||
$this->loadChannelState($channelId, ['_' => 'updateChannelTooLong', 'pts' => 1]);
|
||||
$this->feeders[$channelId] ??= new FeedLoop($this, $channelId);
|
||||
|
@ -24,6 +24,7 @@ use danog\Decoder\FileId;
|
||||
use danog\MadelineProto\Lang;
|
||||
use danog\MadelineProto\Logger;
|
||||
use danog\MadelineProto\MTProto;
|
||||
use danog\MadelineProto\MTProtoTools\DialogId;
|
||||
use danog\MadelineProto\StrTools;
|
||||
use danog\MadelineProto\Tools;
|
||||
use Throwable;
|
||||
@ -207,7 +208,7 @@ trait BotAPI
|
||||
}
|
||||
if (isset($data['fwd_from']['channel_id'])) {
|
||||
try {
|
||||
$newd['forward_from_chat'] = $this->getPwrChat(MTProto::toSupergroup($data['fwd_from']['channel_id']), false);
|
||||
$newd['forward_from_chat'] = $this->getPwrChat(DialogId::toSupergroupOrChannel($data['fwd_from']['channel_id']), false);
|
||||
} catch (Throwable $e) {
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ use danog\Decoder\PhotoSizeSource\PhotoSizeSourceStickersetThumbnail;
|
||||
use danog\Decoder\PhotoSizeSource\PhotoSizeSourceThumbnail;
|
||||
use danog\MadelineProto\API;
|
||||
use danog\MadelineProto\Lang;
|
||||
use danog\MadelineProto\MTProtoTools\DialogId;
|
||||
|
||||
use const danog\Decoder\ANIMATION;
|
||||
use const danog\Decoder\AUDIO;
|
||||
@ -105,7 +106,7 @@ trait BotAPIFiles
|
||||
if ($photoSize->getDialogId() < 0) {
|
||||
$res['Chat'] = [
|
||||
'_' => $photoSize->getDialogId() < -1000000000000 ? 'channel' : 'chat',
|
||||
'id' => $photoSize->getDialogId() < -1000000000000 ? API::fromSupergroup($photoSize->getDialogId()) : -$photoSize->getDialogId(),
|
||||
'id' => $photoSize->getDialogId() < -1000000000000 ? DialogId::fromSupergroupOrChannel($photoSize->getDialogId()) : -$photoSize->getDialogId(),
|
||||
'access_hash' => $photoSize->getDialogAccessHash(),
|
||||
'photo' => [
|
||||
'_' => 'chatPhoto',
|
||||
|
Loading…
Reference in New Issue
Block a user