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

Fix delete_profile_photos. Closes #259

This commit is contained in:
Dan 2019-06-26 21:43:08 +02:00
parent 39e25147bd
commit 40bcd4e59d

View File

@ -16,23 +16,24 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from base64 import b64decode
from struct import unpack from struct import unpack
from typing import List, Union from typing import List, Union
from pyrogram.api import functions, types from pyrogram.api import functions, types
from pyrogram.client.ext import utils
from ...ext import BaseClient from ...ext import BaseClient
class DeleteProfilePhotos(BaseClient): class DeleteProfilePhotos(BaseClient):
def delete_profile_photos( def delete_profile_photos(
self, self,
id: Union[str, List[str]] photo_ids: Union[str, List[str]]
) -> bool: ) -> bool:
"""Delete your own profile photos. """Delete your own profile photos.
Parameters: Parameters:
id (``str`` | ``list``): photo_ids (``str`` | List of ``str``):
A single :obj:`Photo` id as string or multiple ids as list of strings for deleting A single :obj:`Photo` id as string or multiple ids as list of strings for deleting
more than one photos at once. more than one photos at once.
@ -42,16 +43,16 @@ class DeleteProfilePhotos(BaseClient):
Raises: Raises:
RPCError: In case of a Telegram RPC error. RPCError: In case of a Telegram RPC error.
""" """
id = id if isinstance(id, list) else [id] photo_ids = photo_ids if isinstance(photo_ids, list) else [photo_ids]
input_photos = [] input_photos = []
for i in id: for photo_id in photo_ids:
s = unpack("<qq", b64decode(i + "=" * (-len(i) % 4), "-_")) unpacked = unpack("<iiqqc", utils.decode(photo_id))
input_photos.append( input_photos.append(
types.InputPhoto( types.InputPhoto(
id=s[0], id=unpacked[2],
access_hash=s[1], access_hash=unpacked[3],
file_reference=b"" file_reference=b""
) )
) )