From 44442a842301069665c5d8af6e0b550687dfc6e8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 29 Jun 2018 01:12:08 +0200 Subject: [PATCH 01/14] Update API scheme to Layer 82 --- compiler/api/source/main_api.tl | 44 ++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/compiler/api/source/main_api.tl b/compiler/api/source/main_api.tl index d1f2fa33..9ee01cb3 100644 --- a/compiler/api/source/main_api.tl +++ b/compiler/api/source/main_api.tl @@ -36,7 +36,7 @@ inputMediaEmpty#9664f57f = InputMedia; inputMediaUploadedPhoto#1e287d04 flags:# file:InputFile stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; inputMediaPhoto#b3ba0635 flags:# id:InputPhoto ttl_seconds:flags.0?int = InputMedia; inputMediaGeoPoint#f9c44144 geo_point:InputGeoPoint = InputMedia; -inputMediaContact#a6e45987 phone_number:string first_name:string last_name:string = InputMedia; +inputMediaContact#f8ab7dfb phone_number:string first_name:string last_name:string vcard:string = InputMedia; inputMediaUploadedDocument#5b38c6c1 flags:# nosound_video:flags.3?true file:InputFile thumb:flags.2?InputFile mime_type:string attributes:Vector stickers:flags.0?Vector ttl_seconds:flags.1?int = InputMedia; inputMediaDocument#23ab23d2 flags:# id:InputDocument ttl_seconds:flags.0?int = InputMedia; inputMediaVenue#c13d1c11 geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string = InputMedia; @@ -61,6 +61,7 @@ inputFileLocation#14637196 volume_id:long local_id:int secret:long = InputFileLo inputEncryptedFileLocation#f5235d55 id:long access_hash:long = InputFileLocation; inputDocumentFileLocation#430f0724 id:long access_hash:long version:int = InputFileLocation; inputSecureFileLocation#cbc7ee28 id:long access_hash:long = InputFileLocation; +inputTakeoutFileLocation#29be5899 = InputFileLocation; inputAppEvent#770656a8 time:double type:string peer:long data:string = InputAppEvent; @@ -121,7 +122,7 @@ messageService#9e19a1f6 flags:# out:flags.1?true mentioned:flags.4?true media_un messageMediaEmpty#3ded6320 = MessageMedia; messageMediaPhoto#695150d7 flags:# photo:flags.0?Photo ttl_seconds:flags.2?int = MessageMedia; messageMediaGeo#56e0d474 geo:GeoPoint = MessageMedia; -messageMediaContact#5e7d2f39 phone_number:string first_name:string last_name:string user_id:int = MessageMedia; +messageMediaContact#cbf24940 phone_number:string first_name:string last_name:string vcard:string user_id:int = MessageMedia; messageMediaUnsupported#9f84f49e = MessageMedia; messageMediaDocument#9cb070d7 flags:# document:flags.0?Document ttl_seconds:flags.2?int = MessageMedia; messageMediaWebPage#a32dd600 webpage:WebPage = MessageMedia; @@ -153,7 +154,7 @@ messageActionBotAllowed#abe9affe domain:string = MessageAction; messageActionSecureValuesSentMe#1b287353 values:Vector credentials:SecureCredentialsEncrypted = MessageAction; messageActionSecureValuesSent#d95c6154 types:Vector = MessageAction; -dialog#e4def5db flags:# pinned:flags.2?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage = Dialog; +dialog#e4def5db flags:# pinned:flags.2?true unread_mark:flags.3?true peer:Peer top_message:int read_inbox_max_id:int read_outbox_max_id:int unread_count:int unread_mentions_count:int notify_settings:PeerNotifySettings pts:flags.0?int draft:flags.1?DraftMessage = Dialog; photoEmpty#2331b22d id:long = Photo; photo#9288dd29 flags:# has_stickers:flags.0?true id:long access_hash:long date:int sizes:Vector = Photo; @@ -163,7 +164,7 @@ photoSize#77bfb61b type:string location:FileLocation w:int h:int size:int = Phot photoCachedSize#e9a734fa type:string location:FileLocation w:int h:int bytes:bytes = PhotoSize; geoPointEmpty#1117dd5f = GeoPoint; -geoPoint#2049d70c long:double lat:double = GeoPoint; +geoPoint#296f104 long:double lat:double access_hash:long = GeoPoint; auth.checkedPhone#811ea28e phone_registered:Bool = auth.CheckedPhone; @@ -213,6 +214,7 @@ contacts.blockedSlice#900802a1 count:int blocked:Vector users:Ve messages.dialogs#15ba6c40 dialogs:Vector messages:Vector chats:Vector users:Vector = messages.Dialogs; messages.dialogsSlice#71e094f3 count:int dialogs:Vector messages:Vector chats:Vector users:Vector = messages.Dialogs; +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; @@ -309,6 +311,7 @@ updateFavedStickers#e511996d = Update; updateChannelReadMessagesContents#89893b45 channel_id:int messages:Vector = Update; updateContactsReset#7084a7be = Update; updateChannelAvailableMessages#70db6837 channel_id:int available_min_id:int = Update; +updateDialogUnreadMark#e16459c3 flags:# unread:flags.0?true peer:DialogPeer = Update; updates.state#a56c2a3e pts:int qts:int date:int seq:int unread_count:int = updates.State; @@ -335,7 +338,7 @@ upload.fileCdnRedirect#f18cda44 dc_id:int file_token:bytes encryption_key:bytes dcOption#18b7a10d flags:# ipv6:flags.0?true media_only:flags.1?true tcpo_only:flags.2?true cdn:flags.3?true static:flags.4?true id:int ip_address:string port:int secret:flags.10?bytes = DcOption; -config#eb7bb160 flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config; +config#3213dbba flags:# phonecalls_enabled:flags.1?true default_p2p_contacts:flags.3?true preload_featured_stickers:flags.4?true ignore_phone_entities:flags.5?true revoke_pm_inbox:flags.6?true blocked_mode:flags.8?true date:int expires:int test_mode:Bool this_dc:int dc_options:Vector dc_txt_domain_name:string chat_size_max:int megagroup_size_max:int forwarded_count_max:int online_update_period_ms:int offline_blur_timeout_ms:int offline_idle_timeout_ms:int online_cloud_timeout_ms:int notify_cloud_delay_ms:int notify_default_delay_ms:int push_chat_period_ms:int push_chat_limit:int saved_gifs_limit:int edit_time_limit:int revoke_time_limit:int revoke_pm_time_limit:int rating_e_decay:int stickers_recent_limit:int stickers_faved_limit:int channels_read_media_period:int tmp_sessions:flags.0?int pinned_dialogs_count_max:int call_receive_timeout_ms:int call_ring_timeout_ms:int call_connect_timeout_ms:int call_packet_timeout_ms:int me_url_prefix:string autoupdate_url_prefix:flags.7?string gif_search_username:flags.9?string venue_search_username:flags.10?string img_search_username:flags.11?string static_maps_provider:flags.12?string caption_length_max:int message_length_max:int webfile_dc_id:int suggested_lang_code:flags.2?string lang_pack_version:flags.2?int = Config; nearestDc#8e1a1775 country:string this_dc:int nearest_dc:int = NearestDc; @@ -562,7 +565,7 @@ inputBotInlineMessageMediaAuto#3380c786 flags:# message:string entities:flags.1? inputBotInlineMessageText#3dcd7a87 flags:# no_webpage:flags.0?true message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageMediaGeo#c1b15d65 flags:# geo_point:InputGeoPoint period:int reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageMediaVenue#417bbf11 flags:# geo_point:InputGeoPoint title:string address:string provider:string venue_id:string venue_type:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; -inputBotInlineMessageMediaContact#2daf01a7 flags:# phone_number:string first_name:string last_name:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; +inputBotInlineMessageMediaContact#a6edbffd flags:# phone_number:string first_name:string last_name:string vcard:string reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineMessageGame#4b425864 flags:# reply_markup:flags.2?ReplyMarkup = InputBotInlineMessage; inputBotInlineResult#88bf9319 flags:# id:string type:string title:flags.1?string description:flags.2?string url:flags.3?string thumb:flags.4?InputWebDocument content:flags.5?InputWebDocument send_message:InputBotInlineMessage = InputBotInlineResult; @@ -574,7 +577,7 @@ botInlineMessageMediaAuto#764cf810 flags:# message:string entities:flags.1?Vecto botInlineMessageText#8c7f65e2 flags:# no_webpage:flags.0?true message:string entities:flags.1?Vector reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineMessageMediaGeo#b722de65 flags:# geo:GeoPoint period:int reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineMessageMediaVenue#8a86659c flags:# geo:GeoPoint title:string address:string provider:string venue_id:string venue_type:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; -botInlineMessageMediaContact#35edb4d4 flags:# phone_number:string first_name:string last_name:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; +botInlineMessageMediaContact#18d1cdc2 flags:# phone_number:string first_name:string last_name:string vcard:string reply_markup:flags.2?ReplyMarkup = BotInlineMessage; botInlineResult#11965f3a flags:# id:string type:string title:flags.1?string description:flags.2?string url:flags.3?string thumb:flags.4?WebDocument content:flags.5?WebDocument send_message:BotInlineMessage = BotInlineResult; botInlineMediaResult#17db940b flags:# id:string type:string photo:flags.0?Photo document:flags.1?Document title:flags.2?string description:flags.3?string send_message:BotInlineMessage = BotInlineResult; @@ -617,8 +620,9 @@ topPeerCategoryPeers#fb834291 category:TopPeerCategory count:int peers:Vector chats:Vector users:Vector = contacts.TopPeers; +contacts.topPeersDisabled#b52c939d = contacts.TopPeers; -draftMessageEmpty#ba4baec5 = DraftMessage; +draftMessageEmpty#1b0c841a flags:# date:flags.0?int = DraftMessage; draftMessage#fd8e711f flags:# no_webpage:flags.1?true reply_to_msg_id:flags.0?int message:string entities:flags.3?Vector date:int = DraftMessage; messages.featuredStickersNotModified#4ede3cf = messages.FeaturedStickers; @@ -706,14 +710,13 @@ paymentRequestedInfo#909c3f94 flags:# name:flags.0?string phone:flags.1?string e paymentSavedCredentialsCard#cdc27a1f id:string title:string = PaymentSavedCredentials; -webDocument#c61acbd8 url:string access_hash:long size:int mime_type:string attributes:Vector dc_id:int = WebDocument; +webDocument#1c570ed1 url:string access_hash:long size:int mime_type:string attributes:Vector = WebDocument; webDocumentNoProxy#f9c8bcc6 url:string size:int mime_type:string attributes:Vector = WebDocument; inputWebDocument#9bed434d url:string size:int mime_type:string attributes:Vector = InputWebDocument; inputWebFileLocation#c239d686 url:string access_hash:long = InputWebFileLocation; -inputWebFileGeoPointLocation#66275a62 geo_point:InputGeoPoint w:int h:int zoom:int scale:int = InputWebFileLocation; -inputWebFileGeoMessageLocation#553f32eb peer:InputPeer msg_id:int w:int h:int zoom:int scale:int = InputWebFileLocation; +inputWebFileGeoPointLocation#9f2221c9 geo_point:InputGeoPoint access_hash:long w:int h:int zoom:int scale:int = InputWebFileLocation; upload.webFile#21e753bc size:int mime_type:string file_type:storage.FileType mtime:int bytes:bytes = upload.WebFile; @@ -883,6 +886,10 @@ account.sentEmailCode#811f854f email_pattern:string length:int = account.SentEma help.deepLinkInfoEmpty#66afa166 = help.DeepLinkInfo; help.deepLinkInfo#6a4ee832 flags:# update_app:flags.0?true message:string entities:flags.1?Vector = help.DeepLinkInfo; +savedPhoneContact#1142bd56 phone:string first_name:string last_name:string date:int = SavedContact; + +account.takeout#4dba4501 id:long = account.Takeout; + ---functions--- invokeAfterMsg#cb9f372d {X:Type} msg_id:long query:!X = X; @@ -890,13 +897,14 @@ invokeAfterMsgs#3dc4b4f0 {X:Type} msg_ids:Vector query:!X = X; initConnection#785188b8 {X:Type} flags:# api_id:int device_model:string system_version:string app_version:string system_lang_code:string lang_pack:string lang_code:string proxy:flags.0?InputClientProxy query:!X = X; invokeWithLayer#da9b0d0d {X:Type} layer:int query:!X = X; 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.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; auth.resetAuthorizations#9fab0d1a = Bool; -auth.sendInvites#771c1d97 phone_numbers:Vector message:string = Bool; auth.exportAuthorization#e5bfffcd dc_id:int = auth.ExportedAuthorization; auth.importAuthorization#e3ef9613 id:int bytes:bytes = auth.Authorization; auth.bindTempAuthKey#cdd42a05 perm_auth_key_id:long nonce:long expires_at:int encrypted_message:bytes = Bool; @@ -948,6 +956,8 @@ account.sendVerifyPhoneCode#823380b4 flags:# allow_flashcall:flags.0?true phone_ 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; +account.initTakeoutSession#f05b4804 flags:# contacts:flags.0?true message_users:flags.1?true message_chats:flags.2?true message_megagroups:flags.3?true message_channels:flags.4?true files:flags.5?true file_max_size:flags.5?int = account.Takeout; +account.finishTakeoutSession#1d2652ee flags:# success:flags.0?true = Bool; users.getUsers#d91a548 id:Vector = Vector; users.getFullUser#ca30a5b1 id:InputUser = UserFull; @@ -968,9 +978,11 @@ contacts.resolveUsername#f93ccba3 username:string = contacts.ResolvedPeer; contacts.getTopPeers#d4982db5 flags:# correspondents:flags.0?true bots_pm:flags.1?true bots_inline:flags.2?true phone_calls:flags.3?true groups:flags.10?true channels:flags.15?true offset:int limit:int hash:int = contacts.TopPeers; contacts.resetTopPeerRating#1ae373ac category:TopPeerCategory peer:InputPeer = Bool; contacts.resetSaved#879537f1 = Bool; +contacts.getSaved#82f1e39f = Vector; +contacts.toggleTopPeers#8514bdda enabled:Bool = Bool; messages.getMessages#63c66506 id:Vector = messages.Messages; -messages.getDialogs#191ba9c5 flags:# exclude_pinned:flags.0?true offset_date:int offset_id:int offset_peer:InputPeer limit:int = messages.Dialogs; +messages.getDialogs#b098aee6 flags:# exclude_pinned:flags.0?true offset_date:int offset_id:int offset_peer:InputPeer limit:int hash:int = messages.Dialogs; messages.getHistory#dcbb8260 peer:InputPeer offset_id:int offset_date:int add_offset:int limit:int max_id:int min_id:int hash:int = messages.Messages; messages.search#8614ef68 flags:# peer:InputPeer q:string from_id:flags.0?InputUser filter:MessagesFilter min_date:int max_date:int offset_id:int add_offset:int limit:int max_id:int min_id:int hash:int = messages.Messages; messages.readHistory#e306d3a peer:InputPeer max_id:int = messages.AffectedMessages; @@ -1065,6 +1077,9 @@ messages.getRecentLocations#bbc45b09 peer:InputPeer limit:int hash:int = message messages.sendMultiMedia#2095512f flags:# silent:flags.5?true background:flags.6?true clear_draft:flags.7?true peer:InputPeer reply_to_msg_id:flags.0?int multi_media:Vector = Updates; messages.uploadEncryptedFile#5057c497 peer:InputEncryptedChat file:InputEncryptedFile = EncryptedFile; messages.searchStickerSets#c2b7d08b flags:# exclude_featured:flags.0?true q:string hash:int = messages.FoundStickerSets; +messages.getSplitRanges#1cff7e08 = Vector; +messages.markDialogUnread#c286d98f flags:# unread:flags.0?true peer:InputDialogPeer = Bool; +messages.getDialogUnreadMarks#22e24e22 = Vector; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; @@ -1131,6 +1146,7 @@ channels.setStickers#ea8ca4f9 channel:InputChannel stickerset:InputStickerSet = channels.readMessageContents#eab5dc38 channel:InputChannel id:Vector = Bool; channels.deleteHistory#af369d42 channel:InputChannel max_id:int = Bool; channels.togglePreHistoryHidden#eabbb94c channel:InputChannel enabled:Bool = Updates; +channels.getLeftChannels#8341ecc0 offset:int = messages.Chats; bots.sendCustomRequest#aa2769ed custom_method:string params:DataJSON = DataJSON; bots.answerWebhookJSONQuery#e6213f4d query_id:long data:DataJSON = Bool; @@ -1161,4 +1177,4 @@ langpack.getStrings#2e1ee318 lang_code:string keys:Vector = Vector; -// LAYER 81 +// LAYER 82 From 29fb0ce599ba67b6aeb532be5350970ece7951a8 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 13:18:20 +0200 Subject: [PATCH 02/14] Also log UpdatesTooLong --- pyrogram/client/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 92666ce5..230d4bef 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -839,6 +839,8 @@ class Client(Methods, BaseClient): self.dispatcher.updates.put((diff.other_updates[0], [], [])) elif isinstance(updates, types.UpdateShort): self.dispatcher.updates.put((updates.update, [], [])) + elif isinstance(updates, types.UpdatesTooLong): + log.warning(updates) except Exception as e: log.error(e, exc_info=True) From c7489cf30203b4780e141862d75103154f0a590a Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 14:03:14 +0200 Subject: [PATCH 03/14] Reformat code --- pyrogram/client/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 230d4bef..e4fb0cc6 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -777,7 +777,7 @@ class Client(Methods, BaseClient): pts = getattr(update, "pts", None) pts_count = getattr(update, "pts_count", None) - + if isinstance(update, types.UpdateChannelTooLong): log.warning(update) From 8bdccda6eed7ada1f3ef83c78606dad563998fbe Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 14:03:45 +0200 Subject: [PATCH 04/14] Fix GetDialog call --- pyrogram/client/client.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index e4fb0cc6..a0f51d84 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -983,8 +983,12 @@ class Client(Methods, BaseClient): try: r = self.send( functions.messages.GetDialogs( - offset_date, 0, types.InputPeerEmpty(), - self.DIALOGS_AT_ONCE, True + offset_date=offset_date, + offset_id=0, + offset_peer=types.InputPeerEmpty(), + limit=self.DIALOGS_AT_ONCE, + hash=0, + exclude_pinned=True ) ) except FloodWait as e: From 52f1f390ca7721a8676b0c89b4fc0c49c7de85d9 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 20:59:21 +0200 Subject: [PATCH 05/14] Rename get_dialogs --- pyrogram/client/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index a0f51d84..d7768c86 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -231,7 +231,7 @@ class Client(Methods, BaseClient): self.peers_by_username = {} self.peers_by_phone = {} - self.get_dialogs() + self.get_initial_dialogs() self.get_contacts() else: self.send(functions.messages.GetPinnedDialogs()) @@ -998,7 +998,7 @@ class Client(Methods, BaseClient): log.info("Total peers: {}".format(len(self.peers_by_id))) return r - def get_dialogs(self): + def get_initial_dialogs(self): self.send(functions.messages.GetPinnedDialogs()) dialogs = self.get_dialogs_chunk(0) From 1d7c857e9f31a9ab7afc702c4d1f3147389987a0 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:02:26 +0200 Subject: [PATCH 06/14] Rename get_dialogs --- pyrogram/client/client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index d7768c86..e8cc394f 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -235,7 +235,7 @@ class Client(Methods, BaseClient): self.get_contacts() else: self.send(functions.messages.GetPinnedDialogs()) - self.get_dialogs_chunk(0) + self.get_initial_dialogs_chunk() else: self.send(functions.updates.GetState()) @@ -978,7 +978,7 @@ class Client(Methods, BaseClient): indent=4 ) - def get_dialogs_chunk(self, offset_date): + def get_initial_dialogs_chunk(self, offset_date: int = 0): while True: try: r = self.send( @@ -1001,14 +1001,14 @@ class Client(Methods, BaseClient): def get_initial_dialogs(self): self.send(functions.messages.GetPinnedDialogs()) - dialogs = self.get_dialogs_chunk(0) + dialogs = self.get_initial_dialogs_chunk() offset_date = utils.get_offset_date(dialogs) while len(dialogs.dialogs) == self.DIALOGS_AT_ONCE: - dialogs = self.get_dialogs_chunk(offset_date) + dialogs = self.get_initial_dialogs_chunk(offset_date) offset_date = utils.get_offset_date(dialogs) - self.get_dialogs_chunk(0) + self.get_initial_dialogs_chunk() def resolve_peer(self, peer_id: int or str): """Use this method to get the *InputPeer* of a known *peer_id*. From 2b36fb31d94262a6f43538c23286ec15ff505284 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:03:29 +0200 Subject: [PATCH 07/14] Add Dialog type --- pyrogram/client/types/dialog.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pyrogram/client/types/dialog.py diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/dialog.py new file mode 100644 index 00000000..792360a6 --- /dev/null +++ b/pyrogram/client/types/dialog.py @@ -0,0 +1,28 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class Dialog(Object): + ID = 0xb0700028 + + def __init__(self, id: int, top_message): + # TODO docstrings + self.id = id + self.top_message = top_message From 1ed202b9261b0b831a472adffa287503e2602d60 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:03:51 +0200 Subject: [PATCH 08/14] Add Dialogs type --- pyrogram/client/types/dialogs.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pyrogram/client/types/dialogs.py diff --git a/pyrogram/client/types/dialogs.py b/pyrogram/client/types/dialogs.py new file mode 100644 index 00000000..1e1b0cb2 --- /dev/null +++ b/pyrogram/client/types/dialogs.py @@ -0,0 +1,28 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 pyrogram.api.core import Object + + +class Dialogs(Object): + ID = 0xb0700029 + + def __init__(self, total_count: int, dialogs: list): + # TODO docstrings + self.total_count = total_count + self.dialogs = dialogs From 91cf2d1a8e4377e476e7a2df91a485b76120edf7 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:05:00 +0200 Subject: [PATCH 09/14] Make Dialog and Dialogs importable and printable --- compiler/api/compiler.py | 2 ++ pyrogram/__init__.py | 4 ++-- pyrogram/client/types/__init__.py | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/api/compiler.py b/compiler/api/compiler.py index 7c1412d1..aa5714ec 100644 --- a/compiler/api/compiler.py +++ b/compiler/api/compiler.py @@ -504,6 +504,8 @@ def start(): f.write("\n 0xb0700025: \"pyrogram.client.types.GIF\",") f.write("\n 0xb0700026: \"pyrogram.client.types.Messages\",") f.write("\n 0xb0700027: \"pyrogram.client.types.Photo\",") + f.write("\n 0xb0700028: \"pyrogram.client.types.Dialog\",") + f.write("\n 0xb0700029: \"pyrogram.client.types.Dialogs\",") f.write("\n}\n") diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index b93b57b1..c151ac4a 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -29,8 +29,8 @@ from .api.errors import Error from .client.types import ( Audio, Chat, ChatMember, ChatPhoto, Contact, Document, InputMediaPhoto, InputMediaVideo, InputPhoneContact, Location, Message, MessageEntity, - Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, Venue, GIF, - Video, VideoNote, Voice, CallbackQuery, Messages + Dialog, Dialogs, Photo, PhotoSize, Sticker, Update, User, UserProfilePhotos, + Venue, GIF, Video, VideoNote, Voice, CallbackQuery, Messages ) from .client.types.reply_markup import ( ForceReply, InlineKeyboardButton, InlineKeyboardMarkup, diff --git a/pyrogram/client/types/__init__.py b/pyrogram/client/types/__init__.py index 84c12a44..3c569324 100644 --- a/pyrogram/client/types/__init__.py +++ b/pyrogram/client/types/__init__.py @@ -22,6 +22,8 @@ from .chat import Chat from .chat_member import ChatMember from .chat_photo import ChatPhoto from .contact import Contact +from .dialog import Dialog +from .dialogs import Dialogs from .document import Document from .gif import GIF from .input_media_photo import InputMediaPhoto From 9ac6633cc81b584515a160a78bd0c859c8a72c96 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:05:43 +0200 Subject: [PATCH 10/14] Add get_dialogs method --- pyrogram/client/methods/messages/__init__.py | 2 + .../client/methods/messages/get_dialogs.py | 100 ++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 pyrogram/client/methods/messages/get_dialogs.py diff --git a/pyrogram/client/methods/messages/__init__.py b/pyrogram/client/methods/messages/__init__.py index e2c2462e..94279ffd 100644 --- a/pyrogram/client/methods/messages/__init__.py +++ b/pyrogram/client/methods/messages/__init__.py @@ -21,6 +21,7 @@ from .edit_message_caption import EditMessageCaption from .edit_message_reply_markup import EditMessageReplyMarkup from .edit_message_text import EditMessageText from .forward_messages import ForwardMessages +from .get_dialogs import GetDialogs from .get_history import GetHistory from .get_messages import GetMessages from .send_audio import SendAudio @@ -47,6 +48,7 @@ class Messages( ForwardMessages, GetHistory, GetMessages, + GetDialogs, SendAudio, SendChatAction, SendContact, diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py new file mode 100644 index 00000000..d0ef032b --- /dev/null +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -0,0 +1,100 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-2018 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 . + +import pyrogram +from pyrogram.api import functions, types +from ...ext import BaseClient, utils + + +class GetDialogs(BaseClient): + # TODO docstrings + + def get_dialogs(self, + last_chunk=None, + limit: int = 100): + offset_date = 0 + offset_id = 0 + offset_peer = types.InputPeerEmpty() + + if last_chunk: + for dialog in reversed(last_chunk.dialogs): + top_message = dialog.top_message + + if top_message: + message_date = top_message.date + + if message_date: + offset_id = top_message.message_id + offset_date = message_date + offset_peer = self.resolve_peer(dialog.id) + break + + r = self.send( + functions.messages.GetDialogs( + offset_date=offset_date, + offset_id=offset_id, + offset_peer=offset_peer, + limit=limit, + hash=0, + exclude_pinned=True + ) + ) + + users = {i.id: i for i in r.users} + chats = {i.id: i for i in r.chats} + messages = {} + + for message in r.messages: + if isinstance(message, (types.Message, types.MessageService)): + chat_id = message.to_id + + if isinstance(chat_id, types.PeerUser): + chat_id = chat_id.user_id + elif isinstance(chat_id, types.PeerChat): + chat_id = -chat_id.chat_id + else: + chat_id = int("-100" + str(chat_id.channel_id)) + + messages[chat_id] = utils.parse_messages( + self, message, + users, chats + ) + + dialogs = [] + + for dialog in r.dialogs: + chat_id = dialog.peer + + if isinstance(chat_id, types.PeerUser): + chat_id = chat_id.user_id + elif isinstance(chat_id, types.PeerChat): + chat_id = -chat_id.chat_id + else: + chat_id = int("-100" + str(chat_id.channel_id)) + + dialogs.append( + pyrogram.Dialog( + id=chat_id, + top_message=messages.get(chat_id) + ) + ) + + return pyrogram.Dialogs( + total_count=getattr(r, "count", len(r.dialogs)), + dialogs=dialogs + ) From 51194945c6abf89897436bd4e5ec1f7fb6f351da Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:31:50 +0200 Subject: [PATCH 11/14] Add members_count attribute to Chat --- pyrogram/client/types/chat.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/types/chat.py b/pyrogram/client/types/chat.py index 1455bd0f..9cd7aec7 100644 --- a/pyrogram/client/types/chat.py +++ b/pyrogram/client/types/chat.py @@ -81,7 +81,8 @@ class Chat(Object): invite_link: str = None, pinned_message=None, sticker_set_name: str = None, - can_set_sticker_set: bool = None + can_set_sticker_set: bool = None, + members_count: int = None ): self.id = id self.type = type @@ -96,3 +97,4 @@ class Chat(Object): self.pinned_message = pinned_message self.sticker_set_name = sticker_set_name self.can_set_sticker_set = can_set_sticker_set + self.members_count = members_count From fe97a4d92bf85bcbde4ab79e6b9db79866e038f6 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:32:35 +0200 Subject: [PATCH 12/14] Parse members_count --- pyrogram/client/ext/utils.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index 3f287b49..d236c69a 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -884,8 +884,8 @@ def parse_chat_full( chat_full: types.messages.ChatFull or types.UserFull ) -> pyrogram_types.Chat: if isinstance(chat_full, types.UserFull): - chat = parse_user_chat(chat_full.user) - chat.description = chat_full.about + parsed_chat = parse_user_chat(chat_full.user) + parsed_chat.description = chat_full.about else: full_chat = chat_full.full_chat chat = None @@ -895,21 +895,25 @@ def parse_chat_full( chat = i if isinstance(full_chat, types.ChatFull): - chat = parse_chat_chat(chat) + parsed_chat = parse_chat_chat(chat) + + if isinstance(full_chat.participants, types.ChatParticipants): + parsed_chat.members_count = len(full_chat.participants.participants) else: - chat = parse_channel_chat(chat) - chat.description = full_chat.about or None + parsed_chat = parse_channel_chat(chat) + parsed_chat.members_count = full_chat.participants_count + parsed_chat.description = full_chat.about or None # TODO: Add StickerSet type - chat.can_set_sticker_set = full_chat.can_set_stickers - chat.sticker_set_name = full_chat.stickerset + parsed_chat.can_set_sticker_set = full_chat.can_set_stickers + parsed_chat.sticker_set_name = full_chat.stickerset if full_chat.pinned_msg_id: - chat.pinned_message = client.get_messages( + parsed_chat.pinned_message = client.get_messages( int("-100" + str(full_chat.id)), full_chat.pinned_msg_id ) if isinstance(full_chat.exported_invite, types.ChatInviteExported): - chat.invite_link = full_chat.exported_invite.link + parsed_chat.invite_link = full_chat.exported_invite.link - return chat + return parsed_chat From 15e3cf0fd5ffc6fae9adfa076778b49fff32ef3c Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:39:09 +0200 Subject: [PATCH 13/14] Small fix --- pyrogram/client/ext/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyrogram/client/ext/utils.py b/pyrogram/client/ext/utils.py index d236c69a..f87b9035 100644 --- a/pyrogram/client/ext/utils.py +++ b/pyrogram/client/ext/utils.py @@ -909,7 +909,7 @@ def parse_chat_full( if full_chat.pinned_msg_id: parsed_chat.pinned_message = client.get_messages( - int("-100" + str(full_chat.id)), + parsed_chat.id, full_chat.pinned_msg_id ) From 8b43ad8a63f6b8f15b24399846074c0bba70240f Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Wed, 4 Jul 2018 21:49:11 +0200 Subject: [PATCH 14/14] Add unread messages, mentions count and unread mark to Dialog --- pyrogram/client/methods/messages/get_dialogs.py | 5 ++++- pyrogram/client/types/dialog.py | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/methods/messages/get_dialogs.py b/pyrogram/client/methods/messages/get_dialogs.py index d0ef032b..28687511 100644 --- a/pyrogram/client/methods/messages/get_dialogs.py +++ b/pyrogram/client/methods/messages/get_dialogs.py @@ -90,7 +90,10 @@ class GetDialogs(BaseClient): dialogs.append( pyrogram.Dialog( id=chat_id, - top_message=messages.get(chat_id) + top_message=messages.get(chat_id), + unread_messages_count=dialog.unread_count, + unread_mentions_count=dialog.unread_mentions_count, + unread_mark=dialog.unread_mark ) ) diff --git a/pyrogram/client/types/dialog.py b/pyrogram/client/types/dialog.py index 792360a6..4210f105 100644 --- a/pyrogram/client/types/dialog.py +++ b/pyrogram/client/types/dialog.py @@ -22,7 +22,15 @@ from pyrogram.api.core import Object class Dialog(Object): ID = 0xb0700028 - def __init__(self, id: int, top_message): + def __init__(self, + id: int, + top_message, + unread_messages_count: int, + unread_mentions_count: int, + unread_mark: bool): # TODO docstrings self.id = id self.top_message = top_message + self.unread_messages_count = unread_messages_count + self.unread_mentions_count = unread_mentions_count + self.unread_mark = unread_mark