1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19+ import logging
20+ import time
21+
1922import pyrogram
2023from pyrogram .api import functions , types
24+ from pyrogram .api .errors import FloodWait
2125from ...ext import BaseClient
2226
27+ log = logging .getLogger (__name__ )
28+
2329
2430class GetDialogs (BaseClient ):
2531 def get_dialogs (self ,
@@ -29,6 +35,7 @@ def get_dialogs(self,
2935 """Use this method to get the user's dialogs
3036
3137 You can get up to 100 dialogs at once.
38+ For a more convenient way of getting a user's dialogs see :meth:`iter_dialogs`.
3239
3340 Args:
3441 offset_date (``int``):
@@ -50,18 +57,25 @@ def get_dialogs(self,
5057 :class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
5158 """
5259
53- if pinned_only :
54- r = self .send (functions .messages .GetPinnedDialogs ())
55- else :
56- r = self .send (
57- functions .messages .GetDialogs (
58- offset_date = offset_date ,
59- offset_id = 0 ,
60- offset_peer = types .InputPeerEmpty (),
61- limit = limit ,
62- hash = 0 ,
63- exclude_pinned = True
64- )
65- )
60+ while True :
61+ try :
62+ if pinned_only :
63+ r = self .send (functions .messages .GetPinnedDialogs ())
64+ else :
65+ r = self .send (
66+ functions .messages .GetDialogs (
67+ offset_date = offset_date ,
68+ offset_id = 0 ,
69+ offset_peer = types .InputPeerEmpty (),
70+ limit = limit ,
71+ hash = 0 ,
72+ exclude_pinned = True
73+ )
74+ )
75+ except FloodWait as e :
76+ log .warning ("Sleeping {}s" .format (e .x ))
77+ time .sleep (e .x )
78+ else :
79+ break
6680
6781 return pyrogram .Dialogs ._parse (self , r )
0 commit comments