Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions scripts/tg_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,19 @@ async def cmd_list(limit: int, since: str = None):
sys.stderr.flush()
chats = []
count = 0
consecutive_old = 0
CONSECUTIVE_OLD_THRESHOLD = 100 # Telethon pages internally in 100s
async for d in client.iter_dialogs(limit=limit):
count += 1
if cutoff and d.date and d.date < cutoff:
sys.stderr.write(f" Stopped at {count} dialogs (reached cutoff {since})\n")
sys.stderr.flush()
break
consecutive_old += 1
if consecutive_old >= CONSECUTIVE_OLD_THRESHOLD:
sys.stderr.write(f" Stopped at {count} dialogs ({CONSECUTIVE_OLD_THRESHOLD} consecutive old, cutoff {since})\n")
sys.stderr.flush()
break
continue # skip this old dialog but keep scanning
else:
consecutive_old = 0 # reset counter on any new dialog
if count % 100 == 0:
sys.stderr.write(f" {count} dialogs...\n")
sys.stderr.flush()
Expand Down
Loading