Add td_api::locationAddress for location story areas.

This commit is contained in:
levlam 2024-06-07 16:13:58 +03:00
parent 98614f6f79
commit dcd532d1c0
5 changed files with 132 additions and 7 deletions

View File

@ -2607,6 +2607,13 @@ bankCardInfo title:string actions:vector<bankCardActionOpenUrl> = BankCardInfo;
//@postal_code Address postal code
address country_code:string state:string city:string street_line1:string street_line2:string postal_code:string = Address;
//@description Describes an address of a location
//@country_code A two-letter ISO 3166-1 alpha-2 country code
//@state State, if applicable; empty if unknown
//@city City; empty if unknown
//@street The address; empty if unknown
locationAddress country_code:string state:string city:string street:string = LocationAddress;
//@description Contains parameters of the application theme
//@background_color A color of the background in the RGB24 format
@ -3867,8 +3874,8 @@ storyAreaPosition x_percentage:double y_percentage:double width_percentage:doubl
//@class StoryAreaType @description Describes type of clickable rectangle area on a story media
//@description An area pointing to a location @location The location
storyAreaTypeLocation location:location = StoryAreaType;
//@description An area pointing to a location @location The location @address Address of the location; may be null if unknown
storyAreaTypeLocation location:location address:locationAddress = StoryAreaType;
//@description An area pointing to a venue @venue Information about the venue
storyAreaTypeVenue venue:venue = StoryAreaType;
@ -3893,8 +3900,8 @@ storyArea position:storyAreaPosition type:StoryAreaType = StoryArea;
//@class InputStoryAreaType @description Describes type of clickable rectangle area on a story media to be added
//@description An area pointing to a location @location The location
inputStoryAreaTypeLocation location:location = InputStoryAreaType;
//@description An area pointing to a location @location The location @address Address of the location; pass null if unknown
inputStoryAreaTypeLocation location:location address:locationAddress = InputStoryAreaType;
//@description An area pointing to a venue found by the bot getOption("venue_search_bot_username")
//@query_id Identifier of the inline query, used to found the venue

View File

@ -29,6 +29,12 @@ MediaArea::MediaArea(Td *td, telegram_api::object_ptr<telegram_api::MediaArea> &
auto area = telegram_api::move_object_as<telegram_api::mediaAreaGeoPoint>(media_area_ptr);
coordinates_ = MediaAreaCoordinates(area->coordinates_);
location_ = Location(td, area->geo_);
if (area->address_ != nullptr) {
address_.country_iso2_ = area->address_->country_iso2_;
address_.state_ = area->address_->state_;
address_.city_ = area->address_->city_;
address_.street_ = area->address_->street_;
}
if (coordinates_.is_valid() && !location_.empty()) {
type_ = Type::Location;
} else {
@ -109,6 +115,16 @@ MediaArea::MediaArea(Td *td, td_api::object_ptr<td_api::inputStoryArea> &&input_
case td_api::inputStoryAreaTypeLocation::ID: {
auto type = td_api::move_object_as<td_api::inputStoryAreaTypeLocation>(input_story_area->type_);
location_ = Location(type->location_);
if (type->address_ != nullptr) {
address_.country_iso2_ = std::move(type->address_->country_code_);
address_.state_ = std::move(type->address_->state_);
address_.city_ = std::move(type->address_->city_);
address_.street_ = std::move(type->address_->street_);
if (!clean_input_string(address_.country_iso2_) || !clean_input_string(address_.state_) ||
!clean_input_string(address_.city_) || !clean_input_string(address_.street_)) {
break;
}
}
if (!location_.empty()) {
type_ = Type::Location;
}
@ -203,7 +219,11 @@ td_api::object_ptr<td_api::storyArea> MediaArea::get_story_area_object(
td_api::object_ptr<td_api::StoryAreaType> type;
switch (type_) {
case Type::Location:
type = td_api::make_object<td_api::storyAreaTypeLocation>(location_.get_location_object());
type = td_api::make_object<td_api::storyAreaTypeLocation>(
location_.get_location_object(),
address_.is_empty() ? nullptr
: td_api::make_object<td_api::locationAddress>(address_.country_iso2_, address_.state_,
address_.city_, address_.street_));
break;
case Type::Venue:
type = td_api::make_object<td_api::storyAreaTypeVenue>(venue_.get_venue_object());
@ -238,8 +258,25 @@ telegram_api::object_ptr<telegram_api::MediaArea> MediaArea::get_input_media_are
switch (type_) {
case Type::Location: {
int32 flags = 0;
telegram_api::object_ptr<telegram_api::geoPointAddress> address;
if (!address_.is_empty()) {
int32 address_flags = 0;
if (!address_.state_.empty()) {
address_flags |= telegram_api::geoPointAddress::STATE_MASK;
}
if (!address_.city_.empty()) {
address_flags |= telegram_api::geoPointAddress::CITY_MASK;
}
if (!address_.street_.empty()) {
address_flags |= telegram_api::geoPointAddress::STREET_MASK;
}
address = telegram_api::make_object<telegram_api::geoPointAddress>(
address_flags, address_.country_iso2_, address_.state_, address_.city_, address_.street_);
flags |= telegram_api::mediaAreaGeoPoint::ADDRESS_MASK;
}
return telegram_api::make_object<telegram_api::mediaAreaGeoPoint>(
flags, coordinates_.get_input_media_area_coordinates(), location_.get_fake_geo_point(), nullptr);
flags, coordinates_.get_input_media_area_coordinates(), location_.get_fake_geo_point(), std::move(address));
}
case Type::Venue:
if (input_query_id_ != 0) {

View File

@ -25,10 +25,28 @@ class Dependencies;
class Td;
class MediaArea {
struct GeoPointAddress {
string country_iso2_;
string state_;
string city_;
string street_;
bool is_empty() const {
return country_iso2_.empty();
}
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
enum class Type : int32 { None, Location, Venue, Reaction, Message, Url };
Type type_ = Type::None;
MediaAreaCoordinates coordinates_;
Location location_;
GeoPointAddress address_;
Venue venue_;
MessageFullId message_full_id_;
int64 input_query_id_ = 0;

View File

@ -13,15 +13,69 @@
namespace td {
template <class StorerT>
void MediaArea::GeoPointAddress::store(StorerT &storer) const {
bool has_country_iso2 = !country_iso2_.empty();
bool has_state = !state_.empty();
bool has_city = !city_.empty();
bool has_street = !street_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_country_iso2);
STORE_FLAG(has_state);
STORE_FLAG(has_city);
STORE_FLAG(has_street);
END_STORE_FLAGS();
if (has_country_iso2) {
td::store(country_iso2_, storer);
}
if (has_state) {
td::store(state_, storer);
}
if (has_city) {
td::store(city_, storer);
}
if (has_street) {
td::store(street_, storer);
}
}
template <class ParserT>
void MediaArea::GeoPointAddress::parse(ParserT &parser) {
bool has_country_iso2;
bool has_state;
bool has_city;
bool has_street;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_country_iso2);
PARSE_FLAG(has_state);
PARSE_FLAG(has_city);
PARSE_FLAG(has_street);
END_PARSE_FLAGS();
if (has_country_iso2) {
td::parse(country_iso2_, parser);
}
if (has_state) {
td::parse(state_, parser);
}
if (has_city) {
td::parse(city_, parser);
}
if (has_street) {
td::parse(street_, parser);
}
}
template <class StorerT>
void MediaArea::store(StorerT &storer) const {
using td::store;
bool has_input_query_id = input_query_id_ != 0;
bool has_address = !address_.is_empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_input_query_id);
STORE_FLAG(is_dark_);
STORE_FLAG(is_flipped_);
STORE_FLAG(is_old_message_);
STORE_FLAG(has_address);
END_STORE_FLAGS();
store(type_, storer);
store(coordinates_, storer);
@ -48,17 +102,22 @@ void MediaArea::store(StorerT &storer) const {
default:
UNREACHABLE();
}
if (has_address) {
store(address_, storer);
}
}
template <class ParserT>
void MediaArea::parse(ParserT &parser) {
using td::parse;
bool has_input_query_id;
bool has_address;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_input_query_id);
PARSE_FLAG(is_dark_);
PARSE_FLAG(is_flipped_);
PARSE_FLAG(is_old_message_);
PARSE_FLAG(has_address);
END_PARSE_FLAGS();
parse(type_, parser);
parse(coordinates_, parser);
@ -85,6 +144,9 @@ void MediaArea::parse(ParserT &parser) {
default:
parser.set_error("Load invalid area type");
}
if (has_address) {
parse(address_, parser);
}
}
} // namespace td

View File

@ -1359,7 +1359,8 @@ class CliClient final : public Actor {
td_api::object_ptr<td_api::InputStoryAreaType> type;
if (area == "l") {
type = td_api::make_object<td_api::inputStoryAreaTypeLocation>(
td_api::make_object<td_api::location>(Random::fast(-50, 50), Random::fast(-50, 50), 0.0));
td_api::make_object<td_api::location>(Random::fast(-50, 50), Random::fast(-50, 50), 0.0),
td_api::make_object<td_api::locationAddress>("US", "ZZ", "Deniles", "Road"));
} else if (area[0] == 'v') {
string query_id;
string result_id;