mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-01-24 08:14:14 +03:00
Fix .get_message_history not working with limit=0
This commit is contained in:
parent
3d6c8915e3
commit
9a12738f0e
|
@ -485,7 +485,16 @@ class TelegramClient(TelegramBareClient):
|
||||||
:return: A tuple containing total message count and two more lists ([messages], [senders]).
|
:return: A tuple containing total message count and two more lists ([messages], [senders]).
|
||||||
Note that the sender can be null if it was not found!
|
Note that the sender can be null if it was not found!
|
||||||
"""
|
"""
|
||||||
|
entity = self.get_input_entity(entity)
|
||||||
limit = float('inf') if limit is None else int(limit)
|
limit = float('inf') if limit is None else int(limit)
|
||||||
|
if limit == 0:
|
||||||
|
# No messages, but we still need to know the total message count
|
||||||
|
result = self(GetHistoryRequest(
|
||||||
|
peer=self.get_input_entity(entity), limit=1,
|
||||||
|
offset_date=None, offset_id=0, max_id=0, min_id=0, add_offset=0
|
||||||
|
))
|
||||||
|
return getattr(result, 'count', len(result.messages)), [], []
|
||||||
|
|
||||||
total_messages = 0
|
total_messages = 0
|
||||||
messages = []
|
messages = []
|
||||||
entities = {}
|
entities = {}
|
||||||
|
@ -493,7 +502,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
# Telegram has a hard limit of 100
|
# Telegram has a hard limit of 100
|
||||||
real_limit = min(limit - len(messages), 100)
|
real_limit = min(limit - len(messages), 100)
|
||||||
result = self(GetHistoryRequest(
|
result = self(GetHistoryRequest(
|
||||||
peer=self.get_input_entity(entity),
|
peer=entity,
|
||||||
limit=real_limit,
|
limit=real_limit,
|
||||||
offset_date=offset_date,
|
offset_date=offset_date,
|
||||||
offset_id=offset_id,
|
offset_id=offset_id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user