Use class for DialogParticipantsFilter.

GitOrigin-RevId: 56fc4ee7a35412db965c668f6a116ae29074f0a4
This commit is contained in:
levlam 2020-10-19 01:48:31 +03:00
parent 80d19432bf
commit 3f143b013a
4 changed files with 44 additions and 37 deletions

View File

@ -13321,18 +13321,18 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::search_chat_partici
} }
auto is_dialog_participant_suitable = [this](const DialogParticipant &participant, DialogParticipantsFilter filter) { auto is_dialog_participant_suitable = [this](const DialogParticipant &participant, DialogParticipantsFilter filter) {
switch (filter) { switch (filter.type) {
case DialogParticipantsFilter::Contacts: case DialogParticipantsFilter::Type::Contacts:
return is_user_contact(participant.user_id); return is_user_contact(participant.user_id);
case DialogParticipantsFilter::Administrators: case DialogParticipantsFilter::Type::Administrators:
return participant.status.is_administrator(); return participant.status.is_administrator();
case DialogParticipantsFilter::Members: case DialogParticipantsFilter::Type::Members:
return participant.status.is_member(); // should be always true return participant.status.is_member(); // should be always true
case DialogParticipantsFilter::Restricted: case DialogParticipantsFilter::Type::Restricted:
return participant.status.is_restricted(); // should be always false return participant.status.is_restricted(); // should be always false
case DialogParticipantsFilter::Banned: case DialogParticipantsFilter::Type::Banned:
return participant.status.is_banned(); // should be always false return participant.status.is_banned(); // should be always false
case DialogParticipantsFilter::Bots: case DialogParticipantsFilter::Type::Bots:
return is_user_bot(participant.user_id); return is_user_bot(participant.user_id);
default: default:
UNREACHABLE(); UNREACHABLE();

View File

@ -802,24 +802,24 @@ StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipan
DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr<td_api::ChatMembersFilter> &filter) { DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr<td_api::ChatMembersFilter> &filter) {
if (filter == nullptr) { if (filter == nullptr) {
return DialogParticipantsFilter::Members; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members};
} }
switch (filter->get_id()) { switch (filter->get_id()) {
case td_api::chatMembersFilterContacts::ID: case td_api::chatMembersFilterContacts::ID:
return DialogParticipantsFilter::Contacts; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Contacts};
case td_api::chatMembersFilterAdministrators::ID: case td_api::chatMembersFilterAdministrators::ID:
return DialogParticipantsFilter::Administrators; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Administrators};
case td_api::chatMembersFilterMembers::ID: case td_api::chatMembersFilterMembers::ID:
return DialogParticipantsFilter::Members; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members};
case td_api::chatMembersFilterRestricted::ID: case td_api::chatMembersFilterRestricted::ID:
return DialogParticipantsFilter::Restricted; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Restricted};
case td_api::chatMembersFilterBanned::ID: case td_api::chatMembersFilterBanned::ID:
return DialogParticipantsFilter::Banned; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Banned};
case td_api::chatMembersFilterBots::ID: case td_api::chatMembersFilterBots::ID:
return DialogParticipantsFilter::Bots; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Bots};
default: default:
UNREACHABLE(); UNREACHABLE();
return DialogParticipantsFilter::Members; return DialogParticipantsFilter{DialogParticipantsFilter::Type::Members};
} }
} }

View File

@ -443,7 +443,14 @@ class ChannelParticipantsFilter {
StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipantsFilter &filter); StringBuilder &operator<<(StringBuilder &string_builder, const ChannelParticipantsFilter &filter);
enum class DialogParticipantsFilter : int32 { Contacts, Administrators, Members, Restricted, Banned, Bots }; class DialogParticipantsFilter {
public:
enum class Type : int32 { Contacts, Administrators, Members, Restricted, Banned, Bots };
Type type;
explicit DialogParticipantsFilter(Type type) : type(type) {
}
};
DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr<td_api::ChatMembersFilter> &filter); DialogParticipantsFilter get_dialog_participants_filter(const tl_object_ptr<td_api::ChatMembersFilter> &filter);

View File

@ -29761,25 +29761,25 @@ DialogParticipant MessagesManager::get_dialog_participant(DialogId dialog_id, Us
std::pair<int32, vector<DialogParticipant>> MessagesManager::search_private_chat_participants( std::pair<int32, vector<DialogParticipant>> MessagesManager::search_private_chat_participants(
UserId my_user_id, UserId peer_user_id, const string &query, int32 limit, DialogParticipantsFilter filter) const { UserId my_user_id, UserId peer_user_id, const string &query, int32 limit, DialogParticipantsFilter filter) const {
vector<UserId> user_ids; vector<UserId> user_ids;
switch (filter) { switch (filter.type) {
case DialogParticipantsFilter::Contacts: case DialogParticipantsFilter::Type::Contacts:
if (peer_user_id.is_valid() && td_->contacts_manager_->is_user_contact(peer_user_id)) { if (peer_user_id.is_valid() && td_->contacts_manager_->is_user_contact(peer_user_id)) {
user_ids.push_back(peer_user_id); user_ids.push_back(peer_user_id);
} }
break; break;
case DialogParticipantsFilter::Administrators: case DialogParticipantsFilter::Type::Administrators:
break; break;
case DialogParticipantsFilter::Members: case DialogParticipantsFilter::Type::Members:
user_ids.push_back(my_user_id); user_ids.push_back(my_user_id);
if (peer_user_id.is_valid() && peer_user_id != my_user_id) { if (peer_user_id.is_valid() && peer_user_id != my_user_id) {
user_ids.push_back(peer_user_id); user_ids.push_back(peer_user_id);
} }
break; break;
case DialogParticipantsFilter::Restricted: case DialogParticipantsFilter::Type::Restricted:
break; break;
case DialogParticipantsFilter::Banned: case DialogParticipantsFilter::Type::Banned:
break; break;
case DialogParticipantsFilter::Bots: case DialogParticipantsFilter::Type::Bots:
if (td_->auth_manager_->is_bot()) { if (td_->auth_manager_->is_bot()) {
user_ids.push_back(my_user_id); user_ids.push_back(my_user_id);
} }
@ -29824,39 +29824,39 @@ std::pair<int32, vector<DialogParticipant>> MessagesManager::search_dialog_parti
tl_object_ptr<td_api::SupergroupMembersFilter> request_filter; tl_object_ptr<td_api::SupergroupMembersFilter> request_filter;
string additional_query; string additional_query;
int32 additional_limit = 0; int32 additional_limit = 0;
switch (filter) { switch (filter.type) {
case DialogParticipantsFilter::Contacts: case DialogParticipantsFilter::Type::Contacts:
request_filter = td_api::make_object<td_api::supergroupMembersFilterContacts>(); request_filter = td_api::make_object<td_api::supergroupMembersFilterContacts>();
break; break;
case DialogParticipantsFilter::Administrators: case DialogParticipantsFilter::Type::Administrators:
request_filter = td_api::make_object<td_api::supergroupMembersFilterAdministrators>(); request_filter = td_api::make_object<td_api::supergroupMembersFilterAdministrators>();
break; break;
case DialogParticipantsFilter::Members: case DialogParticipantsFilter::Type::Members:
request_filter = td_api::make_object<td_api::supergroupMembersFilterSearch>(query); request_filter = td_api::make_object<td_api::supergroupMembersFilterSearch>(query);
break; break;
case DialogParticipantsFilter::Restricted: case DialogParticipantsFilter::Type::Restricted:
request_filter = td_api::make_object<td_api::supergroupMembersFilterRestricted>(query); request_filter = td_api::make_object<td_api::supergroupMembersFilterRestricted>(query);
break; break;
case DialogParticipantsFilter::Banned: case DialogParticipantsFilter::Type::Banned:
request_filter = td_api::make_object<td_api::supergroupMembersFilterBanned>(query); request_filter = td_api::make_object<td_api::supergroupMembersFilterBanned>(query);
break; break;
case DialogParticipantsFilter::Bots: case DialogParticipantsFilter::Type::Bots:
request_filter = td_api::make_object<td_api::supergroupMembersFilterBots>(); request_filter = td_api::make_object<td_api::supergroupMembersFilterBots>();
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
switch (filter) { switch (filter.type) {
case DialogParticipantsFilter::Contacts: case DialogParticipantsFilter::Type::Contacts:
case DialogParticipantsFilter::Administrators: case DialogParticipantsFilter::Type::Administrators:
case DialogParticipantsFilter::Bots: case DialogParticipantsFilter::Type::Bots:
additional_query = query; additional_query = query;
additional_limit = limit; additional_limit = limit;
limit = 100; limit = 100;
break; break;
case DialogParticipantsFilter::Members: case DialogParticipantsFilter::Type::Members:
case DialogParticipantsFilter::Restricted: case DialogParticipantsFilter::Type::Restricted:
case DialogParticipantsFilter::Banned: case DialogParticipantsFilter::Type::Banned:
// query is passed to the server request // query is passed to the server request
break; break;
default: default: