diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 1530b8713..6a2fe616f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -9244,9 +9244,12 @@ reorderActiveUsernames usernames:vector = Ok; //@description Changes the emoji status of the current user; for Telegram Premium users only @emoji_status New emoji status; pass null to switch to the default badge setEmojiStatus emoji_status:emojiStatus = 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 +//@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. Must not be called if the user has a business location @location The new location of the user setLocation location:location = Ok; +//@description Changes the business location of the current user. Requires Telegram Business subscription @location The new location of the business; pass null to remove the location +setBusinessLocation location:chatLocation = Ok; + //@description Changes the phone number of the user and sends an authentication code to the user's new phone number; for official Android and iOS applications only. 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; pass null to use default settings diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index f325f22df..e672ae220 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1090,6 +1090,41 @@ class UpdateEmojiStatusQuery final : public Td::ResultHandler { } }; +class UpdateBusinessLocationQuery final : public Td::ResultHandler { + Promise promise_; + DialogLocation location_; + + public: + explicit UpdateBusinessLocationQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(DialogLocation &&location) { + location_ = std::move(location); + int32 flags = 0; + if (!location_.empty()) { + flags |= telegram_api::account_updateBusinessLocation::GEO_POINT_MASK; + } + send_query(G()->net_query_creator().create( + telegram_api::account_updateBusinessLocation(flags, location_.get_input_geo_point(), location_.get_address()), + {{"me"}})); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + td_->contacts_manager_->on_update_user_location(td_->contacts_manager_->get_my_id(), std::move(location_)); + + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class CreateChatQuery final : public Td::ResultHandler { Promise> promise_; @@ -6944,6 +6979,10 @@ void ContactsManager::on_set_emoji_status(EmojiStatus emoji_status, Promise &&promise) { + td_->create_handler(std::move(promise))->send(std::move(location)); +} + void ContactsManager::set_chat_description(ChatId chat_id, const string &description, Promise &&promise) { auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH); auto c = get_chat(chat_id); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 157984d4b..9c6eb527b 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -463,6 +463,8 @@ class ContactsManager final : public Actor { void set_emoji_status(const EmojiStatus &emoji_status, Promise &&promise); + void set_business_location(DialogLocation &&location, Promise &&promise); + void set_chat_description(ChatId chat_id, const string &description, Promise &&promise); void set_channel_username(ChannelId channel_id, const string &username, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 0b3b5cb3a..359c9b262 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7738,6 +7738,12 @@ void Td::on_request(uint64 id, const td_api::setLocation &request) { contacts_manager_->set_location(Location(request.location_), std::move(promise)); } +void Td::on_request(uint64 id, td_api::setBusinessLocation &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->set_business_location(DialogLocation(std::move(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 513117b5c..f8587afdc 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1367,6 +1367,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::setLocation &request); + void on_request(uint64 id, td_api::setBusinessLocation &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 4fa209c6e..e3c7d5ed1 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5901,6 +5901,15 @@ class CliClient final : public Actor { string longitude; get_args(args, latitude, longitude); send_request(td_api::make_object(as_location(latitude, longitude, string()))); + } else if (op == "sbl") { + string latitude; + string longitude; + get_args(args, latitude, longitude); + if (latitude.empty() || longitude.empty()) { + send_request(td_api::make_object(nullptr)); + } + send_request(td_api::make_object( + td_api::make_object(as_location(latitude, longitude, string()), "business address"))); } else if (op == "sco") { SearchQuery query; get_args(args, query);