From 62dfaa0abebb6a67a8ab32da3a7fa4b5e04d83af Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 30 Dec 2019 00:22:01 +0100 Subject: [PATCH] Add rename tests --- docs | 2 +- .../MadelineProto/MTProtoTools/Files.php | 21 ++++++++++++------- tests/testing.php | 4 +++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/docs b/docs index 7e995342..4ed3a844 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 7e995342fef7cb8f489d80983e9e7b34012b1a89 +Subproject commit 4ed3a8447cf21c69322bcdaf149eb3ce0befe8c0 diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 573e64ee..4d661ead 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -392,7 +392,7 @@ trait Files $chunk_size = $this->settings['upload']['part_size']; - $bridge = new class($size, $chunk_size) { + $bridge = new class($size, $chunk_size, $cb) { /** * Read promises. * @@ -417,20 +417,28 @@ trait Files * @var int */ private $offset = 0; + /** + * Callback + * + * @var ?callable + */ + private $cb; /** * Constructor. * * @param integer $size Total file size * @param integer $partSize Part size + * @param integer $cb Callback */ - public function __construct(int $size, int $partSize) + public function __construct(int $size, int $partSize, $cb) { for ($x = 0; $x < $size; $x += $partSize) { $this->read []= new Deferred; $this->write []= new Deferred; } $this->partSize = $partSize; + $this->cb = $cb; } /** * Read chunk. @@ -467,15 +475,14 @@ trait Files public function callback(): void { $this->read[$this->offset++]->resolve(); + if ($this->cb) { + Tools::callFork(($this->cb)()); + } } }; $reader = [$bridge, 'read']; $writer = [$bridge, 'write']; - - $cb = static function (...$params) use ($cb, $bridge): \Generator { - $bridge->callback(); - yield $cb(...$params); - }; + $cb = [$bridge, 'callback']; $read = $this->uploadFromCallable($reader, $size, $mime, '', $cb, true, $encrypted); $write = $this->downloadToCallable($media, $writer, null, true, 0, -1, $chunk_size); diff --git a/tests/testing.php b/tests/testing.php index 8fd2585a..43b066b1 100755 --- a/tests/testing.php +++ b/tests/testing.php @@ -273,7 +273,9 @@ var_dump(time()-$t); foreach ($media as $type => $inputMedia) { $MadelineProto->logger("Sending $type"); $type = yield $MadelineProto->messages->sendMedia(['peer' => $peer, 'media' => $inputMedia, 'message' => '['.$message.'](mention:'.$mention.')', 'parse_mode' => 'markdown']); - yield $MadelineProto->downloadToDir(yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]), '/tmp'); + yield $MadelineProto->downloadToDir($media = yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]), '/tmp'); + $inputMedia['file'] = $media; + yield $MadelineProto->messages->uploadMedia(['peer' => '@me', 'media' => $inputMedia]); } }