mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-22 19:11:16 +01:00
Remove isSupergroup and create isSupergroupOrChannel method
This commit is contained in:
parent
5aabfb0f9c
commit
85000058f2
@ -17,7 +17,6 @@
|
|||||||
namespace danog\MadelineProto\EventHandler;
|
namespace danog\MadelineProto\EventHandler;
|
||||||
|
|
||||||
use AssertionError;
|
use AssertionError;
|
||||||
use danog\MadelineProto\API;
|
|
||||||
use danog\MadelineProto\MTProto;
|
use danog\MadelineProto\MTProto;
|
||||||
use danog\MadelineProto\ParseMode;
|
use danog\MadelineProto\ParseMode;
|
||||||
|
|
||||||
@ -146,7 +145,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters
|
|||||||
return $this->replyCache;
|
return $this->replyCache;
|
||||||
}
|
}
|
||||||
$messages = $this->getClient()->methodCallAsyncRead(
|
$messages = $this->getClient()->methodCallAsyncRead(
|
||||||
API::isSupergroup($this->chatId) ? 'channels.getMessages' : 'messages.getMessages',
|
MTProto::isSupergroupOrChannel($this->chatId) ? 'channels.getMessages' : 'messages.getMessages',
|
||||||
[
|
[
|
||||||
'channel' => $this->chatId,
|
'channel' => $this->chatId,
|
||||||
'id' => [['_' => 'inputMessageReplyTo', 'id' => $this->id]]
|
'id' => [['_' => 'inputMessageReplyTo', 'id' => $this->id]]
|
||||||
@ -169,7 +168,7 @@ abstract class AbstractMessage extends Update implements SimpleFilters
|
|||||||
public function delete(bool $revoke = true): void
|
public function delete(bool $revoke = true): void
|
||||||
{
|
{
|
||||||
$this->getClient()->methodCallAsyncRead(
|
$this->getClient()->methodCallAsyncRead(
|
||||||
API::isSupergroup($this->chatId) ? 'channels.deleteMessages' : 'messages.deleteMessages',
|
MTProto::isSupergroupOrChannel($this->chatId) ? 'channels.deleteMessages' : 'messages.deleteMessages',
|
||||||
[
|
[
|
||||||
'channel' => $this->chatId,
|
'channel' => $this->chatId,
|
||||||
'id' => [$this->id],
|
'id' => [$this->id],
|
||||||
|
@ -53,7 +53,7 @@ abstract class AbstractFilterFromSenders extends Filter
|
|||||||
public function apply(Update $update): bool
|
public function apply(Update $update): bool
|
||||||
{
|
{
|
||||||
return $update instanceof GroupMessage && \in_array($update->senderId, $this->peersResolved, true);
|
return $update instanceof GroupMessage && \in_array($update->senderId, $this->peersResolved, true);
|
||||||
($update instanceof ButtonQuery && \in_array($update->userId, $this->peersResolved, true)) ||
|
($update instanceof ButtonQuery && \in_array($update->userId, $this->peersResolved, true)) ||
|
||||||
($update instanceof InlineQuery && \in_array($update->userId, $this->peersResolved, true));
|
($update instanceof InlineQuery && \in_array($update->userId, $this->peersResolved, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1249,9 +1249,9 @@ abstract class InternalDoc
|
|||||||
*
|
*
|
||||||
* @param int $id Bot API ID
|
* @param int $id Bot API ID
|
||||||
*/
|
*/
|
||||||
public static function isSupergroup(int $id): bool
|
public static function isSupergroupOrChannel(int $id): bool
|
||||||
{
|
{
|
||||||
return \danog\MadelineProto\MTProto::isSupergroup($id);
|
return \danog\MadelineProto\MTProto::isSupergroupOrChannel($id);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Whether we're currently connected to the test DCs.
|
* Whether we're currently connected to the test DCs.
|
||||||
|
@ -76,7 +76,7 @@ trait PeerHandler
|
|||||||
*
|
*
|
||||||
* @param int $id Bot API ID
|
* @param int $id Bot API ID
|
||||||
*/
|
*/
|
||||||
public static function isSupergroup(int $id): bool
|
public static function isSupergroupOrChannel(int $id): bool
|
||||||
{
|
{
|
||||||
return $id < Magic::ZERO_CHANNEL_ID;
|
return $id < Magic::ZERO_CHANNEL_ID;
|
||||||
}
|
}
|
||||||
@ -429,7 +429,7 @@ trait PeerHandler
|
|||||||
if (!$this->peerDatabase->isset($id)) {
|
if (!$this->peerDatabase->isset($id)) {
|
||||||
try {
|
try {
|
||||||
$this->logger->logger("Try fetching {$id} with access hash 0");
|
$this->logger->logger("Try fetching {$id} with access hash 0");
|
||||||
if ($this->isSupergroup($id)) {
|
if (self::isSupergroupOrChannel($id)) {
|
||||||
$this->peerDatabase->addChatBlocking($id);
|
$this->peerDatabase->addChatBlocking($id);
|
||||||
} elseif ($id < 0) {
|
} elseif ($id < 0) {
|
||||||
$this->methodCallAsyncRead('messages.getChats', ['id' => [-$id]]);
|
$this->methodCallAsyncRead('messages.getChats', ['id' => [-$id]]);
|
||||||
|
@ -659,7 +659,7 @@ trait UpdateHandler
|
|||||||
public function subscribeToUpdates(mixed $channel): bool
|
public function subscribeToUpdates(mixed $channel): bool
|
||||||
{
|
{
|
||||||
$channelId = $this->getInfo($channel, API::INFO_TYPE_ID);
|
$channelId = $this->getInfo($channel, API::INFO_TYPE_ID);
|
||||||
if (!MTProto::isSupergroup($channelId)) {
|
if (!MTProto::isSupergroupOrChannel($channelId)) {
|
||||||
throw new Exception("You can only subscribe to channels or supergroups!");
|
throw new Exception("You can only subscribe to channels or supergroups!");
|
||||||
}
|
}
|
||||||
$channelId = MTProto::fromSupergroup($channelId);
|
$channelId = MTProto::fromSupergroup($channelId);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user