Move search_dialog_participants to DialogParticipantManager.

This commit is contained in:
levlam 2024-03-02 02:02:01 +03:00
parent 29a8e8062b
commit 465fdd8505
6 changed files with 78 additions and 73 deletions

View File

@ -16600,65 +16600,6 @@ std::pair<int32, vector<DialogId>> ContactsManager::search_among_dialogs(const v
return {narrow_cast<int32>(result.first), transform(result.second, [](int64 key) { return DialogId(key); })};
}
DialogParticipants ContactsManager::search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
const string &query, int32 limit,
DialogParticipantFilter filter) const {
vector<DialogId> dialog_ids;
if (filter.is_dialog_participant_suitable(td_, DialogParticipant::private_member(my_user_id, peer_user_id))) {
dialog_ids.push_back(DialogId(my_user_id));
}
if (peer_user_id.is_valid() && peer_user_id != my_user_id &&
filter.is_dialog_participant_suitable(td_, DialogParticipant::private_member(peer_user_id, my_user_id))) {
dialog_ids.push_back(DialogId(peer_user_id));
}
auto result = search_among_dialogs(dialog_ids, query, limit);
return {result.first, transform(result.second, [&](DialogId dialog_id) {
auto user_id = dialog_id.get_user_id();
return DialogParticipant::private_member(user_id, user_id == my_user_id ? peer_user_id : my_user_id);
})};
}
void ContactsManager::search_dialog_participants(DialogId dialog_id, const string &query, int32 limit,
DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise) {
LOG(INFO) << "Receive searchChatMembers request to search for \"" << query << "\" in " << dialog_id << " with filter "
<< filter;
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "search_dialog_participants")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (limit < 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be non-negative"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
promise.set_value(search_private_chat_participants(get_my_id(), dialog_id.get_user_id(), query, limit, filter));
return;
case DialogType::Chat:
return search_chat_participants(dialog_id.get_chat_id(), query, limit, filter, std::move(promise));
case DialogType::Channel: {
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));
}
}
case DialogType::SecretChat: {
auto peer_user_id = get_secret_chat_user_id(dialog_id.get_secret_chat_id());
promise.set_value(search_private_chat_participants(get_my_id(), peer_user_id, query, limit, filter));
return;
}
case DialogType::None:
default:
UNREACHABLE();
promise.set_error(Status::Error(500, "Wrong chat type"));
}
}
void ContactsManager::get_chat_participant(ChatId chat_id, UserId user_id, Promise<DialogParticipant> &&promise) {
LOG(INFO) << "Trying to get " << user_id << " as member of " << chat_id;

View File

@ -663,8 +663,11 @@ class ContactsManager final : public Actor {
void speculative_add_channel_user(ChannelId channel_id, UserId user_id, const DialogParticipantStatus &new_status,
const DialogParticipantStatus &old_status);
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise);
std::pair<int32, vector<DialogId>> search_among_dialogs(const vector<DialogId> &dialog_ids, const string &query,
int32 limit) const;
void search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise);
void get_channel_participants(ChannelId channel_id, tl_object_ptr<td_api::SupergroupMembersFilter> &&filter,
string additional_query, int32 offset, int32 limit, int32 additional_limit,
@ -1717,12 +1720,6 @@ class ContactsManager final : public Actor {
static const DialogParticipant *get_chat_full_participant(const ChatFull *chat_full, DialogId dialog_id);
std::pair<int32, vector<DialogId>> search_among_dialogs(const vector<DialogId> &dialog_ids, const string &query,
int32 limit) const;
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
int32 limit, DialogParticipantFilter filter) const;
void finish_get_chat_participant(ChatId chat_id, UserId user_id, Promise<DialogParticipant> &&promise);
void remove_dialog_suggested_action(SuggestedAction action);
@ -1795,9 +1792,6 @@ class ContactsManager final : public Actor {
void update_dialogs_for_discussion(DialogId dialog_id, bool is_suitable);
void search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise);
void do_search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise);

View File

@ -1605,6 +1605,67 @@ void DialogParticipantManager::finish_get_channel_participant(ChannelId channel_
promise.set_value(std::move(dialog_participant));
}
DialogParticipants DialogParticipantManager::search_private_chat_participants(UserId my_user_id, UserId peer_user_id,
const string &query, int32 limit,
DialogParticipantFilter filter) const {
vector<DialogId> dialog_ids;
if (filter.is_dialog_participant_suitable(td_, DialogParticipant::private_member(my_user_id, peer_user_id))) {
dialog_ids.push_back(DialogId(my_user_id));
}
if (peer_user_id.is_valid() && peer_user_id != my_user_id &&
filter.is_dialog_participant_suitable(td_, DialogParticipant::private_member(peer_user_id, my_user_id))) {
dialog_ids.push_back(DialogId(peer_user_id));
}
auto result = td_->contacts_manager_->search_among_dialogs(dialog_ids, query, limit);
return {result.first, transform(result.second, [&](DialogId dialog_id) {
auto user_id = dialog_id.get_user_id();
return DialogParticipant::private_member(user_id, user_id == my_user_id ? peer_user_id : my_user_id);
})};
}
void DialogParticipantManager::search_dialog_participants(DialogId dialog_id, const string &query, int32 limit,
DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise) {
LOG(INFO) << "Receive searchChatMembers request to search for \"" << query << "\" in " << dialog_id << " with filter "
<< filter;
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "search_dialog_participants")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (limit < 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be non-negative"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
return promise.set_value(search_private_chat_participants(td_->contacts_manager_->get_my_id(),
dialog_id.get_user_id(), query, limit, filter));
case DialogType::Chat:
return td_->contacts_manager_->search_chat_participants(dialog_id.get_chat_id(), query, limit, filter,
std::move(promise));
case DialogType::Channel: {
auto channel_id = dialog_id.get_channel_id();
if (filter.has_query()) {
return td_->contacts_manager_->get_channel_participants(
channel_id, filter.get_supergroup_members_filter_object(query), string(), 0, limit, 0, std::move(promise));
} else {
return td_->contacts_manager_->get_channel_participants(channel_id,
filter.get_supergroup_members_filter_object(string()),
query, 0, 100, limit, std::move(promise));
}
}
case DialogType::SecretChat: {
auto peer_user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
return promise.set_value(
search_private_chat_participants(td_->contacts_manager_->get_my_id(), peer_user_id, query, limit, filter));
}
case DialogType::None:
default:
UNREACHABLE();
promise.set_error(Status::Error(500, "Wrong chat type"));
}
}
void DialogParticipantManager::add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit,
Promise<Unit> &&promise) {
if (!td_->dialog_manager_->have_dialog_force(dialog_id, "add_dialog_participant")) {

View File

@ -12,6 +12,7 @@
#include "td/telegram/DialogId.h"
#include "td/telegram/DialogInviteLink.h"
#include "td/telegram/DialogParticipant.h"
#include "td/telegram/DialogParticipantFilter.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
@ -89,6 +90,9 @@ class DialogParticipantManager final : public Actor {
void get_channel_participant(ChannelId channel_id, DialogId participant_dialog_id,
Promise<DialogParticipant> &&promise);
void search_dialog_participants(DialogId dialog_id, const string &query, int32 limit, DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise);
void add_dialog_participant(DialogId dialog_id, UserId user_id, int32 forward_limit, Promise<Unit> &&promise);
void add_dialog_participants(DialogId dialog_id, const vector<UserId> &user_ids, Promise<Unit> &&promise);
@ -178,6 +182,9 @@ class DialogParticipantManager final : public Actor {
void finish_get_channel_participant(ChannelId channel_id, DialogParticipant &&dialog_participant,
Promise<DialogParticipant> &&promise);
DialogParticipants search_private_chat_participants(UserId my_user_id, UserId peer_user_id, const string &query,
int32 limit, DialogParticipantFilter filter) const;
void set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status, bool is_recursive,
Promise<Unit> &&promise);

View File

@ -13,6 +13,7 @@
#include "td/telegram/DialogActionManager.h"
#include "td/telegram/DialogManager.h"
#include "td/telegram/DialogParticipantFilter.h"
#include "td/telegram/DialogParticipantManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/MessageSender.h"
@ -2817,7 +2818,7 @@ void GroupCallManager::try_load_group_call_administrators(InputGroupCallId input
send_closure(actor_id, &GroupCallManager::finish_load_group_call_administrators, input_group_call_id,
std::move(result));
});
td_->contacts_manager_->search_dialog_participants(
td_->dialog_participant_manager_->search_dialog_participants(
dialog_id, string(), 100, DialogParticipantFilter(td_api::make_object<td_api::chatMembersFilterAdministrators>()),
std::move(promise));
}

View File

@ -7003,8 +7003,9 @@ void Td::on_request(uint64 id, td_api::searchChatMembers &request) {
promise.set_value(result.ok().get_chat_members_object(td, "searchChatMembers"));
}
});
contacts_manager_->search_dialog_participants(DialogId(request.chat_id_), request.query_, request.limit_,
DialogParticipantFilter(request.filter_), std::move(query_promise));
dialog_participant_manager_->search_dialog_participants(DialogId(request.chat_id_), request.query_, request.limit_,
DialogParticipantFilter(request.filter_),
std::move(query_promise));
}
void Td::on_request(uint64 id, const td_api::getChatAdministrators &request) {