Fix getMediaPreview

This commit is contained in:
Alexander Pankratov 2020-09-13 00:20:03 +03:00
parent e63415a2ef
commit 1e31286e88

View File

@ -415,23 +415,39 @@ class ApiExtensions
}
$media = $message['media'][array_key_last($message['media'])];
$thumb = null;
switch (true) {
case isset($media['sizes']):
$thumb = $media['sizes'][array_key_last($media['sizes'])];
foreach ($media['sizes'] as $size) {
if ($size['_'] === 'photoSize') {
$thumb = $size;
}
}
break;
case isset($media['thumb']['size']):
$thumb = $media['thumb'];
break;
case !empty($media['thumbs']):
$thumb = $media['thumbs'][array_key_last($media['thumbs'])];
foreach ($media['thumbs'] as $size) {
if ($size['_'] === 'photoSize') {
$thumb = $size;
}
}
break;
case isset($media['photo']['sizes']):
$thumb = $media['photo']['sizes'][array_key_last($media['photo']['sizes'])];
foreach ($media['photo']['sizes'] as $size) {
if ($size['_'] === 'photoSize') {
$thumb = $size;
}
}
break;
default:
throw new UnexpectedValueException('Message has no preview');
}
if (null === $thumb) {
throw new UnexpectedValueException('Empty preview');
}
$info = yield $this->madelineProto->getDownloadInfo($thumb);
if ($media['_'] === 'webPage') {