Add searchUserByPhoneNumber.only_local.

This commit is contained in:
levlam 2024-05-14 13:45:04 +03:00
parent 6d780d02af
commit d9942a5765
5 changed files with 18 additions and 11 deletions

View File

@ -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;

View File

@ -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<Unit> &&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> td, uint64 request_id, string &&phone_number)
: RequestActor(std::move(td), request_id), phone_number_(std::move(phone_number)) {
SearchUserByPhoneNumberRequest(ActorShared<Td> 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) {

View File

@ -6645,7 +6645,7 @@ void UserManager::on_set_close_friends(const vector<UserId> &user_ids, Promise<U
promise.set_value(Unit());
}
UserId UserManager::search_user_by_phone_number(string phone_number, Promise<Unit> &&promise) {
UserId UserManager::search_user_by_phone_number(string phone_number, bool only_local, Promise<Unit> &&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, Promise<Uni
return it->second;
}
if (only_local) {
promise.set_value(Unit());
} else {
td_->create_handler<ResolvePhoneQuery>(std::move(promise))->send(phone_number);
}
return UserId();
}

View File

@ -429,7 +429,7 @@ class UserManager final : public Actor {
void on_set_close_friends(const vector<UserId> &user_ids, Promise<Unit> &&promise);
UserId search_user_by_phone_number(string phone_number, Promise<Unit> &&promise);
UserId search_user_by_phone_number(string phone_number, bool only_local, Promise<Unit> &&promise);
void on_resolved_phone_number(const string &phone_number, UserId user_id);

View File

@ -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::addContact>(
td_api::make_object<td_api::contact>(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<td_api::searchUserByPhoneNumber>(phone_number));
send_request(td_api::make_object<td_api::searchUserByPhoneNumber>(phone_number, op == "subpnl"));
} else if (op == "spn") {
UserId user_id;
get_args(args, user_id);