From a0eb824e87546596d8534105c2d37d38841f5e64 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 20 Jun 2018 12:03:42 +0200 Subject: [PATCH] Support ignore_migrated in iter_dialogs --- telethon/client/dialogs.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/telethon/client/dialogs.py b/telethon/client/dialogs.py index 1adb9ba2..6a34bf99 100644 --- a/telethon/client/dialogs.py +++ b/telethon/client/dialogs.py @@ -15,7 +15,8 @@ class DialogMethods(UserMethods): @async_generator async def iter_dialogs( self, limit=None, offset_date=None, offset_id=0, - offset_peer=types.InputPeerEmpty(), _total=None): + offset_peer=types.InputPeerEmpty(), ignore_migrated=False, + _total=None): """ Returns an iterator over the dialogs, yielding 'limit' at most. Dialogs are the open "chats" or conversations with other people, @@ -38,6 +39,12 @@ class DialogMethods(UserMethods): offset_peer (:tl:`InputPeer`, optional): The peer to be used as an offset. + ignore_migrated (`bool`, optional): + Whether :tl:`Chat` that have ``migrated_to`` a :tl:`Channel` + should be included or not. By default all the chats in your + dialogs are returned, but setting this to ``True`` will hide + them in the same way official applications do. + _total (`list`, optional): A single-item list to pass the total parameter by reference. @@ -84,7 +91,10 @@ class DialogMethods(UserMethods): peer_id = utils.get_peer_id(d.peer) if peer_id not in seen: seen.add(peer_id) - await yield_(custom.Dialog(self, d, entities, messages)) + cd = custom.Dialog(self, d, entities, messages) + if not ignore_migrated or getattr( + cd.entity, 'migrated_to', None) is None: + await yield_(cd) if len(r.dialogs) < req.limit\ or not isinstance(r, types.messages.DialogsSlice):