From 370d862acf632888f8989c267e981407e6f07c8d Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 23 Feb 2024 21:03:44 +0300 Subject: [PATCH] Support address-only business location. --- td/generate/scheme/td_api.tl | 8 ++++++-- td/telegram/ContactsManager.cpp | 7 +++++-- td/telegram/DialogLocation.cpp | 17 +++++++++++++++++ td/telegram/DialogLocation.h | 4 ++++ td/telegram/cli.cpp | 6 +++--- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d10ee890f..66d31feb7 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -576,6 +576,10 @@ botMenuButton text:string url:string = BotMenuButton; chatLocation location:location address:string = ChatLocation; +//@description Represents a location of a business @location The location; may be null if not specified @address Location address; 1-96 characters +businessLocation location:location address:string = BusinessLocation; + + //@description Describes an interval of time when the business is open //@start_minute The first minute of the interval since start of the week; 0-7*24*60 //@end_minute The first minute after the end of the interval since start of the week; 1-8*24*60 @@ -859,7 +863,7 @@ botInfo short_description:string description:string photo:photo animation:animat //@business_location Location of the business for Telegram Business users; may be null if none //@business_work_hours Work hours of the business for Telegram Business users; may be null if none //@bot_info For bots, information about the bot; may be null if the user isn't a bot -userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool set_chat_background:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 business_location:chatLocation business_work_hours:businessWorkHours bot_info:botInfo = UserFullInfo; +userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool set_chat_background:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 business_location:businessLocation business_work_hours:businessWorkHours bot_info:botInfo = UserFullInfo; //@description Represents a list of users @total_count Approximate total number of users found @user_ids A list of user identifiers users total_count:int32 user_ids:vector = Users; @@ -9297,7 +9301,7 @@ setEmojiStatus emoji_status:emojiStatus = Ok; 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; +setBusinessLocation location:businessLocation = Ok; //@description Changes the business work hours of the current user. Requires Telegram Business subscription @work_hours The new work hours of the business; pass null to remove the work hours setBusinessWorkHours work_hours:businessWorkHours = Ok; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index e30e6351b..18b66f02f 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1105,6 +1105,9 @@ class UpdateBusinessLocationQuery final : public Td::ResultHandler { if (!location_.empty()) { flags |= telegram_api::account_updateBusinessLocation::GEO_POINT_MASK; } + if (!location_.get_address().empty()) { + flags |= telegram_api::account_updateBusinessLocation::ADDRESS_MASK; + } send_query(G()->net_query_creator().create( telegram_api::account_updateBusinessLocation(flags, location_.get_input_geo_point(), location_.get_address()), {{"me"}})); @@ -3498,7 +3501,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const { bool has_premium_gift_options = !premium_gift_options.empty(); bool has_personal_photo = !personal_photo.is_empty(); bool has_fallback_photo = !fallback_photo.is_empty(); - bool has_location = !location.empty(); + bool has_location = !location.empty() || !location.get_address().empty(); bool has_work_hours = !work_hours.is_empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_about); @@ -17158,7 +17161,7 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U !user_full->private_forward_name.empty(), voice_messages_forbidden, user_full->has_pinned_stories, user_full->need_phone_number_privacy_exception, user_full->wallpaper_overridden, std::move(bio_object), get_premium_payment_options_object(user_full->premium_gift_options), user_full->common_chat_count, - user_full->location.get_chat_location_object(), user_full->work_hours.get_business_work_hours_object(), + user_full->location.get_business_location_object(), user_full->work_hours.get_business_work_hours_object(), std::move(bot_info)); } diff --git a/td/telegram/DialogLocation.cpp b/td/telegram/DialogLocation.cpp index 7ecf39bae..c12df81b7 100644 --- a/td/telegram/DialogLocation.cpp +++ b/td/telegram/DialogLocation.cpp @@ -35,6 +35,16 @@ DialogLocation::DialogLocation(td_api::object_ptr &&chat_l } } +DialogLocation::DialogLocation(td_api::object_ptr &&business_location) { + if (business_location != nullptr) { + location_ = Location(business_location->location_); + address_ = std::move(business_location->address_); + if (!clean_input_string(address_)) { + address_.clear(); + } + } +} + bool DialogLocation::empty() const { return location_.empty(); } @@ -46,6 +56,13 @@ td_api::object_ptr DialogLocation::get_chat_location_objec return td_api::make_object(location_.get_location_object(), address_); } +td_api::object_ptr DialogLocation::get_business_location_object() const { + if (empty() && address_.empty()) { + return nullptr; + } + return td_api::make_object(location_.get_location_object(), address_); +} + telegram_api::object_ptr DialogLocation::get_input_geo_point() const { return location_.get_input_geo_point(); } diff --git a/td/telegram/DialogLocation.h b/td/telegram/DialogLocation.h index 0c04abf2d..7c8866097 100644 --- a/td/telegram/DialogLocation.h +++ b/td/telegram/DialogLocation.h @@ -36,10 +36,14 @@ class DialogLocation { explicit DialogLocation(td_api::object_ptr &&chat_location); + explicit DialogLocation(td_api::object_ptr &&business_location); + bool empty() const; td_api::object_ptr get_chat_location_object() const; + td_api::object_ptr DialogLocation::get_business_location_object() const; + telegram_api::object_ptr get_input_geo_point() const; const string &get_address() const; diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 03e5ab593..8b85aa47a 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5907,11 +5907,11 @@ class CliClient final : public Actor { string latitude; string longitude; get_args(args, latitude, longitude); - if (latitude.empty() || longitude.empty()) { + if (latitude.empty()) { send_request(td_api::make_object(nullptr)); } else { - send_request(td_api::make_object( - td_api::make_object(as_location(latitude, longitude, string()), "business address"))); + send_request(td_api::make_object(td_api::make_object( + longitude.empty() ? nullptr : as_location(latitude, longitude, string()), "business address"))); } } else if (op == "sbwh") { string time_zone_id;