Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@EzekialSA
Copy link
Contributor

@EzekialSA EzekialSA commented Dec 10, 2025

I had this ready to go, someone pushed a change and I had no idea that my PR was merged already. I went ahead and closed it and rebased my fork to match and am properly doing branches for features. I've been using this in my lab for a couple weeks with zero issues.

Replace query.GetDialogs() iterator with manual pagination using MessagesGetDialogs API
to fix multiple critical issues with dialog listing functionality.

Problems fixed:

  • Index out of range panic when accessing empty Messages array in fetchTopics

    • Add empty array check before accessing messages for pagination offsets
    • Return empty Topics array instead of nil on fetch errors
  • Incomplete dialog fetching

    • Implement proper pagination loop with totalCount stopping condition
    • Use MessagesDialogsSlice.Count to determine when all dialogs are fetched
    • Handle partial batches that can occur mid-stream
  • Infinite loop causing flood waits due to incorrect offset calculation

    • Calculate offsets from dialog.TopMessage instead of messages array
    • Prevent duplicate messages from causing offset to get stuck
  • Entity population failures preventing proper dialog processing

    • Accumulate users, chats, channels, and messages across all batches into global maps
    • Build single peer.Entities object from complete dataset after fetching
  • Hard failures when encountering deleted/inaccessible channels

    • Use InputPeerEmpty for offsetPeer to avoid ExtractPeer failures during pagination
    • Gracefully skip dialogs with invalid/missing peers instead of failing
    • Add detailed logging for skipped dialogs with peer IDs and types

Additional improvements:

  • Switch from fixed-width columns to tab-delimited output
  • Remove runewidth dependency and unused trunc function
  • Add comprehensive batch-level and summary logging
  • Track and report non-Dialog types (e.g., DialogFolder)

…rror handling

- Implement manual pagination with proper offset handling to avoid API issues
- Add global entity accumulation across all batches for complete peer resolution
- Implement deduplication using seen dialogs map to prevent duplicate entries
- Add extensive logging for debugging pagination and dialog processing
- Improve error handling for invalid peers (deleted channels, banned users)
- Simplify table output format (remove runewidth truncation complexity)
- Add detailed processing summary with counts for blocked, nil, and skipped dialogs
- Fix infinite loop issues with duplicate dialog detection in pagination
- Handle edge cases: empty messages, DialogFolder types, missing access hashes
- Pass logger to printTable for better observability
- Return dialogs with empty topics array instead of nil on topic fetch errors

This is a more comprehensive fix than upstream's basic index check, providing
production-ready pagination handling and better user experience.
@Zig-VS-TypeScript-VS
Copy link

Zig-VS-TypeScript-VS commented Dec 14, 2025

@EzekialSA hello
I tried your two PR, and it caused a bug. It resulted in an incorrect order for reading the TDL ID.

join https://t.me/happylibrary >>> View discussion >>> join.

tdl-export.json

logs

tdl dl -f D:\88\tdl-export.json --template "{{ filenamify .FileName }}" -i epub --skip-same --takeout --pool 0 -d D:\88\ -t 6 -l 7

All files will be downloaded to 'D:\88\' dir
书库小说讨论群[NSFW](1285760920):961110 -> D:\88~ ... done! [1.11 MB in 7.752s; 146.33 KB/s]

It should start downloading from the latest to the earliest ID.

{"id":965682,"type":"message","file":"复兴之路 - wanglong - 266CHS.epub"},
{"id":93,"type":"message","file":"宰执天下-cuslaa.epub"}

D:\88>tdl dl -f D:\88\tdl-export.json --template "{{ filenamify .FileName }}" -i txt --skip-same --takeout --pool 0 -d D:\88\ -t 6 -l 7
All files will be downloaded to 'D:\88\' dir
书库小说讨论群[NSFW](1285760920):516933 -> D:\88~ ... done! [666.13 KB in 4.775s; 138.09 KB/s]

It should start downloading from the latest to the earliest ID.

{"id":966782,"type":"message","file":"sxsy_org发现清冷系校花偷喝我飞机杯里O液的这件事_作者:_FXY.txt"}
{"id":53,"type":"message","file":"大奉打更人番外(7篇)_soushu555_org_搜书吧网址.txt"}]

@Zig-VS-TypeScript-VS
Copy link

EzekialSA Sorry, this isn’t your PR’s fault; it’s a bug in TDL itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants