File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -279,22 +279,21 @@ def get_dialogs(self,
279279 The peer to be used as an offset.
280280 :return: A tuple of lists ([dialogs], [entities]).
281281 """
282- if limit is None :
283- limit = float ('inf' )
282+ limit = float ('inf' ) if limit is None else int (limit )
283+ if limit == 0 :
284+ return [], []
284285
285286 dialogs = {} # Use peer id as identifier to avoid dupes
286287 messages = {} # Used later for sorting TODO also return these?
287288 entities = {}
288289 while len (dialogs ) < limit :
289- need = limit - len (dialogs )
290+ real_limit = min ( limit - len (dialogs ), 100 )
290291 r = self (GetDialogsRequest (
291292 offset_date = offset_date ,
292293 offset_id = offset_id ,
293294 offset_peer = offset_peer ,
294- limit = need if need < float ( 'inf' ) else 0
295+ limit = real_limit
295296 ))
296- if not r .dialogs :
297- break
298297
299298 for d in r .dialogs :
300299 dialogs [utils .get_peer_id (d .peer , True )] = d
@@ -307,8 +306,9 @@ def get_dialogs(self,
307306 for c in r .chats :
308307 entities [c .id ] = c
309308
310- if not isinstance (r , DialogsSlice ):
311- # Don't enter next iteration if we already got all
309+ if len (r .dialogs ) < real_limit or not isinstance (r , DialogsSlice ):
310+ # Less than we requested means we reached the end, or
311+ # we didn't get a DialogsSlice which means we got all.
312312 break
313313
314314 offset_date = r .messages [- 1 ].date
You can’t perform that action at this time.
0 commit comments