Add struct DialogParticipants.

This commit is contained in:
levlam 2021-01-25 02:00:57 +03:00
parent feba24f1f4
commit ef160aa2c0
7 changed files with 49 additions and 41 deletions

View File

@ -13401,11 +13401,9 @@ DialogParticipant ContactsManager::get_chat_participant(ChatId chat_id, UserId u
return *result;
}
std::pair<int32, vector<DialogParticipant>> ContactsManager::search_chat_participants(ChatId chat_id,
const string &query, int32 limit,
DialogParticipantsFilter filter,
bool force,
Promise<Unit> &&promise) {
DialogParticipants ContactsManager::search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantsFilter filter, bool force,
Promise<Unit> &&promise) {
if (limit < 0) {
promise.set_error(Status::Error(3, "Parameter limit must be non-negative"));
return {};
@ -13518,7 +13516,7 @@ DialogParticipant ContactsManager::get_channel_participant(ChannelId channel_id,
return DialogParticipant();
}
std::pair<int32, vector<DialogParticipant>> ContactsManager::get_channel_participants(
DialogParticipants ContactsManager::get_channel_participants(
ChannelId channel_id, const tl_object_ptr<td_api::SupergroupMembersFilter> &filter, const string &additional_query,
int32 offset, int32 limit, int32 additional_limit, int64 &random_id, bool without_bot_info, bool force,
Promise<Unit> &&promise) {
@ -13534,24 +13532,24 @@ std::pair<int32, vector<DialogParticipant>> ContactsManager::get_channel_partici
return result;
}
auto user_ids = transform(result.second, [](const auto &participant) { return participant.user_id; });
auto user_ids = transform(result.participants_, [](const auto &participant) { return participant.user_id; });
std::pair<int32, vector<UserId>> result_user_ids = search_among_users(user_ids, additional_query, additional_limit);
result.first = result_user_ids.first;
result.total_count_ = result_user_ids.first;
std::unordered_set<UserId, UserIdHash> result_user_ids_set(result_user_ids.second.begin(),
result_user_ids.second.end());
auto all_participants = std::move(result.second);
result.second.clear();
auto all_participants = std::move(result.participants_);
result.participants_.clear();
for (auto &participant : all_participants) {
if (result_user_ids_set.count(participant.user_id)) {
result.second.push_back(std::move(participant));
result.participants_.push_back(std::move(participant));
result_user_ids_set.erase(participant.user_id);
}
}
return result;
}
std::pair<int32, vector<DialogParticipant>> result;
DialogParticipants result;
if (limit <= 0) {
promise.set_error(Status::Error(3, "Parameter limit must be positive"));
return result;

View File

@ -501,17 +501,17 @@ class ContactsManager : public Actor {
DialogParticipant get_chat_participant(ChatId chat_id, UserId user_id, bool force, Promise<Unit> &&promise);
std::pair<int32, vector<DialogParticipant>> search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantsFilter filter, bool force,
Promise<Unit> &&promise);
DialogParticipants search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantsFilter filter, bool force, Promise<Unit> &&promise);
DialogParticipant get_channel_participant(ChannelId channel_id, UserId user_id, int64 &random_id, bool force,
Promise<Unit> &&promise);
std::pair<int32, vector<DialogParticipant>> get_channel_participants(
ChannelId channel_id, const tl_object_ptr<td_api::SupergroupMembersFilter> &filter,
const string &additional_query, int32 offset, int32 limit, int32 additional_limit, int64 &random_id,
bool without_bot_info, bool force, Promise<Unit> &&promise);
DialogParticipants get_channel_participants(ChannelId channel_id,
const tl_object_ptr<td_api::SupergroupMembersFilter> &filter,
const string &additional_query, int32 offset, int32 limit,
int32 additional_limit, int64 &random_id, bool without_bot_info,
bool force, Promise<Unit> &&promise);
void send_get_channel_participants_query(ChannelId channel_id, ChannelParticipantsFilter filter, int32 offset,
int32 limit, int64 random_id, Promise<Unit> &&promise);
@ -1567,7 +1567,7 @@ class ContactsManager : public Actor {
std::unordered_map<int64, std::pair<vector<UserId>, vector<int32>>> imported_contacts_;
std::unordered_map<int64, DialogParticipant> received_channel_participant_;
std::unordered_map<int64, std::pair<int32, vector<DialogParticipant>>> received_channel_participants_;
std::unordered_map<int64, DialogParticipants> received_channel_participants_;
std::unordered_map<ChannelId, vector<DialogParticipant>, ChannelIdHash> cached_channel_participants_;

View File

@ -409,6 +409,16 @@ struct DialogParticipant {
StringBuilder &operator<<(StringBuilder &string_builder, const DialogParticipant &dialog_participant);
struct DialogParticipants {
int32 total_count_ = 0;
vector<DialogParticipant> participants_;
DialogParticipants() = default;
DialogParticipants(int32 total_count, vector<DialogParticipant> &&participants)
: total_count_(total_count), participants_(std::move(participants)) {
}
};
class ChannelParticipantsFilter {
enum class Type : int32 { Recent, Contacts, Administrators, Search, Mention, Restricted, Banned, Bots } type;
string query;

View File

@ -1520,7 +1520,7 @@ void GroupCallManager::finish_load_group_call_administrators(InputGroupCallId in
auto participants = td_->messages_manager_->search_dialog_participants(
group_call->dialog_id, string(), 100, DialogParticipantsFilter(DialogParticipantsFilter::Type::Administrators),
random_id, true, true, std::move(promise));
for (auto &administrator : participants.second) {
for (auto &administrator : participants.participants_) {
if (administrator.status.can_manage_calls() && administrator.user_id != td_->contacts_manager_->get_my_id()) {
administrator_user_ids.push_back(administrator.user_id);
}

View File

@ -30265,8 +30265,9 @@ DialogParticipant MessagesManager::get_dialog_participant(DialogId dialog_id, Us
return DialogParticipant();
}
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 {
DialogParticipants MessagesManager::search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
const string &query, int32 limit,
DialogParticipantsFilter filter) const {
vector<UserId> user_ids;
switch (filter.type) {
case DialogParticipantsFilter::Type::Contacts:
@ -30307,9 +30308,10 @@ std::pair<int32, vector<DialogParticipant>> MessagesManager::search_private_chat
})};
}
std::pair<int32, vector<DialogParticipant>> MessagesManager::search_dialog_participants(
DialogId dialog_id, const string &query, int32 limit, DialogParticipantsFilter filter, int64 &random_id,
bool without_bot_info, bool force, Promise<Unit> &&promise) {
DialogParticipants MessagesManager::search_dialog_participants(DialogId dialog_id, const string &query, int32 limit,
DialogParticipantsFilter filter, int64 &random_id,
bool without_bot_info, bool force,
Promise<Unit> &&promise) {
LOG(INFO) << "Receive searchChatMembers request to search for \"" << query << "\" in " << dialog_id << " with filter "
<< filter;
if (!have_dialog_force(dialog_id)) {

View File

@ -477,10 +477,9 @@ class MessagesManager : public Actor {
DialogParticipant get_dialog_participant(DialogId dialog_id, UserId user_id, int64 &random_id, bool force,
Promise<Unit> &&promise);
std::pair<int32, vector<DialogParticipant>> search_dialog_participants(DialogId dialog_id, const string &query,
int32 limit, DialogParticipantsFilter filter,
int64 &random_id, bool without_bot_info,
bool force, Promise<Unit> &&promise);
DialogParticipants search_dialog_participants(DialogId dialog_id, const string &query, int32 limit,
DialogParticipantsFilter filter, int64 &random_id,
bool without_bot_info, bool force, Promise<Unit> &&promise);
vector<DialogAdministrator> get_dialog_administrators(DialogId dialog_id, int left_tries, Promise<Unit> &&promise);
@ -2515,9 +2514,8 @@ class MessagesManager : public Actor {
DialogFolder *get_dialog_folder(FolderId folder_id);
const DialogFolder *get_dialog_folder(FolderId folder_id) const;
std::pair<int32, vector<DialogParticipant>> search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
const string &query, int32 limit,
DialogParticipantsFilter filter) const;
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
int32 limit, DialogParticipantsFilter filter) const;
static unique_ptr<Message> *treap_find_message(unique_ptr<Message> *v, MessageId message_id);
static const unique_ptr<Message> *treap_find_message(const unique_ptr<Message> *v, MessageId message_id);

View File

@ -1968,7 +1968,7 @@ class SearchChatMembersRequest : public RequestActor<> {
DialogParticipantsFilter filter_;
int64 random_id_ = 0;
std::pair<int32, vector<DialogParticipant>> participants_;
DialogParticipants participants_;
void do_run(Promise<Unit> &&promise) override {
participants_ = td->messages_manager_->search_dialog_participants(dialog_id_, query_, limit_, filter_, random_id_,
@ -1978,12 +1978,12 @@ class SearchChatMembersRequest : public RequestActor<> {
void do_send_result() override {
// TODO create function get_chat_members_object
vector<tl_object_ptr<td_api::chatMember>> result;
result.reserve(participants_.second.size());
for (auto participant : participants_.second) {
result.reserve(participants_.participants_.size());
for (auto participant : participants_.participants_) {
result.push_back(td->contacts_manager_->get_chat_member_object(participant));
}
send_result(make_tl_object<td_api::chatMembers>(participants_.first, std::move(result)));
send_result(make_tl_object<td_api::chatMembers>(participants_.total_count_, std::move(result)));
}
public:
@ -2285,7 +2285,7 @@ class GetSupergroupMembersRequest : public RequestActor<> {
int32 limit_;
int64 random_id_ = 0;
std::pair<int32, vector<DialogParticipant>> participants_;
DialogParticipants participants_;
void do_run(Promise<Unit> &&promise) override {
participants_ = td->contacts_manager_->get_channel_participants(
@ -2295,12 +2295,12 @@ class GetSupergroupMembersRequest : public RequestActor<> {
void do_send_result() override {
// TODO create function get_chat_members_object
vector<tl_object_ptr<td_api::chatMember>> result;
result.reserve(participants_.second.size());
for (auto participant : participants_.second) {
result.reserve(participants_.participants_.size());
for (auto participant : participants_.participants_) {
result.push_back(td->contacts_manager_->get_chat_member_object(participant));
}
send_result(make_tl_object<td_api::chatMembers>(participants_.first, std::move(result)));
send_result(make_tl_object<td_api::chatMembers>(participants_.total_count_, std::move(result)));
}
public: