From aaa569a08dca9c075779c1230577fc0a69643866 Mon Sep 17 00:00:00 2001
From: Dan <14043624+delivrance@users.noreply.github.com>
Date: Wed, 29 May 2019 09:47:14 +0200
Subject: [PATCH] Revamp Thumbnail type (ex PhotoSize)
---
.../{photo_size.py => thumbnail.py} | 65 ++++++++++++-------
1 file changed, 40 insertions(+), 25 deletions(-)
rename pyrogram/client/types/messages_and_media/{photo_size.py => thumbnail.py} (53%)
diff --git a/pyrogram/client/types/messages_and_media/photo_size.py b/pyrogram/client/types/messages_and_media/thumbnail.py
similarity index 53%
rename from pyrogram/client/types/messages_and_media/photo_size.py
rename to pyrogram/client/types/messages_and_media/thumbnail.py
index 9f64ae6a..0ff15e66 100644
--- a/pyrogram/client/types/messages_and_media/photo_size.py
+++ b/pyrogram/client/types/messages_and_media/thumbnail.py
@@ -17,15 +17,16 @@
# along with Pyrogram. If not, see .
from struct import pack
-from typing import List, Union
+from typing import Union, List
import pyrogram
from pyrogram.api import types
from pyrogram.client.ext.utils import encode
+from .stripped_thumbnail import StrippedThumbnail
from ..pyrogram_type import PyrogramType
-class PhotoSize(PyrogramType):
+class Thumbnail(PyrogramType):
"""One size of a photo or a file/sticker thumbnail.
Parameters:
@@ -61,30 +62,44 @@ class PhotoSize(PyrogramType):
self.file_size = file_size
@staticmethod
- def _parse(client, thumbs: List) -> Union["PhotoSize", None]:
- if not thumbs:
+ def _parse(
+ client,
+ media: Union[types.Photo, types.Document]
+ ) -> Union[List[Union[StrippedThumbnail, "Thumbnail"]], None]:
+ if isinstance(media, types.Photo):
+ raw_thumbnails = media.sizes[:-1]
+ media_type = 0
+ elif isinstance(media, types.Document):
+ raw_thumbnails = media.thumbs
+ media_type = 14
+
+ if not raw_thumbnails:
+ return None
+ else:
return None
- photo_size = thumbs[-1]
+ thumbnails = []
- if not isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize, types.PhotoStrippedSize)):
- return None
-
- loc = photo_size.location
-
- if not isinstance(loc, types.FileLocation):
- return None
-
- return PhotoSize(
- file_id=encode(
- pack(
- "