From 8ba10b047efb67611bed68ebe028d3ac12d5fb57 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 29 Dec 2019 15:20:46 +0100 Subject: [PATCH] Update file callback interfaces --- docs | 2 +- examples/downloadRenameBot.php | 8 +++++--- src/danog/MadelineProto/FileCallback.php | 4 ++-- src/danog/MadelineProto/FileCallbackInterface.php | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs b/docs index 135f3110..4ed3a844 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 135f3110232f3a486b83438fdc0f15db165f7494 +Subproject commit 4ed3a8447cf21c69322bcdaf149eb3ce0befe8c0 diff --git a/examples/downloadRenameBot.php b/examples/downloadRenameBot.php index 83c0f7e9..b9ca8fe1 100644 --- a/examples/downloadRenameBot.php +++ b/examples/downloadRenameBot.php @@ -104,15 +104,17 @@ class EventHandler extends \danog\MadelineProto\EventHandler $id = yield $this->messages->sendMessage(['peer' => $peerId, 'message' => 'Preparing...', 'reply_to_msg_id' => $messageId])['id']; $url = new \danog\MadelineProto\FileCallback( $url, - function ($progress) use ($peerId, $id) { - static $prev = 0; + function ($progress, $speed, $time) use ($peerId, $id) { + $this->logger("Upload progress: $progress%"); + + static $prev = -1; $progressR = (int) ($progress / 10); if ($progressR === $prev) { return; } $prev = $progressR; try { - yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => 'Upload progress: '.$progress.'%']); + yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => "Upload progress: $progress%\nSpeed: $speed mbps\nTime elapsed since start: $time"]); } catch (\danog\MadelineProto\RPCErrorException $e) { } } diff --git a/src/danog/MadelineProto/FileCallback.php b/src/danog/MadelineProto/FileCallback.php index 24202e29..e1d0902d 100644 --- a/src/danog/MadelineProto/FileCallback.php +++ b/src/danog/MadelineProto/FileCallback.php @@ -35,10 +35,10 @@ class FileCallback implements FileCallbackInterface return $this->file; } - public function __invoke($percent) + public function __invoke($percent, $speed, $time) { $callback = $this->callback; - return $callback($percent); + return $callback($percent, $speed, $time); } } diff --git a/src/danog/MadelineProto/FileCallbackInterface.php b/src/danog/MadelineProto/FileCallbackInterface.php index 55dacec9..0192041c 100644 --- a/src/danog/MadelineProto/FileCallbackInterface.php +++ b/src/danog/MadelineProto/FileCallbackInterface.php @@ -23,5 +23,5 @@ interface FileCallbackInterface { public function getFile(); - public function __invoke($percent); + public function __invoke($percent, $speed, $time); }