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:
return search_chat_participants(dialog_id.get_chat_id(), query, limit, filter, std::move(promise));
case DialogType::Channel: {
td_api::object_ptr<td_api::SupergroupMembersFilter> request_filter;
string additional_query;
int32 additional_limit = 0;
switch (filter.type_) {
case DialogParticipantsFilter::Type::Contacts:
request_filter = td_api::make_object<td_api::supergroupMembersFilterContacts>();
break;
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();
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());

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) {
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<const td_api::chatMembersFilterMention *>(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<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);
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<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);
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(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_,
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) {