diff --git a/src/Broadcast/Broadcast.php b/src/Broadcast/Broadcast.php index a50045f96..bfffa93ef 100644 --- a/src/Broadcast/Broadcast.php +++ b/src/Broadcast/Broadcast.php @@ -20,7 +20,6 @@ declare(strict_types=1); namespace danog\MadelineProto\Broadcast; -use Amp\Cancellation; use danog\MadelineProto\Broadcast\Action\ActionForward; use danog\MadelineProto\Broadcast\Action\ActionSend; use Webmozart\Assert\Assert; @@ -54,9 +53,8 @@ trait Broadcast * @param array $messages The messages to send: an array of arrays, containing parameters to pass to messages.sendMessage. * @param bool $pin Whether to also pin the last sent message. * @param float|null $delay Number of seconds to wait between each peer. - * @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable. */ - public function broadcastMessages(array $messages, ?Filter $filter = null, bool $pin = false, ?float $delay = null, ?Cancellation $cancellation = null): int + public function broadcastMessages(array $messages, ?Filter $filter = null, bool $pin = false, ?float $delay = null): int { foreach ($messages as &$message) { if (isset($message['media']['_']) && @@ -69,11 +67,11 @@ trait Broadcast ) { $message['media'] = $this->methodCallAsyncRead( 'messages.uploadMedia', - ['peer' => 'me', 'media' => $message['media'], 'cancellation' => $cancellation] + ['peer' => 'me', 'media' => $message['media']] ); } } unset($message); - return $this->broadcastCustom(new ActionSend($this, $messages, $pin), $filter, $delay, $cancellation); + return $this->broadcastCustom(new ActionSend($this, $messages, $pin), $filter, $delay); } /** * Forwards a list of messages to all peers (users, chats, channels) of the bot. @@ -92,11 +90,10 @@ trait Broadcast * @param bool $drop_author If true, will forward messages without quoting the original author. * @param bool $pin Whether to also pin the last sent message. * @param float|null $delay Number of seconds to wait between each peer. - * @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable. */ - public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?Filter $filter = null, bool $pin = false, ?float $delay = null, ?Cancellation $cancellation = null): int + public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?Filter $filter = null, bool $pin = false, ?float $delay = null): int { - return $this->broadcastCustom(new ActionForward($this, $this->getID($from_peer), $message_ids, $drop_author, $pin), $filter, $delay, $cancellation); + return $this->broadcastCustom(new ActionForward($this, $this->getID($from_peer), $message_ids, $drop_author, $pin), $filter, $delay); } /** @@ -113,16 +110,14 @@ trait Broadcast * * @param Action $action A custom, serializable Action class that will be called once for every peer. * @param float|null $delay Number of seconds to wait between each peer. - * @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable. */ - public function broadcastCustom(Action $action, ?Filter $filter = null, ?float $delay = null, ?Cancellation $cancellation = null): int + public function broadcastCustom(Action $action, ?Filter $filter = null, ?float $delay = null): int { // Ensure it can be serialized Assert::eq(unserialize(serialize($action))::class, $action::class); $id = $this->broadcastId--; $this->broadcasts[$id] = new InternalState($id, $this, $action, $filter ?? Filter::default(), $delay); - $cancellation?->subscribe(fn () => $this->cancelBroadcast($id)); return $id; } /** diff --git a/src/InternalDoc.php b/src/InternalDoc.php index 9ecb200ab..ff19fedb0 100644 --- a/src/InternalDoc.php +++ b/src/InternalDoc.php @@ -250,11 +250,10 @@ abstract class InternalDoc * * @param Action $action A custom, serializable Action class that will be called once for every peer. * @param float|null $delay Number of seconds to wait between each peer. - * @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable. */ - final public function broadcastCustom(\danog\MadelineProto\Broadcast\Action $action, ?\danog\MadelineProto\Broadcast\Filter $filter = null, ?float $delay = null, ?\Amp\Cancellation $cancellation = null): int + final public function broadcastCustom(\danog\MadelineProto\Broadcast\Action $action, ?\danog\MadelineProto\Broadcast\Filter $filter = null, ?float $delay = null): int { - return $this->wrapper->getAPI()->broadcastCustom($action, $filter, $delay, $cancellation); + return $this->wrapper->getAPI()->broadcastCustom($action, $filter, $delay); } /** * Forwards a list of messages to all peers (users, chats, channels) of the bot. @@ -273,11 +272,10 @@ abstract class InternalDoc * @param bool $drop_author If true, will forward messages without quoting the original author. * @param bool $pin Whether to also pin the last sent message. * @param float|null $delay Number of seconds to wait between each peer. - * @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable. */ - final public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null, ?\Amp\Cancellation $cancellation = null): int + final public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null): int { - return $this->wrapper->getAPI()->broadcastForwardMessages($from_peer, $message_ids, $drop_author, $filter, $pin, $delay, $cancellation); + return $this->wrapper->getAPI()->broadcastForwardMessages($from_peer, $message_ids, $drop_author, $filter, $pin, $delay); } /** * Sends a list of messages to all peers (users, chats, channels) of the bot. @@ -296,11 +294,10 @@ abstract class InternalDoc * @param array $messages The messages to send: an array of arrays, containing parameters to pass to messages.sendMessage. * @param bool $pin Whether to also pin the last sent message. * @param float|null $delay Number of seconds to wait between each peer. - * @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable. */ - final public function broadcastMessages(array $messages, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null, ?\Amp\Cancellation $cancellation = null): int + final public function broadcastMessages(array $messages, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null): int { - return $this->wrapper->getAPI()->broadcastMessages($messages, $filter, $pin, $delay, $cancellation); + return $this->wrapper->getAPI()->broadcastMessages($messages, $filter, $pin, $delay); } /** * Fork a new green thread and execute the passed function in the background.