@@ -28,7 +28,7 @@ async def get_blocked_message_senders(
2828 block_list : "enums.BlockList" = enums .BlockList .MAIN ,
2929 offset : int = 0 ,
3030 limit : int = 0 ,
31- ) -> AsyncGenerator ["types.Chat" ]:
31+ ) -> AsyncGenerator ["types.Chat" , None ]:
3232 """Returns users and chats that were blocked by the current user.
3333
3434 .. include:: /_includes/usable-by/users.rst
@@ -52,24 +52,30 @@ async def get_blocked_message_senders(
5252 print(chat)
5353 """
5454
55+ current = 0
5556 total = abs (limit ) or (1 << 31 ) - 1
5657 limit = min (100 , total )
5758
58- r = await self .invoke (
59- raw .functions .contacts .GetBlocked (
60- offset = offset ,
61- limit = limit ,
62- my_stories_from = block_list == enums .BlockList .STORIES ,
59+ while True :
60+ r = await self .invoke (
61+ raw .functions .contacts .GetBlocked (
62+ offset = offset ,
63+ limit = limit ,
64+ my_stories_from = block_list == enums .BlockList .STORIES ,
65+ )
6366 )
64- )
65-
66- users = {i .id : i for i in r .users }
67- chats = {i .id : i for i in r .chats }
68-
69- for peer in r .blocked :
70- if isinstance (peer .peer_id , raw .types .PeerUser ):
71- yield types .User ._parse (self , users [peer .peer_id .user_id ])
72- elif isinstance (peer .peer_id , raw .types .PeerChat ):
73- yield types .Chat ._parse (self , chats [peer .peer_id .chat_id ])
74- elif isinstance (peer .peer_id , raw .types .PeerChannel ):
75- yield types .Chat ._parse (self , chats [peer .peer_id .channel_id ])
67+
68+ if not r .blocked :
69+ return
70+
71+ users = {i .id : i for i in r .users }
72+ chats = {i .id : i for i in r .chats }
73+
74+ for peer in r .blocked :
75+ yield types .Chat ._parse_chat (self , users [peer .peer_id .user_id ])
76+
77+ current += 1
78+ if current >= total :
79+ return
80+
81+ offset += len (r .blocked )
0 commit comments