mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-23 01:46:35 +03:00
Add an additional check to avoid duplicate iter_messages
This commit is contained in:
parent
cffef411b2
commit
129f5bf1f8
|
@ -1137,6 +1137,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
wait_time = 1 if limit > 3000 else 0
|
wait_time = 1 if limit > 3000 else 0
|
||||||
|
|
||||||
have = 0
|
have = 0
|
||||||
|
last_id = float('inf')
|
||||||
batch_size = min(max(batch_size, 1), 100)
|
batch_size = min(max(batch_size, 1), 100)
|
||||||
while have < limit:
|
while have < limit:
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
@ -1150,9 +1151,15 @@ class TelegramClient(TelegramBareClient):
|
||||||
for x in itertools.chain(r.users, r.chats)}
|
for x in itertools.chain(r.users, r.chats)}
|
||||||
|
|
||||||
for message in r.messages:
|
for message in r.messages:
|
||||||
if isinstance(message, MessageEmpty):
|
if isinstance(message, MessageEmpty) or message.id >= last_id:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# There has been reports that on bad connections this method
|
||||||
|
# was returning duplicated IDs sometimes. Using ``last_id``
|
||||||
|
# is an attempt to avoid these duplicates, since the message
|
||||||
|
# IDs are returned in descending order.
|
||||||
|
last_id = message.id
|
||||||
|
|
||||||
# Add a few extra attributes to the Message to be friendlier.
|
# Add a few extra attributes to the Message to be friendlier.
|
||||||
# To make messages more friendly, always add message
|
# To make messages more friendly, always add message
|
||||||
# to service messages, and action to normal messages.
|
# to service messages, and action to normal messages.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user