diff --git a/pyrogram/client/methods/chats/get_dialogs.py b/pyrogram/client/methods/chats/get_dialogs.py
index f80518b0..35fc7752 100644
--- a/pyrogram/client/methods/chats/get_dialogs.py
+++ b/pyrogram/client/methods/chats/get_dialogs.py
@@ -16,10 +16,16 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see .
+import logging
+import time
+
import pyrogram
from pyrogram.api import functions, types
+from pyrogram.api.errors import FloodWait
from ...ext import BaseClient
+log = logging.getLogger(__name__)
+
class GetDialogs(BaseClient):
def get_dialogs(self,
@@ -29,6 +35,7 @@ class GetDialogs(BaseClient):
"""Use this method to get the user's dialogs
You can get up to 100 dialogs at once.
+ For a more convenient way of getting a user's dialogs see :meth:`iter_dialogs`.
Args:
offset_date (``int``):
@@ -50,18 +57,25 @@ class GetDialogs(BaseClient):
:class:`Error ` in case of a Telegram RPC error.
"""
- if pinned_only:
- r = self.send(functions.messages.GetPinnedDialogs())
- else:
- r = self.send(
- functions.messages.GetDialogs(
- offset_date=offset_date,
- offset_id=0,
- offset_peer=types.InputPeerEmpty(),
- limit=limit,
- hash=0,
- exclude_pinned=True
- )
- )
+ while True:
+ try:
+ if pinned_only:
+ r = self.send(functions.messages.GetPinnedDialogs())
+ else:
+ r = self.send(
+ functions.messages.GetDialogs(
+ offset_date=offset_date,
+ offset_id=0,
+ offset_peer=types.InputPeerEmpty(),
+ limit=limit,
+ hash=0,
+ exclude_pinned=True
+ )
+ )
+ except FloodWait as e:
+ log.warning("Sleeping {}s".format(e.x))
+ time.sleep(e.x)
+ else:
+ break
return pyrogram.Dialogs._parse(self, r)