diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 6d9dab2a4..0e8f9bff4 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13234,6 +13234,14 @@ const DialogParticipant *ContactsManager::get_chat_full_participant(const ChatFu return nullptr; } +const vector *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 ContactsManager::get_chat_member_object(const DialogParticipant &dialog_participant, const char *source) const { return td_api::make_object( @@ -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 &&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 &&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 &&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 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 &&filter, string additional_query, int32 offset, int32 limit, diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 989a31bfb..b7d46f9cd 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -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 *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> search_among_dialogs(const vector &dialog_ids, const string &query, int32 limit) const; - void search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantFilter filter, - Promise &&promise); - void get_channel_participants(ChannelId channel_id, tl_object_ptr &&filter, string additional_query, int32 offset, int32 limit, int32 additional_limit, Promise &&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 &&promise); - void on_get_channel_participants(ChannelId channel_id, ChannelParticipantFilter &&filter, int32 offset, int32 limit, string additional_query, int32 additional_limit, tl_object_ptr &&channel_participants, diff --git a/td/telegram/DialogParticipantManager.cpp b/td/telegram/DialogParticipantManager.cpp index 4147c2e56..3aa80ab61 100644 --- a/td/telegram/DialogParticipantManager.cpp +++ b/td/telegram/DialogParticipantManager.cpp @@ -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 &&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 &&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 &&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 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 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 &&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()) { diff --git a/td/telegram/DialogParticipantManager.h b/td/telegram/DialogParticipantManager.h index 2d4af6ae3..f7b7ebf77 100644 --- a/td/telegram/DialogParticipantManager.h +++ b/td/telegram/DialogParticipantManager.h @@ -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 &&promise); + + void do_search_chat_participants(ChatId chat_id, const string &query, int32 limit, DialogParticipantFilter filter, + Promise &&promise); + void set_chat_participant_status(ChatId chat_id, UserId user_id, DialogParticipantStatus status, bool is_recursive, Promise &&promise);