diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 009caab15..dfa83ca4f 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -14859,55 +14859,14 @@ void ContactsManager::search_dialog_participants(DialogId dialog_id, const strin case DialogType::Chat: return search_chat_participants(dialog_id.get_chat_id(), query, limit, filter, std::move(promise)); case DialogType::Channel: { - td_api::object_ptr request_filter; - string additional_query; - int32 additional_limit = 0; - switch (filter.type_) { - case DialogParticipantsFilter::Type::Contacts: - request_filter = td_api::make_object(); - break; - case DialogParticipantsFilter::Type::Administrators: - request_filter = td_api::make_object(); - break; - case DialogParticipantsFilter::Type::Members: - request_filter = td_api::make_object(query); - break; - case DialogParticipantsFilter::Type::Restricted: - request_filter = td_api::make_object(query); - break; - case DialogParticipantsFilter::Type::Banned: - request_filter = td_api::make_object(query); - break; - case DialogParticipantsFilter::Type::Mention: - request_filter = - td_api::make_object(query, filter.top_thread_message_id_.get()); - break; - case DialogParticipantsFilter::Type::Bots: - request_filter = td_api::make_object(); - break; - default: - UNREACHABLE(); + auto channel_id = dialog_id.get_channel_id(); + if (filter.has_query()) { + return get_channel_participants(channel_id, filter.get_supergroup_members_filter_object(query), string(), 0, + limit, 0, std::move(promise)); + } else { + return get_channel_participants(channel_id, filter.get_supergroup_members_filter_object(string()), query, 0, + 100, limit, std::move(promise)); } - switch (filter.type_) { - case DialogParticipantsFilter::Type::Contacts: - case DialogParticipantsFilter::Type::Administrators: - case DialogParticipantsFilter::Type::Bots: - additional_query = query; - additional_limit = limit; - limit = 100; - break; - case DialogParticipantsFilter::Type::Members: - case DialogParticipantsFilter::Type::Restricted: - case DialogParticipantsFilter::Type::Banned: - case DialogParticipantsFilter::Type::Mention: - // query is passed to the server request - break; - default: - UNREACHABLE(); - } - - return get_channel_participants(dialog_id.get_channel_id(), std::move(request_filter), - std::move(additional_query), 0, limit, additional_limit, std::move(promise)); } case DialogType::SecretChat: { auto peer_user_id = get_secret_chat_user_id(dialog_id.get_secret_chat_id()); diff --git a/td/telegram/DialogParticipant.cpp b/td/telegram/DialogParticipant.cpp index effd77333..b60604e4f 100644 --- a/td/telegram/DialogParticipant.cpp +++ b/td/telegram/DialogParticipant.cpp @@ -895,34 +895,83 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant } } -DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr &filter) { +DialogParticipantsFilter::DialogParticipantsFilter(const tl_object_ptr &filter) { if (filter == nullptr) { - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members}; + type_ = Type::Members; + return; } switch (filter->get_id()) { case td_api::chatMembersFilterContacts::ID: - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Contacts}; + type_ = Type::Contacts; + break; case td_api::chatMembersFilterAdministrators::ID: - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Administrators}; + type_ = Type::Administrators; + break; case td_api::chatMembersFilterMembers::ID: - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members}; + type_ = Type::Members; + break; case td_api::chatMembersFilterRestricted::ID: - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Restricted}; + type_ = Type::Restricted; + break; case td_api::chatMembersFilterBanned::ID: - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Banned}; + type_ = Type::Banned; + break; case td_api::chatMembersFilterMention::ID: { auto mention_filter = static_cast(filter.get()); - auto top_thread_message_id = MessageId(mention_filter->message_thread_id_); - if (!top_thread_message_id.is_valid() || !top_thread_message_id.is_server()) { - top_thread_message_id = MessageId(); + top_thread_message_id_ = MessageId(mention_filter->message_thread_id_); + if (!top_thread_message_id_.is_valid() || !top_thread_message_id_.is_server()) { + top_thread_message_id_ = MessageId(); } - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Mention, top_thread_message_id}; + type_ = Type::Mention; + break; } case td_api::chatMembersFilterBots::ID: - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Bots}; + type_ = Type::Bots; + break; default: UNREACHABLE(); - return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members}; + type_ = Type::Members; + break; + } +} + +td_api::object_ptr DialogParticipantsFilter::get_supergroup_members_filter_object( + const string &query) const { + switch (type_) { + case Type::Contacts: + return td_api::make_object(); + case Type::Administrators: + return td_api::make_object(); + case Type::Members: + return td_api::make_object(query); + case Type::Restricted: + return td_api::make_object(query); + case Type::Banned: + return td_api::make_object(query); + case Type::Mention: + return td_api::make_object(query, top_thread_message_id_.get()); + case Type::Bots: + return td_api::make_object(); + default: + UNREACHABLE(); + return nullptr; + } +} + +bool DialogParticipantsFilter::has_query() const { + switch (type_) { + case Type::Members: + case Type::Restricted: + case Type::Banned: + case Type::Mention: + return true; + case Type::Contacts: + case Type::Administrators: + case Type::Bots: + return false; + default: + UNREACHABLE(); + return false; } } diff --git a/td/telegram/DialogParticipant.h b/td/telegram/DialogParticipant.h index 3f779b1f7..cf5b36c7f 100644 --- a/td/telegram/DialogParticipant.h +++ b/td/telegram/DialogParticipant.h @@ -492,20 +492,25 @@ class ChannelParticipantsFilter { StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipantsFilter &filter); class DialogParticipantsFilter { + MessageId top_thread_message_id_; + public: enum class Type : int32 { Contacts, Administrators, Members, Restricted, Banned, Mention, Bots }; Type type_; - MessageId top_thread_message_id_; explicit DialogParticipantsFilter(Type type, MessageId top_thread_message_id = MessageId()) : type_(type), top_thread_message_id_(top_thread_message_id) { } + + explicit DialogParticipantsFilter(const tl_object_ptr &filter); + + td_api::object_ptr get_supergroup_members_filter_object(const string &query) const; + + bool has_query() const; }; StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantsFilter &filter); -DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr &filter); - DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr &status); DialogParticipantStatus get_dialog_participant_status(bool can_be_edited, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 92fe1cd2b..e166fbd28 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6270,8 +6270,7 @@ void Td::on_request(uint64 id, td_api::searchChatMembers &request) { } }); contacts_manager_->search_dialog_participants(DialogId(request.chat_id_), request.query_, request.limit_, - get_dialog_participants_filter(request.filter_), - std::move(query_promise)); + DialogParticipantsFilter(request.filter_), std::move(query_promise)); } void Td::on_request(uint64 id, td_api::getChatAdministrators &request) {