diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 915c1572e..b6404603b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7509,7 +7509,7 @@ addContact contact:contact share_phone_number:Bool = Ok; //@description Adds new contacts or edits existing contacts by their phone numbers; contacts' user identifiers are ignored @contacts The list of contacts to import or edit; contacts' vCard are ignored and are not imported importContacts contacts:vector = ImportedContacts; -//@description Returns all user contacts +//@description Returns all contacts of the user getContacts = Users; //@description Searches for the specified query in the first names, last names and usernames of the known user contacts @@ -7531,6 +7531,9 @@ changeImportedContacts contacts:vector = ImportedContacts; //@description Clears all imported contacts, contact list remains unchanged clearImportedContacts = Ok; +//@description Returns all close friends of the user +getCloseFriends = Users; + //@description Changes a personal profile photo of a contact user @user_id User identifier @photo Profile photo to set; pass null to delete the photo; inputChatPhotoPrevious isn't supported in this function setUserPersonalProfilePhoto user_id:int53 photo:InputChatPhoto = Ok; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 7f224bc9a..4012a77cf 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -6858,6 +6858,28 @@ std::pair> ContactsManager::search_contacts(const string & return {narrow_cast(result.first), std::move(user_ids)}; } +vector ContactsManager::get_close_friends(Promise &&promise) { + if (!are_contacts_loaded_) { + load_contacts(std::move(promise)); + return {}; + } + reload_contacts(false); + + auto result = contacts_hints_.search_empty(10000); + + vector user_ids; + for (auto key : result.second) { + UserId user_id(key); + const User *u = get_user(user_id); + if (u != nullptr && u->is_close_friend) { + user_ids.push_back(user_id); + } + } + + promise.set_value(Unit()); + return user_ids; +} + UserId ContactsManager::search_user_by_phone_number(string phone_number, Promise &&promise) { clean_phone_number(phone_number); if (phone_number.empty()) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 8d58a932a..dbd81f2d2 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -358,6 +358,8 @@ class ContactsManager final : public Actor { void on_update_contacts_reset(); + vector get_close_friends(Promise &&promise); + UserId search_user_by_phone_number(string phone_number, Promise &&promise); void on_resolved_phone_number(const string &phone_number, UserId user_id); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 25a9e00a1..70ac5e0a1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1889,6 +1889,22 @@ class ChangeImportedContactsRequest final : public RequestActor<> { } }; +class GetCloseFriendsRequest final : public RequestActor<> { + vector user_ids_; + + void do_run(Promise &&promise) final { + user_ids_ = td_->contacts_manager_->get_close_friends(std::move(promise)); + } + + void do_send_result() final { + send_result(td_->contacts_manager_->get_users_object(-1, user_ids_)); + } + + public: + GetCloseFriendsRequest(ActorShared td, uint64 request_id) : RequestActor(std::move(td), request_id) { + } +}; + class GetRecentInlineBotsRequest final : public RequestActor<> { vector user_ids_; @@ -6976,6 +6992,11 @@ void Td::on_request(uint64 id, const td_api::clearImportedContacts &request) { contacts_manager_->clear_imported_contacts(std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getCloseFriends &request) { + CHECK_IS_USER(); + CREATE_NO_ARGS_REQUEST(GetCloseFriendsRequest); +} + void Td::on_request(uint64 id, td_api::setUserPersonalProfilePhoto &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 29bcbd8c7..998291b9d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1125,6 +1125,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::clearImportedContacts &request); + void on_request(uint64 id, const td_api::getCloseFriends &request); + void on_request(uint64 id, td_api::setUserPersonalProfilePhoto &request); void on_request(uint64 id, td_api::suggestUserProfilePhoto &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 2824d8cc4..0a2828678 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2391,6 +2391,8 @@ class CliClient final : public Actor { } else { send_request(td_api::make_object("", as_limit(args))); } + } else if (op == "gcfr") { + send_request(td_api::make_object()); } else if (op == "gul") { send_request(td_api::make_object()); } else if (op == "subt") {