From e85fef23a575c99ea014f9c980194eca49c1df52 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 12 Sep 2020 20:01:34 +0200 Subject: [PATCH] Yield from reference database --- docs | 2 +- src/danog/MadelineProto/MTProtoTools/Files.php | 14 +++++++------- .../MTProtoTools/ReferenceDatabase.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs b/docs index b8ee95c1..57562236 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit b8ee95c1435bbd74ddd4783a34e9e90cbfb38999 +Subproject commit 57562236aade5d13a01c18a2290aa647686eebd5 diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index fd176839..1921e84b 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -554,7 +554,7 @@ trait Files throw new \danog\MadelineProto\Exception('No access hash'); } $res['Photo'] = $media['photo']; - $res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['photo']['id'], 'access_hash' => $media['photo']['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media['photo'])]; + $res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['photo']['id'], 'access_hash' => $media['photo']['access_hash'], 'file_reference' => yield from $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media['photo'])]; $res['InputMedia'] = ['_' => 'inputMediaPhoto', 'id' => $res['InputPhoto']]; if (isset($media['ttl_seconds'])) { $res['InputMedia']['ttl_seconds'] = $media['ttl_seconds']; @@ -565,7 +565,7 @@ trait Files throw new \danog\MadelineProto\Exception('No access hash'); } $res['Document'] = $media['document']; - $res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['document']['id'], 'access_hash' => $media['document']['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media['document'])]; + $res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['document']['id'], 'access_hash' => $media['document']['access_hash'], 'file_reference' => yield from $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media['document'])]; $res['InputMedia'] = ['_' => 'inputMediaDocument', 'id' => $res['InputDocument']]; if (isset($media['ttl_seconds'])) { $res['InputMedia']['ttl_seconds'] = $media['ttl_seconds']; @@ -581,7 +581,7 @@ trait Files if (!isset($media['access_hash'])) { throw new \danog\MadelineProto\Exception('No access hash'); } - $res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media)]; + $res['InputDocument'] = ['_' => 'inputDocument', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => yield from $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $media)]; $res['InputMedia'] = ['_' => 'inputMediaDocument', 'id' => $res['InputDocument']]; $res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $media]; break; @@ -589,7 +589,7 @@ trait Files if (!isset($media['access_hash'])) { throw new \danog\MadelineProto\Exception('No access hash'); } - $res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media)]; + $res['InputPhoto'] = ['_' => 'inputPhoto', 'id' => $media['id'], 'access_hash' => $media['access_hash'], 'file_reference' => yield from $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $media)]; $res['InputMedia'] = ['_' => 'inputMediaPhoto', 'id' => $res['InputPhoto']]; $res['MessageMedia'] = ['_' => 'messageMediaPhoto', 'photo' => $media]; break; @@ -790,7 +790,7 @@ trait Files $messageMedia = $messageMedia['photo']; $size = \end($messageMedia['sizes']); $res = \array_merge($res, yield from $this->getDownloadInfo($size)); - $res['InputFileLocation'] = ['_' => 'inputPhotoFileLocation', 'thumb_size' => $res['thumb_size'] ?? 'x', 'dc_id' => $messageMedia['dc_id'], 'access_hash' => $messageMedia['access_hash'], 'id' => $messageMedia['id'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $messageMedia)]; + $res['InputFileLocation'] = ['_' => 'inputPhotoFileLocation', 'thumb_size' => $res['thumb_size'] ?? 'x', 'dc_id' => $messageMedia['dc_id'], 'access_hash' => $messageMedia['access_hash'], 'id' => $messageMedia['id'], 'file_reference' => yield from $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION, $messageMedia)]; return $res; case 'user': case 'folder': @@ -844,7 +844,7 @@ trait Files throw new \danog\MadelineProto\Exception('File location unavailable'); case 'fileLocation': $res['name'] = Tools::unpackSignedLongString($messageMedia['volume_id']).'_'.$messageMedia['local_id']; - $res['InputFileLocation'] = ['_' => 'inputFileLocation', 'volume_id' => $messageMedia['volume_id'], 'local_id' => $messageMedia['local_id'], 'secret' => $messageMedia['secret'], 'dc_id' => $messageMedia['dc_id'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION_LOCATION, $messageMedia)]; + $res['InputFileLocation'] = ['_' => 'inputFileLocation', 'volume_id' => $messageMedia['volume_id'], 'local_id' => $messageMedia['local_id'], 'secret' => $messageMedia['secret'], 'dc_id' => $messageMedia['dc_id'], 'file_reference' => yield from $this->referenceDatabase->getReference(ReferenceDatabase::PHOTO_LOCATION_LOCATION, $messageMedia)]; $res['ext'] = $this->getExtensionFromLocation($res['InputFileLocation'], '.jpg'); $res['mime'] = $this->getMimeFromExtension($res['ext'], 'image/jpeg'); return $res; @@ -886,7 +886,7 @@ trait Files $res['name'] .= ' - '.$audio['performer']; } } - $res['InputFileLocation'] = ['_' => 'inputDocumentFileLocation', 'id' => $messageMedia['document']['id'], 'access_hash' => $messageMedia['document']['access_hash'], 'version' => isset($messageMedia['document']['version']) ? $messageMedia['document']['version'] : 0, 'dc_id' => $messageMedia['document']['dc_id'], 'file_reference' => yield $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $messageMedia['document'])]; + $res['InputFileLocation'] = ['_' => 'inputDocumentFileLocation', 'id' => $messageMedia['document']['id'], 'access_hash' => $messageMedia['document']['access_hash'], 'version' => isset($messageMedia['document']['version']) ? $messageMedia['document']['version'] : 0, 'dc_id' => $messageMedia['document']['dc_id'], 'file_reference' => yield from $this->referenceDatabase->getReference(ReferenceDatabase::DOCUMENT_LOCATION, $messageMedia['document'])]; if (!isset($res['ext']) || $res['ext'] === '') { $res['ext'] = $this->getExtensionFromLocation($res['InputFileLocation'], $this->getExtensionFromMime($messageMedia['document']['mime_type'])); } diff --git a/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php b/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php index a1b0d407..9f8bd28e 100644 --- a/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php +++ b/src/danog/MadelineProto/MTProtoTools/ReferenceDatabase.php @@ -469,7 +469,7 @@ class ReferenceDatabase implements TLCallback } public function populateReference(array $object): \Generator { - $object['file_reference'] = yield $this->getReference(self::LOCATION_CONTEXT[$object['_']], $object); + $object['file_reference'] = yield from $this->getReference(self::LOCATION_CONTEXT[$object['_']], $object); return $object; } public function getReference(int $locationType, array $location): \Generator