Sitelet https://web.archive.org/web/20201210055304/https://github.com/pyrogram/pyrogram/pull/511
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dialog methods to fetch archived chats #511

Closed
wants to merge 1 commit into from

Conversation

@kandnub
Copy link

@kandnub kandnub commented Oct 6, 2020

This PR closes #362

get_dialogs_count/get_dialogs/iter_dialogs: Added "archived_only" kwarg.

types.Dialog: Added "is_archived" boolean attribute.

get_dialogs_count/get_dialogs/iter_dialogs: Added "archived_only" kwarg.

types.Dialog: Added "is_archived" boolean attribute.
@delivrance
Copy link
Member

@delivrance delivrance commented Oct 18, 2020

Hi. Two issues:

  • You are using a boolean value where an integer is required. archived_only is boolean but the method works with integer folder ids.
  • This method is not that trivial to deal with. Telegram works with an optional folder id. If you don't pass it you'll get all dialogs, if you pass 0 you get the non-archived dialogs, if you pass 1 you get the archived dialogs. With your solution we are missing one case.

I believe the whole method needs a rewrite to allow an easier implementation and usage, in order to allow every possible case. Maybe pinned dialogs should also be fetched using a separate convenience method?

@kandnub
Copy link
Author

@kandnub kandnub commented Oct 19, 2020

You're correct about those issues, I used archived_only as a boolean since it's a subclass of int and to pass None to it directly to fetch all dialogs (which is dirty), but that doesn't seem suitable for folder_id anymore, plus it would fail with GetPinnedDialogs since folder_id isn't optional there. My apologises for not testing all the possible scenarios.

I also looked a bit into GetPinnedDialogs, GetDialogs and GetPeerDialogs (new get_dialog method maybe), having separate methods for them should be better. Maybe move the common dialog parsing code into a function outside the class and separate the methods in their classes respectively rather making a new file to avoid boilerplate?

Also, currently GetDialogs has a limit of only retrieving 100 dialogs the most, perhaps we could call iter_dialogs inside get_dialogs to make better use of the limit argument and rename pinned_only to exclude_pinned to match the raw method more?

@kandnub kandnub closed this Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.