Fix get_chat_history method to work properly with min_id and max_id#203
Merged
Merged
Conversation
SpEcHiDe
added a commit
to TelegramPlayground/PyroTGFork
that referenced
this pull request
Aug 13, 2025
KurimuzonAkuma/kurigram#203 Co-authored-by: Danipulok <Danipulok@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description: Fix
get_chat_historyBoundary and Reverse IssuesOverview
This pull request fixes critical bugs in Pyrogram's
get_chat_historymethod, which failed to handlemin_id,max_id, andreverseparameters correctly, often returning no messages or incorrect ranges. The changes ensure reliable message retrieval within specified boundaries and proper sorting.Issues Fixed
min_idandmax_idcombinations, returning no messages for valid ranges.reverse=True, the method often failed to return messages or started from incorrect IDs.min_id=50,max_id=55) and invalid ranges (e.g.,min_id > max_id) were not handled correctly.Changes Made
get_chunkto properly handlemin_idandmax_idas inclusive boundaries.min_idormax_id+1).reverse=True, descending otherwise).Example
To verify, use this example with a public Telegram group like
@tginfo:Expected:
Current output:
<None>Proof of Fix
Before the fix, queries with
min_idandmax_id(e.g., 10-100) orreverse=Trueoften returned 0 messages or incorrect IDs. After the fix:min_id=10,max_id=100return messages in the correct range (e.g., 15 messages, IDs 78-99).reverse=Truecorrectly returns messages in ascending order (e.g., IDs 10-19 for limit=10).min_id=50,max_id=55) return expected messages (e.g., 6 messages, IDs 50-55).Conclusion
This PR resolves critical bugs in
get_chat_history, ensuring accurate message retrieval with boundaries and reverse sorting. The changes are backward-compatible and can be verified with the provided example in any public Telegram chat.