Move search_chat_participants to DialogParticipantManager.

This commit is contained in:
levlam 2024-03-02 03:02:34 +03:00
parent 82e109a4d5
commit 3d9d6f51f4
4 changed files with 67 additions and 51 deletions

View File

@ -13234,6 +13234,14 @@ const DialogParticipant *ContactsManager::get_chat_full_participant(const ChatFu
return nullptr;
}
const vector<DialogParticipant> *ContactsManager::get_chat_participants(ChatId chat_id) const {
auto chat_full = get_chat_full(chat_id);
if (chat_full == nullptr) {
return nullptr;
}
return &chat_full->participants;
}
tl_object_ptr<td_api::chatMember> ContactsManager::get_chat_member_object(const DialogParticipant &dialog_participant,
const char *source) const {
return td_api::make_object<td_api::chatMember>(
@ -16638,49 +16646,6 @@ void ContactsManager::finish_get_chat_participant(ChatId chat_id, UserId user_id
promise.set_value(DialogParticipant(*participant));
}
void ContactsManager::search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantFilter filter, Promise<DialogParticipants> &&promise) {
if (limit < 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be non-negative"));
}
auto load_chat_full_promise = PromiseCreator::lambda([actor_id = actor_id(this), chat_id, query, limit, filter,
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &ContactsManager::do_search_chat_participants, chat_id, query, limit, filter,
std::move(promise));
}
});
load_chat_full(chat_id, false, std::move(load_chat_full_promise), "search_chat_participants");
}
void ContactsManager::do_search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
auto chat_full = get_chat_full(chat_id);
if (chat_full == nullptr) {
return promise.set_error(Status::Error(500, "Can't find basic group full info"));
}
vector<DialogId> dialog_ids;
for (const auto &participant : chat_full->participants) {
if (filter.is_dialog_participant_suitable(td_, participant)) {
dialog_ids.push_back(participant.dialog_id_);
}
}
int32 total_count;
std::tie(total_count, dialog_ids) = search_among_dialogs(dialog_ids, query, limit);
on_view_dialog_active_stories(dialog_ids);
promise.set_value(DialogParticipants{total_count, transform(dialog_ids, [chat_full](DialogId dialog_id) {
return *ContactsManager::get_chat_full_participant(chat_full, dialog_id);
})});
}
void ContactsManager::get_channel_participants(ChannelId channel_id,
tl_object_ptr<td_api::SupergroupMembersFilter> &&filter,
string additional_query, int32 offset, int32 limit,

View File

@ -612,6 +612,7 @@ class ContactsManager final : public Actor {
DialogParticipantStatus get_chat_permissions(ChatId chat_id) const;
bool is_appointed_chat_administrator(ChatId chat_id) const;
const DialogParticipant *get_chat_participant(ChatId chat_id, UserId user_id) const;
const vector<DialogParticipant> *get_chat_participants(ChatId chat_id) const;
void create_new_channel(const string &title, bool is_forum, bool is_megagroup, const string &description,
const DialogLocation &location, bool for_import, MessageTtl message_ttl,
@ -666,9 +667,6 @@ class ContactsManager final : public Actor {
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,
Promise<DialogParticipants> &&promise);
@ -1792,9 +1790,6 @@ class ContactsManager final : public Actor {
void update_dialogs_for_discussion(DialogId dialog_id, bool is_suitable);
void do_search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise);
void on_get_channel_participants(ChannelId channel_id, ChannelParticipantFilter &&filter, int32 offset, int32 limit,
string additional_query, int32 additional_limit,
tl_object_ptr<telegram_api::channels_channelParticipants> &&channel_participants,

View File

@ -1625,6 +1625,57 @@ DialogParticipants DialogParticipantManager::search_private_chat_participants(Us
})};
}
void DialogParticipantManager::search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise) {
if (limit < 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be non-negative"));
}
auto load_chat_full_promise = PromiseCreator::lambda([actor_id = actor_id(this), chat_id, query, limit, filter,
promise = std::move(promise)](Result<Unit> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
} else {
send_closure(actor_id, &DialogParticipantManager::do_search_chat_participants, chat_id, query, limit, filter,
std::move(promise));
}
});
td_->contacts_manager_->load_chat_full(chat_id, false, std::move(load_chat_full_promise), "search_chat_participants");
}
void DialogParticipantManager::do_search_chat_participants(ChatId chat_id, const string &query, int32 limit,
DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
const auto *participants = td_->contacts_manager_->get_chat_participants(chat_id);
if (participants == nullptr) {
return promise.set_error(Status::Error(500, "Can't find basic group full info"));
}
vector<DialogId> dialog_ids;
for (const auto &participant : *participants) {
if (filter.is_dialog_participant_suitable(td_, participant)) {
dialog_ids.push_back(participant.dialog_id_);
}
}
int32 total_count;
std::tie(total_count, dialog_ids) = td_->contacts_manager_->search_among_dialogs(dialog_ids, query, limit);
td_->contacts_manager_->on_view_dialog_active_stories(dialog_ids);
vector<DialogParticipant> dialog_participants;
for (auto dialog_id : dialog_ids) {
for (const auto &participant : *participants) {
if (participant.dialog_id_ == dialog_id) {
dialog_participants.push_back(participant);
break;
}
}
}
promise.set_value(DialogParticipants{total_count, std::move(dialog_participants)});
}
void DialogParticipantManager::search_dialog_participants(DialogId dialog_id, const string &query, int32 limit,
DialogParticipantFilter filter,
Promise<DialogParticipants> &&promise) {
@ -1641,8 +1692,7 @@ void DialogParticipantManager::search_dialog_participants(DialogId dialog_id, co
case DialogType::User:
return promise.set_value(search_private_chat_participants(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));
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()) {

View File

@ -185,6 +185,12 @@ class DialogParticipantManager final : public Actor {
DialogParticipants search_private_chat_participants(UserId peer_user_id, const string &query, int32 limit,
DialogParticipantFilter filter) const;
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);
void set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status, bool is_recursive,
Promise<Unit> &&promise);