diff --git a/CMakeLists.txt b/CMakeLists.txt index b3987f3f8..ed447e756 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -386,6 +386,7 @@ set(TDLIB_SOURCE td/telegram/Location.cpp td/telegram/logevent/LogEventHelper.cpp td/telegram/Logging.cpp + td/telegram/MediaArea.cpp td/telegram/MediaAreaCoordinates.cpp td/telegram/MessageContent.cpp td/telegram/MessageContentType.cpp @@ -660,6 +661,7 @@ set(TDLIB_SOURCE td/telegram/logevent/LogEventHelper.h td/telegram/logevent/SecretChatEvent.h td/telegram/Logging.h + td/telegram/MediaArea.h td/telegram/MediaAreaCoordinates.h td/telegram/MessageContent.h td/telegram/MessageContentType.h @@ -834,6 +836,7 @@ set(TDLIB_SOURCE td/telegram/Game.hpp td/telegram/InputInvoice.hpp td/telegram/InputMessageText.hpp + td/telegram/MediaArea.hpp td/telegram/MediaAreaCoordinates.hpp td/telegram/MessageEntity.hpp td/telegram/MessageExtendedMedia.hpp diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 135e4329a..ec8a4dab4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4907,7 +4907,7 @@ messageLink link:string is_public:Bool = MessageLink; messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:message media_timestamp:int32 for_album:Bool = MessageLinkInfo; -//@description Describes a clickable rectangle area on a story media +//@description Describes position of a clickable rectangle area on a story media //@x_percentage The abscissa of the rectangle's center, as a percentage of the media width //@y_percentage The ordinate of the rectangle's center, as a percentage of the media height //@width_percentage The width of the rectangle, as a percentage of the media width @@ -4916,6 +4916,19 @@ messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:mes storyAreaPosition x_percentage:double y_percentage:double width_percentage:double height_percentage:double rotation_angle:double = StoryAreaPosition; +//@class StoryAreaType @description Describes type of a 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 venue @venue Information about the venue +storyAreaTypeVenue venue:venue = StoryAreaType; + + +//@description Describes a clickable rectangle area on a story media @position Position of the area @type Type of the area +storyArea position:storyAreaPosition type:StoryAreaType = StoryArea; + + //@description Describes a video file sent in a story //@duration Duration of the video, in seconds //@width Video width diff --git a/td/telegram/MediaArea.cpp b/td/telegram/MediaArea.cpp new file mode 100644 index 000000000..dcbbbb1bc --- /dev/null +++ b/td/telegram/MediaArea.cpp @@ -0,0 +1,75 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/telegram/MediaArea.h" + +namespace td { + +MediaArea::MediaArea(Td *td, telegram_api::object_ptr &&media_area_ptr) { + CHECK(media_area_ptr != nullptr); + switch (media_area_ptr->get_id()) { + case telegram_api::mediaAreaGeoPoint::ID: { + auto area = telegram_api::move_object_as(media_area_ptr); + coordinates_ = MediaAreaCoordinates(area->coordinates_); + location_ = Location(td, area->geo_); + if (coordinates_.is_valid() && !location_.empty()) { + type_ = Type::Location; + } else { + LOG(ERROR) << "Receive " << to_string(area); + } + break; + } + case telegram_api::mediaAreaVenue::ID: { + auto area = telegram_api::move_object_as(media_area_ptr); + coordinates_ = MediaAreaCoordinates(area->coordinates_); + venue_ = Venue(td, area->geo_, std::move(area->title_), std::move(area->address_), std::move(area->provider_), + std::move(area->venue_id_), std::move(area->venue_type_)); + if (coordinates_.is_valid() && !venue_.empty()) { + type_ = Type::Venue; + } else { + LOG(ERROR) << "Receive " << to_string(area); + } + break; + } + case telegram_api::inputMediaAreaVenue::ID: + LOG(ERROR) << "Receive " << to_string(media_area_ptr); + break; + default: + UNREACHABLE(); + } +} + +td_api::object_ptr MediaArea::get_story_area_object() const { + CHECK(is_valid()); + td_api::object_ptr type; + switch (type_) { + case Type::Location: + type = td_api::make_object(location_.get_location_object()); + break; + case Type::Venue: + type = td_api::make_object(venue_.get_venue_object()); + break; + default: + UNREACHABLE(); + } + return td_api::make_object(coordinates_.get_story_area_position_object(), std::move(type)); +} + +bool operator==(const MediaArea &lhs, const MediaArea &rhs) { + return lhs.type_ == rhs.type_ && lhs.coordinates_ == rhs.coordinates_ && lhs.location_ == rhs.location_ && + lhs.venue_ == rhs.venue_; +} + +bool operator!=(const MediaArea &lhs, const MediaArea &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const MediaArea &media_area) { + return string_builder << "StoryArea[" << media_area.coordinates_ << ": " << media_area.location_ << '/' + << media_area.venue_ << ']'; +} + +} // namespace td diff --git a/td/telegram/MediaArea.h b/td/telegram/MediaArea.h new file mode 100644 index 000000000..8e10f6e69 --- /dev/null +++ b/td/telegram/MediaArea.h @@ -0,0 +1,57 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/Location.h" +#include "td/telegram/MediaAreaCoordinates.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" +#include "td/telegram/Venue.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class Td; + +class MediaArea { + enum class Type : int32 { None, Location, Venue }; + Type type_ = Type::None; + MediaAreaCoordinates coordinates_; + Location location_; + Venue venue_; + + friend bool operator==(const MediaArea &lhs, const MediaArea &rhs); + friend bool operator!=(const MediaArea &lhs, const MediaArea &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const MediaArea &media_area); + + public: + MediaArea() = default; + + MediaArea(Td *td, telegram_api::object_ptr &&media_area_ptr); + + td_api::object_ptr get_story_area_object() const; + + bool is_valid() const { + return type_ != Type::None; + } + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); +}; + +bool operator==(const MediaArea &lhs, const MediaArea &rhs); +bool operator!=(const MediaArea &lhs, const MediaArea &rhs); + +StringBuilder &operator<<(StringBuilder &string_builder, const MediaArea &media_area); + +} // namespace td diff --git a/td/telegram/MediaArea.hpp b/td/telegram/MediaArea.hpp new file mode 100644 index 000000000..a086fa207 --- /dev/null +++ b/td/telegram/MediaArea.hpp @@ -0,0 +1,54 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#pragma once + +#include "td/telegram/MediaArea.h" +#include "td/telegram/MediaAreaCoordinates.hpp" + +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void MediaArea::store(StorerT &storer) const { + using td::store; + BEGIN_STORE_FLAGS(); + END_STORE_FLAGS(); + store(type_, storer); + store(coordinates_, storer); + switch (type_) { + case Type::Location: + store(location_, storer); + break; + case Type::Venue: + store(venue_, storer); + break; + default: + UNREACHABLE(); + } +} + +template +void MediaArea::parse(ParserT &parser) { + using td::parse; + BEGIN_PARSE_FLAGS(); + END_PARSE_FLAGS(); + parse(type_, parser); + parse(coordinates_, parser); + switch (type_) { + case Type::Location: + parse(location_, parser); + break; + case Type::Venue: + parse(venue_, parser); + break; + default: + parser.set_error("Load invalid area type"); + } +} + +} // namespace td