From d9942a5765438807d21aaf646cfa43e5cb4c5f41 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 May 2024 13:45:04 +0300 Subject: [PATCH] Add searchUserByPhoneNumber.only_local. --- td/generate/scheme/td_api.tl | 6 ++++-- td/telegram/Td.cpp | 9 +++++---- td/telegram/UserManager.cpp | 8 ++++++-- td/telegram/UserManager.h | 2 +- td/telegram/cli.cpp | 4 ++-- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 4ad3a4465..6721b4e36 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -9708,8 +9708,10 @@ setUserPersonalProfilePhoto user_id:int53 photo:InputChatPhoto = Ok; suggestUserProfilePhoto user_id:int53 photo:InputChatPhoto = Ok; -//@description Searches a user by their phone number. Returns a 404 error if the user can't be found @phone_number Phone number to search for -searchUserByPhoneNumber phone_number:string = User; +//@description Searches a user by their phone number. Returns a 404 error if the user can't be found +//@phone_number Phone number to search for +//@only_local Pass true to get only locally available information without sending network requests +searchUserByPhoneNumber phone_number:string only_local:Bool = User; //@description Shares the phone number of the current user with a mutual contact. Supposed to be called when the user clicks on chatActionBarSharePhoneNumber @user_id Identifier of the user with whom to share the phone number. The user must be a mutual contact sharePhoneNumber user_id:int53 = Ok; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 4143ca061..5aafdc581 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -764,11 +764,12 @@ class GetChatRequest final : public RequestActor<> { class SearchUserByPhoneNumberRequest final : public RequestActor<> { string phone_number_; + bool only_local_; UserId user_id_; void do_run(Promise &&promise) final { - user_id_ = td_->user_manager_->search_user_by_phone_number(phone_number_, std::move(promise)); + user_id_ = td_->user_manager_->search_user_by_phone_number(phone_number_, only_local_, std::move(promise)); } void do_send_result() final { @@ -776,8 +777,8 @@ class SearchUserByPhoneNumberRequest final : public RequestActor<> { } public: - SearchUserByPhoneNumberRequest(ActorShared td, uint64 request_id, string &&phone_number) - : RequestActor(std::move(td), request_id), phone_number_(std::move(phone_number)) { + SearchUserByPhoneNumberRequest(ActorShared td, uint64 request_id, string &&phone_number, bool only_local) + : RequestActor(std::move(td), request_id), phone_number_(std::move(phone_number)), only_local_(only_local) { } }; @@ -7649,7 +7650,7 @@ void Td::on_request(uint64 id, td_api::suggestUserProfilePhoto &request) { void Td::on_request(uint64 id, td_api::searchUserByPhoneNumber &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.phone_number_); - CREATE_REQUEST(SearchUserByPhoneNumberRequest, std::move(request.phone_number_)); + CREATE_REQUEST(SearchUserByPhoneNumberRequest, std::move(request.phone_number_), request.only_local_); } void Td::on_request(uint64 id, const td_api::sharePhoneNumber &request) { diff --git a/td/telegram/UserManager.cpp b/td/telegram/UserManager.cpp index c9d03f137..4217808a7 100644 --- a/td/telegram/UserManager.cpp +++ b/td/telegram/UserManager.cpp @@ -6645,7 +6645,7 @@ void UserManager::on_set_close_friends(const vector &user_ids, Promise &&promise) { +UserId UserManager::search_user_by_phone_number(string phone_number, bool only_local, Promise &&promise) { clean_phone_number(phone_number); if (phone_number.empty()) { promise.set_error(Status::Error(200, "Phone number is invalid")); @@ -6658,7 +6658,11 @@ UserId UserManager::search_user_by_phone_number(string phone_number, Promisesecond; } - td_->create_handler(std::move(promise))->send(phone_number); + if (only_local) { + promise.set_value(Unit()); + } else { + td_->create_handler(std::move(promise))->send(phone_number); + } return UserId(); } diff --git a/td/telegram/UserManager.h b/td/telegram/UserManager.h index 261540874..b8c7b91ba 100644 --- a/td/telegram/UserManager.h +++ b/td/telegram/UserManager.h @@ -429,7 +429,7 @@ class UserManager final : public Actor { void on_set_close_friends(const vector &user_ids, Promise &&promise); - UserId search_user_by_phone_number(string phone_number, Promise &&promise); + UserId search_user_by_phone_number(string phone_number, bool only_local, Promise &&promise); void on_resolved_phone_number(const string &phone_number, UserId user_id); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index cacdd6ed0..65a828680 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2802,10 +2802,10 @@ class CliClient final : public Actor { get_args(args, user_id, first_name, last_name); send_request(td_api::make_object( td_api::make_object(string(), first_name, last_name, string(), user_id), false)); - } else if (op == "subpn") { + } else if (op == "subpn" || op == "subpnl") { string phone_number; get_args(args, phone_number); - send_request(td_api::make_object(phone_number)); + send_request(td_api::make_object(phone_number, op == "subpnl")); } else if (op == "spn") { UserId user_id; get_args(args, user_id);