Update file callback interfaces

This commit is contained in:
Daniil Gentili 2019-12-29 15:20:46 +01:00
parent 203d86cb28
commit 8ba10b047e
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
4 changed files with 9 additions and 7 deletions

2
docs

@ -1 +1 @@
Subproject commit 135f3110232f3a486b83438fdc0f15db165f7494
Subproject commit 4ed3a8447cf21c69322bcdaf149eb3ce0befe8c0

View File

@ -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) {
}
}

View File

@ -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);
}
}

View File

@ -23,5 +23,5 @@ interface FileCallbackInterface
{
public function getFile();
public function __invoke($percent);
public function __invoke($percent, $speed, $time);
}