From 3aa55a2e894fb0f6e5e51abb2d9d8315d5174f21 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 14 Feb 2020 16:17:45 +0300 Subject: [PATCH] Add setLocation method. GitOrigin-RevId: 43fef89f4d2175cf9ec5a20409979c988e781a28 --- td/generate/scheme/td_api.tl | 3 +++ td/generate/scheme/td_api.tlo | Bin 167284 -> 167372 bytes td/telegram/ContactsManager.cpp | 14 ++++++++++++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/Td.cpp | 6 ++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 6 ++++++ 7 files changed, 33 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d520a54e5..f0478d03e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3901,6 +3901,9 @@ setBio bio:string = Ok; //@description Changes the username of the current user. If something changes, updateUser will be sent @username The new value of the username. Use an empty string to remove the username setUsername username:string = Ok; +//@description Changes the location of the current user. Needs to be called if GetOption("is_location_visible") is true and location changes for more than 1 kilometer @location The new location of the user +setLocation location:location = Ok; + //@description Changes the phone number of the user and sends an authentication code to the user's new phone number. On success, returns information about the sent code //@phone_number The new phone number of the user in international format @settings Settings for the authentication of the user's phone number changePhoneNumber phone_number:string settings:phoneNumberAuthenticationSettings = AuthenticationCodeInfo; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 1b8539dbdce87bde799d84cbed04476dc97be18d..761a9c091b7c0eb9886a64ef13d5cec35a376353 100644 GIT binary patch delta 51 zcmV-30L=gNnhMOD3V^f$wAuk~x3$^<3z-ygGnoYob7gc)Z)0I}X>V?6zU|bP&{P66 Jx3F^p#2Hdr7M}nB delta 25 hcmX>zo9oLgu7)j)TW&GtZr^%~k$dKLi4vwQk^rAG3pfA( diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 2f3563c0f..6e3bd52b2 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4852,6 +4852,20 @@ void ContactsManager::search_dialogs_nearby(const Location &location, td_->create_handler(std::move(query_promise))->send(location, false, -1); } +void ContactsManager::set_location(const Location &location, Promise &&promise) { + if (location.empty()) { + return promise.set_error(Status::Error(400, "Invalid location specified")); + } + last_user_location_ = location; + try_send_set_location_visibility_query(); + + auto query_promise = PromiseCreator::lambda( + [promise = std::move(promise)](Result> result) mutable { + promise.set_value(Unit()); + }); + td_->create_handler(std::move(query_promise))->send(location, true, -1); +} + vector> ContactsManager::get_chats_nearby_object( const vector &dialogs_nearby) { return transform(dialogs_nearby, [](const DialogNearby &dialog_nearby) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index fa6829029..9eeacd666 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -313,6 +313,8 @@ class ContactsManager : public Actor { void search_dialogs_nearby(const Location &location, Promise> &&promise); + void set_location(const Location &location, Promise &&promise); + void set_location_visibility(); void set_profile_photo(const tl_object_ptr &input_photo, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 607ac9dea..64017a7d3 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6170,6 +6170,12 @@ void Td::on_request(uint64 id, td_api::setUsername &request) { contacts_manager_->set_username(request.username_, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::setLocation &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->set_location(Location(request.location_), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setProfilePhoto &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index b82af9df9..a8e8b45c4 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -781,6 +781,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::setUsername &request); + void on_request(uint64 id, const td_api::setLocation &request); + void on_request(uint64 id, td_api::setProfilePhoto &request); void on_request(uint64 id, const td_api::deleteProfilePhoto &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index d62f45807..5c08d25bb 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3701,6 +3701,12 @@ class CliClient final : public Actor { std::tie(latitude, longitude) = split(args); send_request(td_api::make_object(as_location(latitude, longitude))); + } else if (op == "sloc") { + string latitude; + string longitude; + + std::tie(latitude, longitude) = split(args); + send_request(td_api::make_object(as_location(latitude, longitude))); } else if (op == "sco") { string limit; string query;