From fa1b6f33e17abb0256657e4e3a1612a0f5d0859c Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 25 Aug 2023 16:37:27 +0300 Subject: [PATCH] Support storyAreaTypeSuggestedReaction. --- td/generate/scheme/td_api.tl | 12 ++++++++++ td/telegram/MediaArea.cpp | 45 ++++++++++++++++++++++++++++++++---- td/telegram/MediaArea.h | 6 ++++- td/telegram/MediaArea.hpp | 10 ++++++++ td/telegram/cli.cpp | 3 +++ 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d017831c5..edada4c2e 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3208,6 +3208,12 @@ storyAreaTypeLocation location:location = StoryAreaType; //@description An area pointing to a venue @venue Information about the venue storyAreaTypeVenue venue:venue = StoryAreaType; +//@description An area pointing to a suggested reaction +//@reaction_type Type of the reaction +//@is_dark True, if reaction has a dark background +//@is_flipped True, if reaction corner is flipped +storyAreaTypeSuggestedReaction reaction_type:ReactionType is_dark:Bool is_flipped:Bool = 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; @@ -3228,6 +3234,12 @@ inputStoryAreaTypeFoundVenue query_id:int64 result_id:string = InputStoryAreaTyp //@venue_id Identifier of the venue in the provider database inputStoryAreaTypePreviousVenue venue_provider:string venue_id:string = InputStoryAreaType; +//@description An area pointing to a suggested reaction +//@reaction_type Type of the reaction +//@is_dark True, if reaction has a dark background +//@is_flipped True, if reaction corner is flipped +inputStoryAreaTypeSuggestedReaction reaction_type:ReactionType is_dark:Bool is_flipped:Bool = InputStoryAreaType; + //@description Describes a clickable rectangle area on a story media to be added @position Position of the area @type Type of the area inputStoryArea position:storyAreaPosition type:InputStoryAreaType = InputStoryArea; diff --git a/td/telegram/MediaArea.cpp b/td/telegram/MediaArea.cpp index f2021d7eb..23522f231 100644 --- a/td/telegram/MediaArea.cpp +++ b/td/telegram/MediaArea.cpp @@ -39,9 +39,19 @@ MediaArea::MediaArea(Td *td, telegram_api::object_ptr & } break; } - case telegram_api::mediaAreaSuggestedReaction::ID: - // TODO + case telegram_api::mediaAreaSuggestedReaction::ID: { + auto area = telegram_api::move_object_as(media_area_ptr); + coordinates_ = MediaAreaCoordinates(area->coordinates_); + reaction_type_ = ReactionType(area->reaction_); + is_dark_ = area->dark_; + is_flipped_ = area->flipped_; + if (coordinates_.is_valid() && !reaction_type_.is_empty()) { + type_ = Type::Reaction; + } else { + LOG(ERROR) << "Receive " << to_string(area); + } break; + } case telegram_api::inputMediaAreaVenue::ID: LOG(ERROR) << "Receive " << to_string(media_area_ptr); break; @@ -99,6 +109,16 @@ MediaArea::MediaArea(Td *td, td_api::object_ptr &&input_ } break; } + case td_api::inputStoryAreaTypeSuggestedReaction::ID: { + auto type = td_api::move_object_as(input_story_area->type_); + reaction_type_ = ReactionType(type->reaction_type_); + is_dark_ = type->is_dark_; + is_flipped_ = type->is_flipped_; + if (!reaction_type_.is_empty()) { + type_ = Type::Reaction; + } + break; + } default: UNREACHABLE(); } @@ -114,6 +134,10 @@ td_api::object_ptr MediaArea::get_story_area_object() const { case Type::Venue: type = td_api::make_object(venue_.get_venue_object()); break; + case Type::Reaction: + type = td_api::make_object(reaction_type_.get_reaction_type_object(), + is_dark_, is_flipped_); + break; default: UNREACHABLE(); } @@ -132,6 +156,18 @@ telegram_api::object_ptr MediaArea::get_input_media_are coordinates_.get_input_media_area_coordinates(), input_query_id_, input_result_id_); } return venue_.get_input_media_area_venue(coordinates_.get_input_media_area_coordinates()); + case Type::Reaction: { + int32 flags = 0; + if (is_dark_) { + flags |= telegram_api::mediaAreaSuggestedReaction::DARK_MASK; + } + if (is_flipped_) { + flags |= telegram_api::mediaAreaSuggestedReaction::FLIPPED_MASK; + } + return telegram_api::make_object( + flags, false /*ignored*/, false /*ignored*/, coordinates_.get_input_media_area_coordinates(), + reaction_type_.get_input_reaction()); + } default: UNREACHABLE(); return nullptr; @@ -141,7 +177,8 @@ telegram_api::object_ptr MediaArea::get_input_media_are 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_ && lhs.input_query_id_ == rhs.input_query_id_ && - lhs.input_result_id_ == rhs.input_result_id_; + lhs.input_result_id_ == rhs.input_result_id_ && lhs.reaction_type_ == rhs.reaction_type_ && + lhs.is_dark_ == rhs.is_dark_ && lhs.is_flipped_ == rhs.is_flipped_; } bool operator!=(const MediaArea &lhs, const MediaArea &rhs) { @@ -150,7 +187,7 @@ bool operator!=(const MediaArea &lhs, const MediaArea &rhs) { StringBuilder &operator<<(StringBuilder &string_builder, const MediaArea &media_area) { return string_builder << "StoryArea[" << media_area.coordinates_ << ": " << media_area.location_ << '/' - << media_area.venue_ << ']'; + << media_area.venue_ << '/' << media_area.reaction_type_ << ']'; } } // namespace td diff --git a/td/telegram/MediaArea.h b/td/telegram/MediaArea.h index 6e8212343..a017a847b 100644 --- a/td/telegram/MediaArea.h +++ b/td/telegram/MediaArea.h @@ -8,6 +8,7 @@ #include "td/telegram/Location.h" #include "td/telegram/MediaAreaCoordinates.h" +#include "td/telegram/ReactionType.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/telegram/Venue.h" @@ -20,13 +21,16 @@ namespace td { class Td; class MediaArea { - enum class Type : int32 { None, Location, Venue }; + enum class Type : int32 { None, Location, Venue, Reaction }; Type type_ = Type::None; MediaAreaCoordinates coordinates_; Location location_; Venue venue_; int64 input_query_id_ = 0; string input_result_id_; + ReactionType reaction_type_; + bool is_dark_ = false; + bool is_flipped_ = false; friend bool operator==(const MediaArea &lhs, const MediaArea &rhs); friend bool operator!=(const MediaArea &lhs, const MediaArea &rhs); diff --git a/td/telegram/MediaArea.hpp b/td/telegram/MediaArea.hpp index 364136504..6096cb4ab 100644 --- a/td/telegram/MediaArea.hpp +++ b/td/telegram/MediaArea.hpp @@ -19,6 +19,8 @@ void MediaArea::store(StorerT &storer) const { bool has_input_query_id = input_query_id_ != 0; BEGIN_STORE_FLAGS(); STORE_FLAG(has_input_query_id); + STORE_FLAG(is_dark_); + STORE_FLAG(is_flipped_); END_STORE_FLAGS(); store(type_, storer); store(coordinates_, storer); @@ -33,6 +35,9 @@ void MediaArea::store(StorerT &storer) const { store(input_result_id_, storer); } break; + case Type::Reaction: + store(reaction_type_, storer); + break; default: UNREACHABLE(); } @@ -44,6 +49,8 @@ void MediaArea::parse(ParserT &parser) { bool has_input_query_id; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_input_query_id); + PARSE_FLAG(is_dark_); + PARSE_FLAG(is_flipped_); END_PARSE_FLAGS(); parse(type_, parser); parse(coordinates_, parser); @@ -58,6 +65,9 @@ void MediaArea::parse(ParserT &parser) { parse(input_result_id_, parser); } break; + case Type::Reaction: + parse(reaction_type_, parser); + break; default: parser.set_error("Load invalid area type"); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7aa2bf282..33245e0a5 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1232,6 +1232,9 @@ class CliClient final : public Actor { string venue_id; std::tie(venue_provider, venue_id) = split(area.substr(1), ':'); type = td_api::make_object(venue_provider, venue_id); + } else if (area[0] == 'r') { + type = td_api::make_object(as_reaction_type(area.substr(1)), + rand_bool(), rand_bool()); } result->areas_.push_back(td_api::make_object(std::move(position), std::move(type))); }