2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Refactor ChatPhoto

This commit is contained in:
Dan 2018-12-15 17:30:24 +01:00
parent bf3609ec0a
commit 5962f8dedc

View File

@ -16,7 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from struct import pack
from pyrogram.api import types
from pyrogram.api.core import Object
from ...ext.utils import encode
class ChatPhoto(Object):
@ -32,6 +36,42 @@ class ChatPhoto(Object):
ID = 0xb0700015
def __init__(self, small_file_id: str, big_file_id: str):
self.small_file_id = small_file_id # string
self.big_file_id = big_file_id # string
def __init__(self, small_file_id: str, big_file_id: str, *,
client=None, raw=None):
self.small_file_id = small_file_id
self.big_file_id = big_file_id
self._client = client
self.raw = raw
@staticmethod
def parse(client, chat_photo: types.UserProfilePhoto or types.ChatPhoto):
if not isinstance(chat_photo, (types.UserProfilePhoto, types.ChatPhoto)):
return None
if not isinstance(chat_photo.photo_small, types.FileLocation):
return None
if not isinstance(chat_photo.photo_big, types.FileLocation):
return None
photo_id = getattr(chat_photo, "photo_id", 0)
loc_small = chat_photo.photo_small
loc_big = chat_photo.photo_big
return ChatPhoto(
small_file_id=encode(
pack(
"<iiqqqqi",
1, loc_small.dc_id, photo_id, 0, loc_small.volume_id, loc_small.secret, loc_small.local_id
)
),
big_file_id=encode(
pack(
"<iiqqqqi",
1, loc_big.dc_id, photo_id, 0, loc_big.volume_id, loc_big.secret, loc_big.local_id
)
),
client=client,
raw=chat_photo
)