Add td_api::setBusinessLocation.

This commit is contained in:
levlam 2024-02-20 12:49:30 +03:00
parent 9c51809490
commit 8d9edcb31d
6 changed files with 62 additions and 1 deletions

View File

@ -9244,9 +9244,12 @@ reorderActiveUsernames usernames:vector<string> = 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

View File

@ -1090,6 +1090,41 @@ class UpdateEmojiStatusQuery final : public Td::ResultHandler {
}
};
class UpdateBusinessLocationQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogLocation location_;
public:
explicit UpdateBusinessLocationQuery(Promise<Unit> &&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<telegram_api::account_updateBusinessLocation>(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<td_api::object_ptr<td_api::chat>> promise_;
@ -6944,6 +6979,10 @@ void ContactsManager::on_set_emoji_status(EmojiStatus emoji_status, Promise<Unit
promise.set_value(Unit());
}
void ContactsManager::set_business_location(DialogLocation &&location, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location));
}
void ContactsManager::set_chat_description(ChatId chat_id, const string &description, Promise<Unit> &&promise) {
auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH);
auto c = get_chat(chat_id);

View File

@ -463,6 +463,8 @@ class ContactsManager final : public Actor {
void set_emoji_status(const EmojiStatus &emoji_status, Promise<Unit> &&promise);
void set_business_location(DialogLocation &&location, Promise<Unit> &&promise);
void set_chat_description(ChatId chat_id, const string &description, Promise<Unit> &&promise);
void set_channel_username(ChannelId channel_id, const string &username, Promise<Unit> &&promise);

View File

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

View File

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

View File

@ -5901,6 +5901,15 @@ class CliClient final : public Actor {
string longitude;
get_args(args, latitude, longitude);
send_request(td_api::make_object<td_api::setLocation>(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<td_api::setBusinessLocation>(nullptr));
}
send_request(td_api::make_object<td_api::setBusinessLocation>(
td_api::make_object<td_api::chatLocation>(as_location(latitude, longitude, string()), "business address")));
} else if (op == "sco") {
SearchQuery query;
get_args(args, query);