Move some methods inside DialogParticipantsFilter class.

This commit is contained in:
levlam 2021-10-23 22:23:59 +03:00
parent 47d4c08de2
commit 1c59f37ca9
4 changed files with 78 additions and 66 deletions

View File

@ -14859,55 +14859,14 @@ void ContactsManager::search_dialog_participants(DialogId dialog_id, const strin
case DialogType::Chat: case DialogType::Chat:
return search_chat_participants(dialog_id.get_chat_id(), query, limit, filter, std::move(promise)); return search_chat_participants(dialog_id.get_chat_id(), query, limit, filter, std::move(promise));
case DialogType::Channel: { case DialogType::Channel: {
td_api::object_ptr<td_api::SupergroupMembersFilter> request_filter; auto channel_id = dialog_id.get_channel_id();
string additional_query; if (filter.has_query()) {
int32 additional_limit = 0; return get_channel_participants(channel_id, filter.get_supergroup_members_filter_object(query), string(), 0,
switch (filter.type_) { limit, 0, std::move(promise));
case DialogParticipantsFilter::Type::Contacts: } else {
request_filter = td_api::make_object<td_api::supergroupMembersFilterContacts>(); return get_channel_participants(channel_id, filter.get_supergroup_members_filter_object(string()), query, 0,
break; 100, limit, std::move(promise));
case DialogParticipantsFilter::Type::Administrators:
request_filter = td_api::make_object<td_api::supergroupMembersFilterAdministrators>();
break;
case DialogParticipantsFilter::Type::Members:
request_filter = td_api::make_object<td_api::supergroupMembersFilterSearch>(query);
break;
case DialogParticipantsFilter::Type::Restricted:
request_filter = td_api::make_object<td_api::supergroupMembersFilterRestricted>(query);
break;
case DialogParticipantsFilter::Type::Banned:
request_filter = td_api::make_object<td_api::supergroupMembersFilterBanned>(query);
break;
case DialogParticipantsFilter::Type::Mention:
request_filter =
td_api::make_object<td_api::supergroupMembersFilterMention>(query, filter.top_thread_message_id_.get());
break;
case DialogParticipantsFilter::Type::Bots:
request_filter = td_api::make_object<td_api::supergroupMembersFilterBots>();
break;
default:
UNREACHABLE();
} }
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: { case DialogType::SecretChat: {
auto peer_user_id = get_secret_chat_user_id(dialog_id.get_secret_chat_id()); auto peer_user_id = get_secret_chat_user_id(dialog_id.get_secret_chat_id());

View File

@ -895,34 +895,83 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant
} }
} }
DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr<td_api::ChatMembersFilter> &filter) { DialogParticipantsFilter::DialogParticipantsFilter(const tl_object_ptr<td_api::ChatMembersFilter> &filter) {
if (filter == nullptr) { if (filter == nullptr) {
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members}; type_ = Type::Members;
return;
} }
switch (filter->get_id()) { switch (filter->get_id()) {
case td_api::chatMembersFilterContacts::ID: case td_api::chatMembersFilterContacts::ID:
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Contacts}; type_ = Type::Contacts;
break;
case td_api::chatMembersFilterAdministrators::ID: case td_api::chatMembersFilterAdministrators::ID:
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Administrators}; type_ = Type::Administrators;
break;
case td_api::chatMembersFilterMembers::ID: case td_api::chatMembersFilterMembers::ID:
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members}; type_ = Type::Members;
break;
case td_api::chatMembersFilterRestricted::ID: case td_api::chatMembersFilterRestricted::ID:
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Restricted}; type_ = Type::Restricted;
break;
case td_api::chatMembersFilterBanned::ID: case td_api::chatMembersFilterBanned::ID:
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Banned}; type_ = Type::Banned;
break;
case td_api::chatMembersFilterMention::ID: { case td_api::chatMembersFilterMention::ID: {
auto mention_filter = static_cast<const td_api::chatMembersFilterMention *>(filter.get()); auto mention_filter = static_cast<const td_api::chatMembersFilterMention *>(filter.get());
auto top_thread_message_id = MessageId(mention_filter->message_thread_id_); top_thread_message_id_ = MessageId(mention_filter->message_thread_id_);
if (!top_thread_message_id.is_valid() || !top_thread_message_id.is_server()) { if (!top_thread_message_id_.is_valid() || !top_thread_message_id_.is_server()) {
top_thread_message_id = MessageId(); top_thread_message_id_ = MessageId();
} }
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Mention, top_thread_message_id}; type_ = Type::Mention;
break;
} }
case td_api::chatMembersFilterBots::ID: case td_api::chatMembersFilterBots::ID:
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Bots}; type_ = Type::Bots;
break;
default: default:
UNREACHABLE(); UNREACHABLE();
return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members}; type_ = Type::Members;
break;
}
}
td_api::object_ptr<td_api::SupergroupMembersFilter> DialogParticipantsFilter::get_supergroup_members_filter_object(
const string &query) const {
switch (type_) {
case Type::Contacts:
return td_api::make_object<td_api::supergroupMembersFilterContacts>();
case Type::Administrators:
return td_api::make_object<td_api::supergroupMembersFilterAdministrators>();
case Type::Members:
return td_api::make_object<td_api::supergroupMembersFilterSearch>(query);
case Type::Restricted:
return td_api::make_object<td_api::supergroupMembersFilterRestricted>(query);
case Type::Banned:
return td_api::make_object<td_api::supergroupMembersFilterBanned>(query);
case Type::Mention:
return td_api::make_object<td_api::supergroupMembersFilterMention>(query, top_thread_message_id_.get());
case Type::Bots:
return td_api::make_object<td_api::supergroupMembersFilterBots>();
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;
} }
} }

View File

@ -492,20 +492,25 @@ class ChannelParticipantsFilter {
StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipantsFilter &filter); StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipantsFilter &filter);
class DialogParticipantsFilter { class DialogParticipantsFilter {
MessageId top_thread_message_id_;
public: public:
enum class Type : int32 { Contacts, Administrators, Members, Restricted, Banned, Mention, Bots }; enum class Type : int32 { Contacts, Administrators, Members, Restricted, Banned, Mention, Bots };
Type type_; Type type_;
MessageId top_thread_message_id_;
explicit DialogParticipantsFilter(Type type, MessageId top_thread_message_id = MessageId()) explicit DialogParticipantsFilter(Type type, MessageId top_thread_message_id = MessageId())
: type_(type), top_thread_message_id_(top_thread_message_id) { : type_(type), top_thread_message_id_(top_thread_message_id) {
} }
explicit DialogParticipantsFilter(const tl_object_ptr<td_api::ChatMembersFilter> &filter);
td_api::object_ptr<td_api::SupergroupMembersFilter> get_supergroup_members_filter_object(const string &query) const;
bool has_query() const;
}; };
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantsFilter &filter); StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipantsFilter &filter);
DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr<td_api::ChatMembersFilter> &filter);
DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api::ChatMemberStatus> &status); DialogParticipantStatus get_dialog_participant_status(const tl_object_ptr<td_api::ChatMemberStatus> &status);
DialogParticipantStatus get_dialog_participant_status(bool can_be_edited, DialogParticipantStatus get_dialog_participant_status(bool can_be_edited,

View File

@ -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_, contacts_manager_->search_dialog_participants(DialogId(request.chat_id_), request.query_, request.limit_,
get_dialog_participants_filter(request.filter_), DialogParticipantsFilter(request.filter_), std::move(query_promise));
std::move(query_promise));
} }
void Td::on_request(uint64 id, td_api::getChatAdministrators &request) { void Td::on_request(uint64 id, td_api::getChatAdministrators &request) {