From f4b4496995808891bff34c8c0e07403ce764a6ec Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 21 Jan 2019 18:34:28 +0100 Subject: [PATCH 01/10] Update API schema to Layer 93 --- compiler/api/source/main_api.tl | 57 ++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 61bd1a41..7bbf15e7 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -96,12 +96,12 @@ userStatusLastWeek#7bf09fc = UserStatus; userStatusLastMonth#77ebc742 = UserStatus; chatEmpty#9ba2d800 id:int = Chat; -chat#d91cdd54 flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true admins_enabled:flags.3?true admin:flags.4?true deactivated:flags.5?true id:int title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel = Chat; +chat#3bda1bde flags:# creator:flags.0?true kicked:flags.1?true left:flags.2?true deactivated:flags.5?true id:int title:string photo:ChatPhoto participants_count:int date:int version:int migrated_to:flags.6?InputChannel admin_rights:flags.14?ChatAdminRights default_banned_rights:flags.18?ChatBannedRights = Chat; chatForbidden#7328bdb id:int title:string = Chat; -channel#c88974ac flags:# creator:flags.0?true left:flags.2?true editor:flags.3?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights participants_count:flags.17?int = Chat; +channel#4df30834 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int = Chat; channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat; -chatFull#edd2a791 flags:# id:int participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int = ChatFull; +chatFull#22a235da flags:# can_set_username:flags.7?true id:int about:string participants:ChatParticipants chat_photo:flags.2?Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:flags.3?Vector pinned_msg_id:flags.6?int = ChatFull; channelFull#1c87a71a flags:# can_view_participants:flags.3?true can_set_username:flags.6?true can_set_stickers:flags.7?true hidden_prehistory:flags.10?true can_view_stats:flags.12?true id:int about:string participants_count:flags.0?int admins_count:flags.1?int kicked_count:flags.2?int banned_count:flags.2?int online_count:flags.13?int read_inbox_max_id:int read_outbox_max_id:int unread_count:int chat_photo:Photo notify_settings:PeerNotifySettings exported_invite:ExportedChatInvite bot_info:Vector migrated_from_chat_id:flags.4?int migrated_from_max_id:flags.4?int pinned_msg_id:flags.5?int stickerset:flags.8?StickerSet available_min_id:flags.9?int = ChatFull; chatParticipant#c8d7493e user_id:int inviter_id:int date:int = ChatParticipant; @@ -163,6 +163,7 @@ photo#9c477dd8 flags:# has_stickers:flags.0?true id:long access_hash:long file_r photoSizeEmpty#e17e23c type:string = PhotoSize; photoSize#77bfb61b type:string location:FileLocation w:int h:int size:int = PhotoSize; photoCachedSize#e9a734fa type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize; +photoStrippedSize#e0b0bc2e type:string bytes:bytes = PhotoSize; geoPointEmpty#1117dd5f = GeoPoint; geoPoint#296f104 long:double lat:double access_hash:long = GeoPoint; @@ -186,8 +187,7 @@ peerNotifySettings#af509d20 flags:# show_previews:flags.0?Bool silent:flags.1?Bo peerSettings#818426cd flags:# report_spam:flags.0?true = PeerSettings; -wallPaper#ccb03657 id:int title:string sizes:Vector color:int = WallPaper; -wallPaperSolid#63117f24 id:int title:string bg_color:int color:int = WallPaper; +wallPaper#f04f91ec id:long flags:# creator:flags.0?true default:flags.1?true access_hash:long slug:string document:Document = WallPaper; inputReportReasonSpam#58dbcab8 = ReportReason; inputReportReasonViolence#1e22c78d = ReportReason; @@ -221,7 +221,7 @@ messages.dialogsSlice#71e094f3 count:int dialogs:Vector messages:Vector< messages.dialogsNotModified#f0e3e596 count:int = messages.Dialogs; messages.messages#8c718e87 messages:Vector chats:Vector users:Vector = messages.Messages; -messages.messagesSlice#b446ae3 count:int messages:Vector chats:Vector users:Vector = messages.Messages; +messages.messagesSlice#a6c47aaa flags:# inexact:flags.1?true count:int messages:Vector chats:Vector users:Vector = messages.Messages; messages.channelMessages#99262e37 flags:# inexact:flags.1?true pts:int count:int messages:Vector chats:Vector users:Vector = messages.Messages; messages.messagesNotModified#74535f21 count:int = messages.Messages; @@ -281,7 +281,6 @@ updateNewChannelMessage#62ba04d9 message:Message pts:int pts_count:int = Update; updateReadChannelInbox#4214f37f channel_id:int max_id:int = Update; updateDeleteChannelMessages#c37521c9 channel_id:int messages:Vector pts:int pts_count:int = Update; updateChannelMessageViews#98a12b4b channel_id:int id:int views:int = Update; -updateChatAdmins#6e947941 chat_id:int enabled:Bool version:int = Update; updateChatParticipantAdmin#b6901959 chat_id:int user_id:int is_admin:Bool version:int = Update; updateNewStickerSet#688a30aa stickerset:messages.StickerSet = Update; updateStickerSetsOrder#bb2d201 flags:# masks:flags.0?true order:Vector = Update; @@ -318,6 +317,7 @@ updateDialogUnreadMark#e16459c3 flags:# unread:flags.0?true peer:DialogPeer = Up updateUserPinnedMessage#4c43da18 user_id:int id:int = Update; updateChatPinnedMessage#22893b26 chat_id:int id:int = Update; updateMessagePoll#aca1657b flags:# poll_id:long poll:flags.0?Poll results:PollResults = Update; +updateChatDefaultBannedRights#54c01850 peer:Peer default_banned_rights:ChatBannedRights version:int = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -382,7 +382,7 @@ inputDocumentEmpty#72f0eaae = InputDocument; inputDocument#1abfb575 id:long access_hash:long file_reference:bytes = InputDocument; documentEmpty#36f8c871 id:long = Document; -document#59534e4c id:long access_hash:long file_reference:bytes date:int mime_type:string size:int thumb:PhotoSize dc_id:int attributes:Vector = Document; +document#9ba29cc1 flags:# id:long access_hash:long file_reference:bytes date:int mime_type:string size:int thumbs:flags.0?Vector dc_id:int attributes:Vector = Document; help.support#17c6b5f6 phone_number:string user:User = help.Support; @@ -544,8 +544,8 @@ channelMessagesFilter#cd77d957 flags:# exclude_new_messages:flags.1?true ranges: channelParticipant#15ebac1d user_id:int date:int = ChannelParticipant; channelParticipantSelf#a3289a6d user_id:int inviter_id:int date:int = ChannelParticipant; channelParticipantCreator#e3e2e1f9 user_id:int = ChannelParticipant; -channelParticipantAdmin#a82fa898 flags:# can_edit:flags.0?true user_id:int inviter_id:int promoted_by:int date:int admin_rights:ChannelAdminRights = ChannelParticipant; -channelParticipantBanned#222c1886 flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChannelBannedRights = ChannelParticipant; +channelParticipantAdmin#5daa6e23 flags:# can_edit:flags.0?true self:flags.1?true user_id:int inviter_id:flags.1?int promoted_by:int date:int admin_rights:ChatAdminRights = ChannelParticipant; +channelParticipantBanned#1c0facaf flags:# left:flags.0?true user_id:int kicked_by:int date:int banned_rights:ChatBannedRights = ChannelParticipant; channelParticipantsRecent#de3f3c79 = ChannelParticipantsFilter; channelParticipantsAdmins#b4608969 = ChannelParticipantsFilter; @@ -553,6 +553,7 @@ channelParticipantsKicked#a3b54985 q:string = ChannelParticipantsFilter; channelParticipantsBots#b0d1865b = ChannelParticipantsFilter; channelParticipantsBanned#1427a5e1 q:string = ChannelParticipantsFilter; channelParticipantsSearch#656ac4b q:string = ChannelParticipantsFilter; +channelParticipantsContacts#bb6ae88d q:string = ChannelParticipantsFilter; channels.channelParticipants#f56ee2a8 count:int participants:Vector users:Vector = channels.ChannelParticipants; channels.channelParticipantsNotModified#f0173fe9 = channels.ChannelParticipants; @@ -789,10 +790,6 @@ langPackDifference#f385c1f6 lang_code:string from_version:int version:int string langPackLanguage#eeca5ce3 flags:# official:flags.0?true rtl:flags.2?true beta:flags.3?true name:string native_name:string lang_code:string base_lang_code:flags.1?string plural_code:string strings_count:int translated_count:int translations_url:string = LangPackLanguage; -channelAdminRights#5d7ceba5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true invite_link:flags.6?true pin_messages:flags.7?true add_admins:flags.9?true manage_call:flags.10?true = ChannelAdminRights; - -channelBannedRights#58cf4249 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true until_date:int = ChannelBannedRights; - channelAdminLogEventActionChangeTitle#e6dfb825 prev_value:string new_value:string = ChannelAdminLogEventAction; channelAdminLogEventActionChangeAbout#55188a2e prev_value:string new_value:string = ChannelAdminLogEventAction; channelAdminLogEventActionChangeUsername#6a4afc38 prev_value:string new_value:string = ChannelAdminLogEventAction; @@ -809,6 +806,8 @@ channelAdminLogEventActionParticipantToggleBan#e6d83d7e prev_participant:Channel channelAdminLogEventActionParticipantToggleAdmin#d5676710 prev_participant:ChannelParticipant new_participant:ChannelParticipant = ChannelAdminLogEventAction; channelAdminLogEventActionChangeStickerSet#b1c3caa7 prev_stickerset:InputStickerSet new_stickerset:InputStickerSet = ChannelAdminLogEventAction; channelAdminLogEventActionTogglePreHistoryHidden#5f5c95f1 new_value:Bool = ChannelAdminLogEventAction; +channelAdminLogEventActionDefaultBannedRights#2df5fc0a prev_banned_rights:ChatBannedRights new_banned_rights:ChatBannedRights = ChannelAdminLogEventAction; +channelAdminLogEventActionStopPoll#8f079643 message:Message = ChannelAdminLogEventAction; channelAdminLogEvent#3b5a3e40 id:long date:int user_id:int action:ChannelAdminLogEventAction = ChannelAdminLogEvent; @@ -972,6 +971,16 @@ chatOnlines#f041e250 onlines:int = ChatOnlines; statsURL#47a971e0 url:string = StatsURL; +chatAdminRights#5fb224d5 flags:# change_info:flags.0?true post_messages:flags.1?true edit_messages:flags.2?true delete_messages:flags.3?true ban_users:flags.4?true invite_users:flags.5?true pin_messages:flags.7?true add_admins:flags.9?true = ChatAdminRights; + +chatBannedRights#9f120418 flags:# view_messages:flags.0?true send_messages:flags.1?true send_media:flags.2?true send_stickers:flags.3?true send_gifs:flags.4?true send_games:flags.5?true send_inline:flags.6?true embed_links:flags.7?true send_polls:flags.8?true change_info:flags.10?true invite_users:flags.15?true pin_messages:flags.17?true until_date:int = ChatBannedRights; + +inputWallPaper#e630b979 id:long access_hash:long = InputWallPaper; +inputWallPaperSlug#72091c80 slug:string = InputWallPaper; + +account.wallPapersNotModified#1c199183 = account.WallPapers; +account.wallPapers#702b65a9 hash:int wallpapers:Vector = account.WallPapers; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -1005,7 +1014,7 @@ account.getNotifySettings#12b3ad31 peer:InputNotifyPeer = PeerNotifySettings; account.resetNotifySettings#db7e1747 = Bool; account.updateProfile#78515775 flags:# first_name:flags.0?string last_name:flags.1?string about:flags.2?string = User; account.updateStatus#6628562c offline:Bool = Bool; -account.getWallPapers#c04cfac2 = Vector; +account.getWallPapers#aabb1763 hash:int = account.WallPapers; account.reportPeer#ae189d5f peer:InputPeer reason:ReportReason = Bool; account.checkUsername#2714d86c username:string = Bool; account.updateUsername#3e0bdd7c username:string = User; @@ -1046,6 +1055,10 @@ account.cancelPasswordEmail#c1cbd5b6 = Bool; account.getContactSignUpNotification#9f07c728 = Bool; account.setContactSignUpNotification#cff43f61 silent:Bool = Bool; account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates; +account.uploadWallPaper#c7ba9b4d file:InputFile mime_type:string = WallPaper; +account.getWallPaper#fc8ddbea wallpaper:InputWallPaper = WallPaper; +account.saveWallPaper#189581b3 wallpaper:InputWallPaper unsave:Bool = Bool; +account.installWallPaper#4a0378ce wallpaper:InputWallPaper = Bool; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#ca30a5b1 id:InputUser = UserFull; @@ -1107,7 +1120,7 @@ messages.readMessageContents#36a73f77 id:Vector = messages.AffectedMessages messages.getStickers#43d4f2c emoticon:string hash:int = messages.Stickers; messages.getAllStickers#1c9618b1 hash:int = messages.AllStickers; messages.getWebPagePreview#8b68b0cc flags:# message:string entities:flags.3?Vector = MessageMedia; -messages.exportChatInvite#7d885289 chat_id:int = ExportedChatInvite; +messages.exportChatInvite#df7534c peer:InputPeer = ExportedChatInvite; messages.checkChatInvite#3eadb1bb hash:string = ChatInvite; messages.importChatInvite#6c50051c hash:string = Updates; messages.getStickerSet#2619a90e stickerset:InputStickerSet = messages.StickerSet; @@ -1115,7 +1128,6 @@ messages.installStickerSet#c78fe460 stickerset:InputStickerSet archived:Bool = m messages.uninstallStickerSet#f96e55de stickerset:InputStickerSet = Bool; messages.startBot#e6df7378 bot:InputUser peer:InputPeer random_id:long start_param:string = Updates; messages.getMessagesViews#c4c8a55d peer:InputPeer id:Vector increment:Bool = Vector; -messages.toggleChatAdmins#ec8bd9e1 chat_id:int enabled:Bool = Updates; messages.editChatAdmin#a9e69f2e chat_id:int user_id:InputUser is_admin:Bool = Bool; messages.migrateChat#15a3b8e3 chat_id:int = Updates; messages.searchGlobal#9e3cacb0 q:string offset_date:int offset_peer:InputPeer offset_id:int limit:int = messages.Messages; @@ -1174,6 +1186,8 @@ messages.sendVote#10ea6184 peer:InputPeer msg_id:int options:Vector = Upd messages.getPollResults#73bb643b peer:InputPeer msg_id:int = Updates; messages.getOnlines#6e2be050 peer:InputPeer = ChatOnlines; messages.getStatsURL#83f6c0cd peer:InputPeer = StatsURL; +messages.editChatAbout#def60797 peer:InputPeer about:string = Bool; +messages.editChatDefaultBannedRights#a5866b41 peer:InputPeer banned_rights:ChatBannedRights = Updates; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1223,8 +1237,7 @@ channels.getParticipant#546dd7a6 channel:InputChannel user_id:InputUser = channe channels.getChannels#a7f6bbb id:Vector = messages.Chats; channels.getFullChannel#8736a09 channel:InputChannel = messages.ChatFull; channels.createChannel#f4893d7f flags:# broadcast:flags.0?true megagroup:flags.1?true title:string about:string = Updates; -channels.editAbout#13e27f1e channel:InputChannel about:string = Bool; -channels.editAdmin#20b88214 channel:InputChannel user_id:InputUser admin_rights:ChannelAdminRights = Updates; +channels.editAdmin#70f893ba channel:InputChannel user_id:InputUser admin_rights:ChatAdminRights = Updates; channels.editTitle#566decd0 channel:InputChannel title:string = Updates; channels.editPhoto#f12e57c9 channel:InputChannel photo:InputChatPhoto = Updates; channels.checkUsername#10e6bd2c channel:InputChannel username:string = Bool; @@ -1232,13 +1245,11 @@ channels.updateUsername#3514b3de channel:InputChannel username:string = Bool; channels.joinChannel#24b524c5 channel:InputChannel = Updates; channels.leaveChannel#f836aa95 channel:InputChannel = Updates; channels.inviteToChannel#199f3a6c channel:InputChannel users:Vector = Updates; -channels.exportInvite#c7560885 channel:InputChannel = ExportedChatInvite; channels.deleteChannel#c0111fe3 channel:InputChannel = Updates; -channels.toggleInvites#49609307 channel:InputChannel enabled:Bool = Updates; channels.exportMessageLink#ceb77163 channel:InputChannel id:int grouped:Bool = ExportedMessageLink; channels.toggleSignatures#1f69b606 channel:InputChannel enabled:Bool = Updates; channels.getAdminedPublicChannels#8d8d82d7 = messages.Chats; -channels.editBanned#bfd915cd channel:InputChannel user_id:InputUser banned_rights:ChannelBannedRights = Updates; +channels.editBanned#72796912 channel:InputChannel user_id:InputUser banned_rights:ChatBannedRights = Updates; channels.getAdminLog#33ddf480 flags:# channel:InputChannel q:string events_filter:flags.0?ChannelAdminLogEventsFilter admins:flags.1?Vector max_id:long min_id:long limit:int = channels.AdminLogResults; channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet = Bool; channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; @@ -1276,4 +1287,4 @@ langpack.getDifference#9d51e814 lang_code:string from_version:int = LangPackDiff langpack.getLanguages#42c6978f lang_pack:string = Vector; langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLanguage; -// LAYER 91 +// LAYER 93 From cb0b8ebeae08f32e21958a2b1bfa4b944a092536 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 21 Jan 2019 18:35:11 +0100 Subject: [PATCH 02/10] Fix Chat sticker_set_name --- pyrogram/client/types/user_and_chats/chat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index ec30b866..75313651 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -197,7 +197,7 @@ class Chat(PyrogramType): parsed_chat.description = full_chat.about or None # TODO: Add StickerSet type parsed_chat.can_set_sticker_set = full_chat.can_set_stickers - parsed_chat.sticker_set_name = full_chat.stickerset + parsed_chat.sticker_set_name = getattr(full_chat.stickerset, "short_name", None) if full_chat.pinned_msg_id: parsed_chat.pinned_message = client.get_messages( From e99f86b69fc0d13f723703f08a53d4d4640ae273 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Mon, 21 Jan 2019 18:45:52 +0100 Subject: [PATCH 03/10] Update media thumbs parsing for L93 --- .../types/messages_and_media/animation.py | 2 +- .../client/types/messages_and_media/audio.py | 2 +- .../types/messages_and_media/document.py | 2 +- .../client/types/messages_and_media/photo.py | 1 - .../types/messages_and_media/photo_size.py | 44 ++++++++++--------- .../types/messages_and_media/sticker.py | 2 +- .../client/types/messages_and_media/video.py | 2 +- .../types/messages_and_media/video_note.py | 2 +- 8 files changed, 30 insertions(+), 27 deletions(-) diff --git a/pyrogram/client/types/messages_and_media/animation.py b/pyrogram/client/types/messages_and_media/animation.py index d5661ea8..9f3ba886 100644 --- a/pyrogram/client/types/messages_and_media/animation.py +++ b/pyrogram/client/types/messages_and_media/animation.py @@ -97,7 +97,7 @@ class Animation(PyrogramType): width=getattr(video_attributes, "w", 0), height=getattr(video_attributes, "h", 0), duration=getattr(video_attributes, "duration", 0), - thumb=PhotoSize._parse(client, animation.thumb), + thumb=PhotoSize._parse(client, animation.thumbs), mime_type=animation.mime_type, file_size=animation.size, file_name=file_name, diff --git a/pyrogram/client/types/messages_and_media/audio.py b/pyrogram/client/types/messages_and_media/audio.py index cfecceae..9c5698f1 100644 --- a/pyrogram/client/types/messages_and_media/audio.py +++ b/pyrogram/client/types/messages_and_media/audio.py @@ -99,7 +99,7 @@ class Audio(PyrogramType): title=audio_attributes.title, mime_type=audio.mime_type, file_size=audio.size, - thumb=PhotoSize._parse(client, audio.thumb), + thumb=PhotoSize._parse(client, audio.thumbs), file_name=file_name, date=audio.date, client=client diff --git a/pyrogram/client/types/messages_and_media/document.py b/pyrogram/client/types/messages_and_media/document.py index e84b5149..5cd01a92 100644 --- a/pyrogram/client/types/messages_and_media/document.py +++ b/pyrogram/client/types/messages_and_media/document.py @@ -78,7 +78,7 @@ class Document(PyrogramType): document.access_hash ) ), - thumb=PhotoSize._parse(client, document.thumb), + thumb=PhotoSize._parse(client, document.thumbs), file_name=file_name, mime_type=document.mime_type, file_size=document.size, diff --git a/pyrogram/client/types/messages_and_media/photo.py b/pyrogram/client/types/messages_and_media/photo.py index 72187761..aa2b3a26 100644 --- a/pyrogram/client/types/messages_and_media/photo.py +++ b/pyrogram/client/types/messages_and_media/photo.py @@ -61,7 +61,6 @@ class Photo(PyrogramType): for raw_size in raw_sizes: if isinstance(raw_size, (types.PhotoSize, types.PhotoCachedSize)): - if isinstance(raw_size, types.PhotoSize): file_size = raw_size.size elif isinstance(raw_size, types.PhotoCachedSize): diff --git a/pyrogram/client/types/messages_and_media/photo_size.py b/pyrogram/client/types/messages_and_media/photo_size.py index 05f00455..e1be74df 100644 --- a/pyrogram/client/types/messages_and_media/photo_size.py +++ b/pyrogram/client/types/messages_and_media/photo_size.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . from struct import pack +from typing import List, Union import pyrogram from pyrogram.api import types @@ -56,27 +57,30 @@ class PhotoSize(PyrogramType): self.file_size = file_size @staticmethod - def _parse(client, photo_size: types.PhotoSize or types.PhotoCachedSize): - if isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize)): + def _parse(client, thumbs: List) -> Union["PhotoSize", None]: + if not thumbs: + return None - if isinstance(photo_size, types.PhotoSize): - file_size = photo_size.size - elif isinstance(photo_size, types.PhotoCachedSize): - file_size = len(photo_size.bytes) - else: - file_size = 0 + photo_size = thumbs[-1] - loc = photo_size.location + if not isinstance(photo_size, (types.PhotoSize, types.PhotoCachedSize, types.PhotoStrippedSize)): + return None - if isinstance(loc, types.FileLocation): - return PhotoSize( - file_id=encode( - pack( - " Date: Thu, 24 Jan 2019 17:03:51 +0100 Subject: [PATCH 04/10] Add ChatPermissions type --- docs/source/pyrogram/Types.rst | 1 + pyrogram/__init__.py | 3 +- pyrogram/client/types/__init__.py | 2 +- .../client/types/user_and_chats/__init__.py | 1 + .../types/user_and_chats/chat_permissions.py | 173 ++++++++++++++++++ 5 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 pyrogram/client/types/user_and_chats/chat_permissions.py diff --git a/docs/source/pyrogram/Types.rst b/docs/source/pyrogram/Types.rst index 6e0a14db..14fb9147 100644 --- a/docs/source/pyrogram/Types.rst +++ b/docs/source/pyrogram/Types.rst @@ -16,6 +16,7 @@ Users & Chats ChatPhoto ChatMember ChatMembers + ChatPermissions Dialog Dialogs diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index db3d8674..7f58a6f6 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -32,7 +32,8 @@ from .client.types import ( Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus, UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, - Poll, PollOption, ChatPreview, StopPropagation, Game, CallbackGame, GameHighScore, GameHighScores + Poll, PollOption, ChatPreview, StopPropagation, Game, CallbackGame, GameHighScore, GameHighScores, + ChatPermissions ) from .client import ( Client, ChatAction, ParseMode, Emoji, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index ca332a22..f29da7bb 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -33,5 +33,5 @@ from .messages_and_media import ( from .update import StopPropagation from .user_and_chats import ( Chat, ChatMember, ChatMembers, ChatPhoto, - Dialog, Dialogs, User, UserStatus, ChatPreview + Dialog, Dialogs, User, UserStatus, ChatPreview, ChatPermissions ) diff --git a/pyrogram/client/types/user_and_chats/__init__.py b/pyrogram/client/types/user_and_chats/__init__.py index 24a9a51b..9c9c0beb 100644 --- a/pyrogram/client/types/user_and_chats/__init__.py +++ b/pyrogram/client/types/user_and_chats/__init__.py @@ -19,6 +19,7 @@ from .chat import Chat from .chat_member import ChatMember from .chat_members import ChatMembers +from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from .chat_preview import ChatPreview from .dialog import Dialog diff --git a/pyrogram/client/types/user_and_chats/chat_permissions.py b/pyrogram/client/types/user_and_chats/chat_permissions.py new file mode 100644 index 00000000..68b4567e --- /dev/null +++ b/pyrogram/client/types/user_and_chats/chat_permissions.py @@ -0,0 +1,173 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2019 Dan Tès +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import Union + +from pyrogram.api import types +from ..pyrogram_type import PyrogramType + + +class ChatPermissions(PyrogramType): + """This object represents both a chat default permissions and a single member permissions within a chat. + + Some permissions make sense depending on the context: default chat permissions, restricted/kicked member or + administrators in groups or channels. + + Args: + until_date (``int``, *optional*): + Applicable to restricted and kicked members only. + Date when user restrictions will be lifted, unix time. + 0 means the restrictions will never be lifted (user restricted forever). + + can_be_edited (``bool``, *optional*): + Applicable to administrators only. + True, if you are allowed to edit administrator privileges of the user. + + can_change_info (``bool``, *optional*): + Applicable to default chat permissions in private groups and administrators in public groups only. + True, if the chat title, photo and other settings can be changed. + + can_post_messages (``bool``, *optional*): + Applicable to channel administrators only. + True, if the administrator can post messages in the channel, channels only. + + can_edit_messages (``bool``, *optional*): + Applicable to channel administrators only. + True, if the administrator can edit messages of other users and can pin messages, channels only. + + can_delete_messages (``bool``, *optional*): + Applicable to administrators only. + True, if the administrator can delete messages of other users. + + can_restrict_members (``bool``, *optional*): + Applicable to administrators only. + True, if the administrator can restrict, ban or unban chat members. + + can_invite_users (``bool``, *optional*): + Applicable to default chat permissions and administrators only. + True, if new users can be invited to the chat. + + can_pin_messages (``bool``, *optional*): + Applicable to default chat permissions in private groups and administrators in public groups only. + True, if messages can be pinned, supergroups only. + + can_promote_members (``bool``, *optional*): + Applicable to administrators only. + True, if the administrator can add new administrators with a subset of his own privileges or demote + administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed + by the user). + + can_send_messages (``bool``, *optional*): + Applicable to default chat permissions and restricted members only. + True, if text messages, contacts, locations and venues can be sent. + + can_send_media_messages (``bool``, *optional*): + Applicable to default chat permissions and restricted members only. + True, if audios, documents, photos, videos, video notes and voice notes can be sent, implies + can_send_messages. + + can_send_other_messages (``bool``, *optional*): + Applicable to default chat permissions and restricted members only. + True, if animations, games, stickers and inline bot results can be sent, implies can_send_media_messages. + + can_add_web_page_previews (``bool``, *optional*): + Applicable to default chat permissions and restricted members only. + True, if web page previews can be attached to text messages, implies can_send_media_messages. + + can_send_polls (``bool``, *optional*): + Applicable to default chat permissions and restricted members only. + True, if polls can be sent, implies can_send_media_messages. + """ + + def __init__( + self, + *, + until_date: int = None, + + # Admin permissions + can_be_edited: bool = None, + can_change_info: bool = None, + can_post_messages: bool = None, # Channels only + can_edit_messages: bool = None, # Channels only + can_delete_messages: bool = None, + can_restrict_members: bool = None, + can_invite_users: bool = None, + can_pin_messages: bool = None, # Supergroups only + can_promote_members: bool = None, + + # Restricted user permissions + can_send_messages: bool = None, # Text, contacts, locations and venues + can_send_media_messages: bool = None, # Audios, documents, photos, videos, video notes and voice notes + can_send_other_messages: bool = None, # Animations (GIFs), games, stickers, inline bot results + can_add_web_page_previews: bool = None, + can_send_polls: bool = None + ): + super().__init__(None) + + self.until_date = until_date + self.can_be_edited = can_be_edited + + self.can_change_info = can_change_info + self.can_post_messages = can_post_messages + self.can_edit_messages = can_edit_messages + self.can_delete_messages = can_delete_messages + self.can_restrict_members = can_restrict_members + self.can_invite_users = can_invite_users + self.can_pin_messages = can_pin_messages + self.can_promote_members = can_promote_members + + self.can_send_messages = can_send_messages + self.can_send_media_messages = can_send_media_messages + self.can_send_other_messages = can_send_other_messages + self.can_add_web_page_previews = can_add_web_page_previews + self.can_send_polls = can_send_polls + + @staticmethod + def _parse(member: Union[types.ChannelParticipantAdmin, types.ChannelParticipantBanned]) -> "ChatPermissions": + if isinstance(member, types.ChannelParticipantAdmin): + permissions = member.admin_rights + + return ChatPermissions( + can_be_edited=member.can_edit, + can_change_info=permissions.change_info, + can_post_messages=permissions.post_messages, + can_edit_messages=permissions.edit_messages, + can_delete_messages=permissions.delete_messages, + can_restrict_members=permissions.ban_users, + can_invite_users=permissions.invite_users, + can_pin_messages=permissions.pin_messages, + can_promote_members=permissions.add_admins + ) + + if isinstance(member, types.ChannelParticipantBanned): + denied_permissions = member.banned_rights # type: types.ChatBannedRights + + return ChatPermissions( + until_date=0 if denied_permissions.until_date == (1 << 31) - 1 else denied_permissions.until_date, + can_send_messages=not denied_permissions.send_messages, + can_send_media_messages=not denied_permissions.send_media, + can_send_other_messages=( + not denied_permissions.send_stickers or not denied_permissions.send_gifs or + not denied_permissions.send_games or not denied_permissions.send_inline + ), + can_add_web_page_previews=not denied_permissions.embed_links, + can_send_polls=not denied_permissions.send_polls, + can_change_info=not denied_permissions.change_info, + can_invite_users=not denied_permissions.invite_users, + can_pin_messages=not denied_permissions.pin_messages + ) From e9b17303184aec9ff051b2e7a20f2f676bb38c52 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 24 Jan 2019 17:05:15 +0100 Subject: [PATCH 05/10] Update ChatMember to use the new ChatPermissions type --- .../types/user_and_chats/chat_member.py | 142 +++++------------- 1 file changed, 35 insertions(+), 107 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/chat_member.py b/pyrogram/client/types/user_and_chats/chat_member.py index 70f32540..5769b3f8 100644 --- a/pyrogram/client/types/user_and_chats/chat_member.py +++ b/pyrogram/client/types/user_and_chats/chat_member.py @@ -30,8 +30,8 @@ class ChatMember(PyrogramType): Information about the user. status (``str``): - The member's status in the chat. Can be "creator", "administrator", "member", "restricted", - "left" or "kicked". + The member's status in the chat. + Can be "creator", "administrator", "member", "restricted", "left" or "kicked". date (``int``, *optional*): Date when the user joined, unix time. Not available for creator. @@ -46,52 +46,9 @@ class ChatMember(PyrogramType): restricted_by (:obj:`User `, *optional*): Restricted and kicked only. Information about the user who restricted or kicked this member. - until_date (``int``, *optional*): - Restricted and kicked only. Date when restrictions will be lifted for this user, unix time. - - can_be_edited (``bool``, *optional*): - Administrators only. True, if the bot is allowed to edit administrator privileges of that user. - - can_change_info (``bool``, *optional*): - Administrators only. True, if the administrator can change the chat title, photo and other settings. - - can_post_messages (``bool``, *optional*): - Administrators only. True, if the administrator can post in the channel, channels only. - - can_edit_messages (``bool``, *optional*): - Administrators only. True, if the administrator can edit messages of other users and can pin messages, - channels only. - - can_delete_messages (``bool``, *optional*): - Administrators only. True, if the administrator can delete messages of other users. - - can_invite_users (``bool``, *optional*): - Administrators only. True, if the administrator can invite new users to the chat. - - can_restrict_members (``bool``, *optional*): - Administrators only. True, if the administrator can restrict, ban or unban chat members. - - can_pin_messages (``bool``, *optional*): - Administrators only. True, if the administrator can pin messages, supergroups only. - - can_promote_members (``bool``, *optional*): - Administrators only. True, if the administrator can add new administrators with a subset of his - own privileges or demote administrators that he has promoted, directly or indirectly (promoted by - administrators that were appointed by the user). - - can_send_messages (``bool``, *optional*): - Restricted only. True, if the user can send text messages, contacts, locations and venues. - - can_send_media_messages (``bool``, *optional*): - Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, - implies can_send_messages. - - can_send_other_messages (``bool``, *optional*): - Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies - can_send_media_messages. - - can_add_web_page_previews (``bool``, *optional*): - Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages. + permissions (:obj:`ChatPermissions ` *optional*): + Administrators, restricted and kicked members only. + Information about the member permissions. """ def __init__(self, @@ -103,20 +60,7 @@ class ChatMember(PyrogramType): invited_by: "pyrogram.User" = None, promoted_by: "pyrogram.User" = None, restricted_by: "pyrogram.User" = None, - until_date: int = None, - can_be_edited: bool = None, - can_change_info: bool = None, - can_post_messages: bool = None, - can_edit_messages: bool = None, - can_delete_messages: bool = None, - can_invite_users: bool = None, - can_restrict_members: bool = None, - can_pin_messages: bool = None, - can_promote_members: bool = None, - can_send_messages: bool = None, - can_send_media_messages: bool = None, - can_send_other_messages: bool = None, - can_add_web_page_previews: bool = None): + permissions: "pyrogram.ChatPermissions" = None): super().__init__(client) self.user = user @@ -125,79 +69,63 @@ class ChatMember(PyrogramType): self.invited_by = invited_by self.promoted_by = promoted_by self.restricted_by = restricted_by - self.until_date = until_date - self.can_be_edited = can_be_edited - self.can_change_info = can_change_info - self.can_post_messages = can_post_messages - self.can_edit_messages = can_edit_messages - self.can_delete_messages = can_delete_messages - self.can_invite_users = can_invite_users - self.can_restrict_members = can_restrict_members - self.can_pin_messages = can_pin_messages - self.can_promote_members = can_promote_members - self.can_send_messages = can_send_messages - self.can_send_media_messages = can_send_media_messages - self.can_send_other_messages = can_send_other_messages - self.can_add_web_page_previews = can_add_web_page_previews + self.permissions = permissions @staticmethod def _parse(client, member, users) -> "ChatMember": user = pyrogram.User._parse(client, users[member.user_id]) - invited_by = pyrogram.User._parse(client, users[member.inviter_id]) if hasattr(member, "inviter_id") else None + + invited_by = ( + pyrogram.User._parse(client, users[member.inviter_id]) + if getattr(member, "inviter_id", None) else None + ) if isinstance(member, (types.ChannelParticipant, types.ChannelParticipantSelf, types.ChatParticipant)): - return ChatMember(user=user, status="member", date=member.date, invited_by=invited_by, client=client) + return ChatMember( + user=user, + status="member", + date=member.date, + invited_by=invited_by, + client=client + ) if isinstance(member, (types.ChannelParticipantCreator, types.ChatParticipantCreator)): - return ChatMember(user=user, status="creator", client=client) + return ChatMember( + user=user, + status="creator", + client=client + ) if isinstance(member, types.ChatParticipantAdmin): - return ChatMember(user=user, status="administrator", date=member.date, invited_by=invited_by, client=client) + return ChatMember( + user=user, + status="administrator", + date=member.date, + invited_by=invited_by, + client=client + ) if isinstance(member, types.ChannelParticipantAdmin): - rights = member.admin_rights - return ChatMember( user=user, status="administrator", date=member.date, invited_by=invited_by, promoted_by=pyrogram.User._parse(client, users[member.promoted_by]), - can_be_edited=member.can_edit, - can_change_info=rights.change_info, - can_post_messages=rights.post_messages, - can_edit_messages=rights.edit_messages, - can_delete_messages=rights.delete_messages, - can_invite_users=rights.invite_users or rights.invite_link, - can_restrict_members=rights.ban_users, - can_pin_messages=rights.pin_messages, - can_promote_members=rights.add_admins, + permissions=pyrogram.ChatPermissions._parse(member), client=client ) if isinstance(member, types.ChannelParticipantBanned): - rights = member.banned_rights - - chat_member = ChatMember( + return ChatMember( user=user, status=( - "kicked" if rights.view_messages + "kicked" if member.banned_rights.view_messages else "left" if member.left else "restricted" ), date=member.date, restricted_by=pyrogram.User._parse(client, users[member.kicked_by]), - until_date=0 if rights.until_date == (1 << 31) - 1 else rights.until_date, + permissions=pyrogram.ChatPermissions._parse(member), client=client ) - - if chat_member.status == "restricted": - chat_member.can_send_messages = not rights.send_messages - chat_member.can_send_media_messages = not rights.send_media - chat_member.can_send_other_messages = ( - not rights.send_stickers or not rights.send_gifs or - not rights.send_games or not rights.send_inline - ) - chat_member.can_add_web_page_previews = not rights.embed_links - - return chat_member From 56e7bc996284cf5c46fef43dc7010d6b129700ef Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Thu, 24 Jan 2019 17:20:29 +0100 Subject: [PATCH 06/10] Update kick*, promote*, restrict* and unban_chat_member methods For Layer 93 --- pyrogram/client/methods/chats/kick_chat_member.py | 2 +- .../client/methods/chats/promote_chat_member.py | 13 ++++++------- .../client/methods/chats/restrict_chat_member.py | 2 +- pyrogram/client/methods/chats/unban_chat_member.py | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/methods/chats/kick_chat_member.py b/pyrogram/client/methods/chats/kick_chat_member.py index 4cd66ec4..49b3dcfd 100644 --- a/pyrogram/client/methods/chats/kick_chat_member.py +++ b/pyrogram/client/methods/chats/kick_chat_member.py @@ -65,7 +65,7 @@ class KickChatMember(BaseClient): functions.channels.EditBanned( channel=chat_peer, user_id=user_peer, - banned_rights=types.ChannelBannedRights( + banned_rights=types.ChatBannedRights( until_date=until_date, view_messages=True, send_messages=True, diff --git a/pyrogram/client/methods/chats/promote_chat_member.py b/pyrogram/client/methods/chats/promote_chat_member.py index 9f2260f0..d1f942c2 100644 --- a/pyrogram/client/methods/chats/promote_chat_member.py +++ b/pyrogram/client/methods/chats/promote_chat_member.py @@ -30,11 +30,12 @@ class PromoteChatMember(BaseClient): can_post_messages: bool = False, can_edit_messages: bool = False, can_delete_messages: bool = True, - can_invite_users: bool = True, can_restrict_members: bool = True, + can_invite_users: bool = True, can_pin_messages: bool = False, can_promote_members: bool = False) -> bool: """Use this method to promote or demote a user in a supergroup or a channel. + You must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user. @@ -58,12 +59,12 @@ class PromoteChatMember(BaseClient): can_delete_messages (``bool``, *optional*): Pass True, if the administrator can delete messages of other users. - can_invite_users (``bool``, *optional*): - Pass True, if the administrator can invite new users to the chat. - can_restrict_members (``bool``, *optional*): Pass True, if the administrator can restrict, ban or unban chat members. + can_invite_users (``bool``, *optional*): + Pass True, if the administrator can invite new users to the chat. + can_pin_messages (``bool``, *optional*): Pass True, if the administrator can pin messages, supergroups only. @@ -82,17 +83,15 @@ class PromoteChatMember(BaseClient): functions.channels.EditAdmin( channel=self.resolve_peer(chat_id), user_id=self.resolve_peer(user_id), - admin_rights=types.ChannelAdminRights( + admin_rights=types.ChatAdminRights( change_info=can_change_info or None, post_messages=can_post_messages or None, edit_messages=can_edit_messages or None, delete_messages=can_delete_messages or None, ban_users=can_restrict_members or None, invite_users=can_invite_users or None, - invite_link=can_invite_users or None, pin_messages=can_pin_messages or None, add_admins=can_promote_members or None, - manage_call=None ) ) ) diff --git a/pyrogram/client/methods/chats/restrict_chat_member.py b/pyrogram/client/methods/chats/restrict_chat_member.py index dbe0054b..f3e43df3 100644 --- a/pyrogram/client/methods/chats/restrict_chat_member.py +++ b/pyrogram/client/methods/chats/restrict_chat_member.py @@ -98,7 +98,7 @@ class RestrictChatMember(BaseClient): functions.channels.EditBanned( channel=self.resolve_peer(chat_id), user_id=self.resolve_peer(user_id), - banned_rights=types.ChannelBannedRights( + banned_rights=types.ChatBannedRights( until_date=until_date, send_messages=send_messages, send_media=send_media, diff --git a/pyrogram/client/methods/chats/unban_chat_member.py b/pyrogram/client/methods/chats/unban_chat_member.py index da706a1f..4c68b14f 100644 --- a/pyrogram/client/methods/chats/unban_chat_member.py +++ b/pyrogram/client/methods/chats/unban_chat_member.py @@ -48,7 +48,7 @@ class UnbanChatMember(BaseClient): functions.channels.EditBanned( channel=self.resolve_peer(chat_id), user_id=self.resolve_peer(user_id), - banned_rights=types.ChannelBannedRights( + banned_rights=types.ChatBannedRights( until_date=0 ) ) From 249e4053395765fa0390061aff95be03e7963e84 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 3 Feb 2019 11:03:11 +0100 Subject: [PATCH 07/10] Update API schema to Layer 95 --- compiler/api/source/main_api.tl | 23 ++++++++++++++--------- pyrogram/client/client.py | 7 ++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 7bbf15e7..8ad94a4e 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -187,7 +187,7 @@ peerNotifySettings#af509d20 flags:# show_previews:flags.0?Bool silent:flags.1?Bo peerSettings#818426cd flags:# report_spam:flags.0?true = PeerSettings; -wallPaper#f04f91ec id:long flags:# creator:flags.0?true default:flags.1?true access_hash:long slug:string document:Document = WallPaper; +wallPaper#a437c3ed id:long flags:# creator:flags.0?true default:flags.1?true pattern:flags.3?true dark:flags.4?true access_hash:long slug:string document:Document settings:flags.2?WallPaperSettings = WallPaper; inputReportReasonSpam#58dbcab8 = ReportReason; inputReportReasonViolence#1e22c78d = ReportReason; @@ -981,6 +981,10 @@ inputWallPaperSlug#72091c80 slug:string = InputWallPaper; account.wallPapersNotModified#1c199183 = account.WallPapers; account.wallPapers#702b65a9 hash:int wallpapers:Vector = account.WallPapers; +codeSettings#302f59f3 flags:# allow_flashcall:flags.0?true current_number:flags.1?true app_hash_persistent:flags.2?true app_hash:flags.3?string = CodeSettings; + +wallPaperSettings#a12f40b8 flags:# blur:flags.1?true motion:flags.2?true background_color:flags.0?int intensity:flags.3?int = WallPaperSettings; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -991,7 +995,7 @@ invokeWithoutUpdates#bf9459b7 {X:Type} query:!X = X; invokeWithMessagesRange#365275f2 {X:Type} range:MessageRange query:!X = X; invokeWithTakeout#aca9fd2e {X:Type} takeout_id:long query:!X = X; -auth.sendCode#86aef0ec flags:# allow_flashcall:flags.0?true phone_number:string current_number:flags.0?Bool api_id:int api_hash:string = auth.SentCode; +auth.sendCode#a677244f phone_number:string api_id:int api_hash:string settings:CodeSettings = auth.SentCode; auth.signUp#1b067634 phone_number:string phone_code_hash:string phone_code:string first_name:string last_name:string = auth.Authorization; auth.signIn#bcd51581 phone_number:string phone_code_hash:string phone_code:string = auth.Authorization; auth.logOut#5717da40 = Bool; @@ -1023,7 +1027,7 @@ account.setPrivacy#c9f81ce8 key:InputPrivacyKey rules:Vector = account.deleteAccount#418d4e0b reason:string = Bool; account.getAccountTTL#8fc711d = AccountDaysTTL; account.setAccountTTL#2442485e ttl:AccountDaysTTL = Bool; -account.sendChangePhoneCode#8e57deb flags:# allow_flashcall:flags.0?true phone_number:string current_number:flags.0?Bool = auth.SentCode; +account.sendChangePhoneCode#82574ae5 phone_number:string settings:CodeSettings = auth.SentCode; account.changePhone#70c32edb phone_number:string phone_code_hash:string phone_code:string = User; account.updateDeviceLocked#38df3532 period:int = Bool; account.getAuthorizations#e320c158 = account.Authorizations; @@ -1031,7 +1035,7 @@ account.resetAuthorization#df77f3bc hash:long = Bool; account.getPassword#548a30f5 = account.Password; account.getPasswordSettings#9cd4eaf9 password:InputCheckPasswordSRP = account.PasswordSettings; account.updatePasswordSettings#a59b102f password:InputCheckPasswordSRP new_settings:account.PasswordInputSettings = Bool; -account.sendConfirmPhoneCode#1516d7bd flags:# allow_flashcall:flags.0?true hash:string current_number:flags.0?Bool = auth.SentCode; +account.sendConfirmPhoneCode#1b3faa88 hash:string settings:CodeSettings = auth.SentCode; account.confirmPhone#5f2178c3 phone_code_hash:string phone_code:string = Bool; account.getTmpPassword#449e0b51 password:InputCheckPasswordSRP period:int = account.TmpPassword; account.getWebAuthorizations#182e6d6f = account.WebAuthorizations; @@ -1043,7 +1047,7 @@ account.saveSecureValue#899fe31d value:InputSecureValue secure_secret_id:long = account.deleteSecureValue#b880bc4b types:Vector = Bool; account.getAuthorizationForm#b86ba8e1 bot_id:int scope:string public_key:string = account.AuthorizationForm; account.acceptAuthorization#e7027c94 bot_id:int scope:string public_key:string value_hashes:Vector credentials:SecureCredentialsEncrypted = Bool; -account.sendVerifyPhoneCode#823380b4 flags:# allow_flashcall:flags.0?true phone_number:string current_number:flags.0?Bool = auth.SentCode; +account.sendVerifyPhoneCode#a5a356f9 phone_number:string settings:CodeSettings = auth.SentCode; account.verifyPhone#4dd3a7f6 phone_number:string phone_code_hash:string phone_code:string = Bool; account.sendVerifyEmailCode#7011509f email:string = account.SentEmailCode; account.verifyEmail#ecba39db email:string code:string = Bool; @@ -1055,10 +1059,11 @@ account.cancelPasswordEmail#c1cbd5b6 = Bool; account.getContactSignUpNotification#9f07c728 = Bool; account.setContactSignUpNotification#cff43f61 silent:Bool = Bool; account.getNotifyExceptions#53577479 flags:# compare_sound:flags.1?true peer:flags.0?InputNotifyPeer = Updates; -account.uploadWallPaper#c7ba9b4d file:InputFile mime_type:string = WallPaper; account.getWallPaper#fc8ddbea wallpaper:InputWallPaper = WallPaper; -account.saveWallPaper#189581b3 wallpaper:InputWallPaper unsave:Bool = Bool; -account.installWallPaper#4a0378ce wallpaper:InputWallPaper = Bool; +account.uploadWallPaper#dd853661 file:InputFile mime_type:string settings:WallPaperSettings = WallPaper; +account.saveWallPaper#6c5a5b37 wallpaper:InputWallPaper unsave:Bool settings:WallPaperSettings = Bool; +account.installWallPaper#feed5769 wallpaper:InputWallPaper settings:WallPaperSettings = Bool; +account.resetWallPapers#bb3b9804 = Bool; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#ca30a5b1 id:InputUser = UserFull; @@ -1287,4 +1292,4 @@ langpack.getDifference#9d51e814 lang_code:string from_version:int = LangPackDiff langpack.getLanguages#42c6978f lang_pack:string = Vector; langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLanguage; -// LAYER 93 +// LAYER 95 diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 576dea9a..eba52b44 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -530,9 +530,10 @@ class Client(Methods, BaseClient): try: r = self.send( functions.auth.SendCode( - self.phone_number, - self.api_id, - self.api_hash + phone_number=self.phone_number, + api_id=self.api_id, + api_hash=self.api_hash, + settings=types.CodeSettings() ) ) except (PhoneMigrate, NetworkMigrate) as e: From 0aee909c1a8b8c6238b59cdc01a82c4db609bf0e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Mar 2019 11:34:40 +0100 Subject: [PATCH 08/10] Update API schema (Layer 95 patch) --- compiler/api/source/main_api.tl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index 8ad94a4e..eb7777c8 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -83,7 +83,7 @@ fileLocationUnavailable#7c596b46 volume_id:long local_id:int secret:long = FileL fileLocation#91d11eb dc_id:int volume_id:long local_id:int secret:long file_reference:bytes = FileLocation; userEmpty#200250ba id:int = User; -user#2e13f4c3 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?string bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User; +user#2e13f4c3 flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true id:int access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?string bot_inline_placeholder:flags.19?string lang_code:flags.22?string = User; userProfilePhotoEmpty#4f11bae1 = UserProfilePhoto; userProfilePhoto#d559d8c8 photo_id:long photo_small:FileLocation photo_big:FileLocation = UserProfilePhoto; @@ -1288,7 +1288,7 @@ phone.saveCallDebug#277add7e peer:InputPhoneCall debug:DataJSON = Bool; langpack.getLangPack#f2f2330a lang_pack:string lang_code:string = LangPackDifference; langpack.getStrings#efea3803 lang_pack:string lang_code:string keys:Vector = Vector; -langpack.getDifference#9d51e814 lang_code:string from_version:int = LangPackDifference; +langpack.getDifference#cd984aa5 lang_pack:string lang_code:string from_version:int = LangPackDifference; langpack.getLanguages#42c6978f lang_pack:string = Vector; langpack.getLanguage#6a596502 lang_pack:string lang_code:string = LangPackLanguage; From 8c9e5e6753674f6caa4f829e3cce3e3322e1efd5 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Mar 2019 12:14:08 +0100 Subject: [PATCH 09/10] Fix PhotoSize parsing --- pyrogram/client/types/messages_and_media/photo_size.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/types/messages_and_media/photo_size.py b/pyrogram/client/types/messages_and_media/photo_size.py index e1be74df..116b564c 100644 --- a/pyrogram/client/types/messages_and_media/photo_size.py +++ b/pyrogram/client/types/messages_and_media/photo_size.py @@ -81,6 +81,6 @@ class PhotoSize(PyrogramType): ), width=getattr(photo_size, "w", 0), height=getattr(photo_size, "h", 0), - file_size=getattr(photo_size, "size", len(photo_size.bytes)), + file_size=getattr(photo_size, "size", len(getattr(photo_size, "bytes", b""))), client=client ) From b6038c4f2e8be79bca5d64a445a65247f73d1934 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 13 Mar 2019 13:02:40 +0100 Subject: [PATCH 10/10] Update Chat and ChatPermissions to accommodate default chat permissions --- pyrogram/client/types/user_and_chats/chat.py | 18 ++++++---------- .../types/user_and_chats/chat_permissions.py | 21 +++++++++++++------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index 89498bd2..96b80bc4 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -18,6 +18,7 @@ import pyrogram from pyrogram.api import types +from .chat_permissions import ChatPermissions from .chat_photo import ChatPhoto from ..pyrogram_type import PyrogramType @@ -44,9 +45,6 @@ class Chat(PyrogramType): last_name (``str``, *optional*): Last name of the other party in a private chat. - all_members_are_administrators (``bool``, *optional*): - True if a basic group has "All Members Are Admins" enabled. - photo (:obj:`ChatPhoto `, *optional*): Chat photo. Suitable for downloads only. @@ -86,7 +84,6 @@ class Chat(PyrogramType): username: str = None, first_name: str = None, last_name: str = None, - all_members_are_administrators: bool = None, photo: ChatPhoto = None, description: str = None, invite_link: str = None, @@ -94,7 +91,8 @@ class Chat(PyrogramType): sticker_set_name: str = None, can_set_sticker_set: bool = None, members_count: int = None, - restriction_reason: str = None): + restriction_reason: str = None, + default_permissions: "pyrogram.ChatPermissions" = None): super().__init__(client) self.id = id @@ -103,7 +101,6 @@ class Chat(PyrogramType): self.username = username self.first_name = first_name self.last_name = last_name - self.all_members_are_administrators = all_members_are_administrators self.photo = photo self.description = description self.invite_link = invite_link @@ -112,6 +109,7 @@ class Chat(PyrogramType): self.can_set_sticker_set = can_set_sticker_set self.members_count = members_count self.restriction_reason = restriction_reason + self.default_permissions = default_permissions @staticmethod def _parse_user_chat(client, user: types.User) -> "Chat": @@ -128,17 +126,12 @@ class Chat(PyrogramType): @staticmethod def _parse_chat_chat(client, chat: types.Chat) -> "Chat": - admins_enabled = getattr(chat, "admins_enabled", None) - - if admins_enabled is not None: - admins_enabled = not admins_enabled - return Chat( id=-chat.id, type="group", title=chat.title, - all_members_are_administrators=admins_enabled, photo=ChatPhoto._parse(client, getattr(chat, "photo", None)), + default_permissions=ChatPermissions._parse(chat.default_banned_rights), client=client ) @@ -151,6 +144,7 @@ class Chat(PyrogramType): username=getattr(channel, "username", None), photo=ChatPhoto._parse(client, getattr(channel, "photo", None)), restriction_reason=getattr(channel, "restriction_reason", None), + default_permissions=ChatPermissions._parse(channel.default_banned_rights), client=client ) diff --git a/pyrogram/client/types/user_and_chats/chat_permissions.py b/pyrogram/client/types/user_and_chats/chat_permissions.py index 68b4567e..a931cd7a 100644 --- a/pyrogram/client/types/user_and_chats/chat_permissions.py +++ b/pyrogram/client/types/user_and_chats/chat_permissions.py @@ -138,12 +138,18 @@ class ChatPermissions(PyrogramType): self.can_send_polls = can_send_polls @staticmethod - def _parse(member: Union[types.ChannelParticipantAdmin, types.ChannelParticipantBanned]) -> "ChatPermissions": - if isinstance(member, types.ChannelParticipantAdmin): - permissions = member.admin_rights + def _parse( + entity: Union[ + types.ChannelParticipantAdmin, + types.ChannelParticipantBanned, + types.ChatBannedRights + ] + ) -> "ChatPermissions": + if isinstance(entity, types.ChannelParticipantAdmin): + permissions = entity.admin_rights return ChatPermissions( - can_be_edited=member.can_edit, + can_be_edited=entity.can_edit, can_change_info=permissions.change_info, can_post_messages=permissions.post_messages, can_edit_messages=permissions.edit_messages, @@ -154,8 +160,11 @@ class ChatPermissions(PyrogramType): can_promote_members=permissions.add_admins ) - if isinstance(member, types.ChannelParticipantBanned): - denied_permissions = member.banned_rights # type: types.ChatBannedRights + if isinstance(entity, (types.ChannelParticipantBanned, types.ChatBannedRights)): + if isinstance(entity, types.ChannelParticipantBanned): + denied_permissions = entity.banned_rights # type: types.ChatBannedRights + else: + denied_permissions = entity return ChatPermissions( until_date=0 if denied_permissions.until_date == (1 << 31) - 1 else denied_permissions.until_date,