File tree Expand file tree Collapse file tree
pyrogram/client/methods/messages Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
1919import logging
20- import time
2120from typing import Union
2221
2322from pyrogram .api import types , functions
2423from pyrogram .client .ext import BaseClient
25- from pyrogram .errors import FloodWait
2624
2725log = logging .getLogger (__name__ )
2826
@@ -51,34 +49,20 @@ def get_history_count(
5149 RPCError: In case of a Telegram RPC error.
5250 """
5351
54- peer = self .resolve_peer (chat_id )
55-
56- if not isinstance (peer , types .InputPeerChannel ):
57- offset = 0
58- limit = 100
59-
60- while True :
61- try :
62- r = self .send (
63- functions .messages .GetHistory (
64- peer = peer ,
65- offset_id = 1 ,
66- offset_date = 0 ,
67- add_offset = - offset - limit ,
68- limit = limit ,
69- max_id = 0 ,
70- min_id = 0 ,
71- hash = 0
72- )
73- )
74- except FloodWait as e :
75- log .warning ("Sleeping for {}s" .format (e .x ))
76- time .sleep (e .x )
77- continue
78-
79- if not r .messages :
80- return offset
81-
82- offset += len (r .messages )
83-
84- return self .get_history (chat_id = chat_id , limit = 1 ).total_count
52+ r = self .send (
53+ functions .messages .GetHistory (
54+ peer = self .resolve_peer (chat_id ),
55+ offset_id = 0 ,
56+ offset_date = 0 ,
57+ add_offset = 0 ,
58+ limit = 1 ,
59+ max_id = 0 ,
60+ min_id = 0 ,
61+ hash = 0
62+ )
63+ )
64+
65+ if isinstance (r , types .messages .Messages ):
66+ return len (r .messages )
67+ else :
68+ return r .count
You can’t perform that action at this time.
0 commit comments