Support storyAreaTypeSuggestedReaction.

This commit is contained in:
levlam 2023-08-25 16:37:27 +03:00
parent 153ff5503b
commit fa1b6f33e1
5 changed files with 71 additions and 5 deletions

View File

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

View File

@ -39,9 +39,19 @@ MediaArea::MediaArea(Td *td, telegram_api::object_ptr<telegram_api::MediaArea> &
}
break;
}
case telegram_api::mediaAreaSuggestedReaction::ID:
// TODO
case telegram_api::mediaAreaSuggestedReaction::ID: {
auto area = telegram_api::move_object_as<telegram_api::mediaAreaSuggestedReaction>(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<td_api::inputStoryArea> &&input_
}
break;
}
case td_api::inputStoryAreaTypeSuggestedReaction::ID: {
auto type = td_api::move_object_as<td_api::inputStoryAreaTypeSuggestedReaction>(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<td_api::storyArea> MediaArea::get_story_area_object() const {
case Type::Venue:
type = td_api::make_object<td_api::storyAreaTypeVenue>(venue_.get_venue_object());
break;
case Type::Reaction:
type = td_api::make_object<td_api::storyAreaTypeSuggestedReaction>(reaction_type_.get_reaction_type_object(),
is_dark_, is_flipped_);
break;
default:
UNREACHABLE();
}
@ -132,6 +156,18 @@ telegram_api::object_ptr<telegram_api::MediaArea> 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<telegram_api::mediaAreaSuggestedReaction>(
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<telegram_api::MediaArea> 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

View File

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

View File

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

View File

@ -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<td_api::inputStoryAreaTypePreviousVenue>(venue_provider, venue_id);
} else if (area[0] == 'r') {
type = td_api::make_object<td_api::inputStoryAreaTypeSuggestedReaction>(as_reaction_type(area.substr(1)),
rand_bool(), rand_bool());
}
result->areas_.push_back(td_api::make_object<td_api::inputStoryArea>(std::move(position), std::move(type)));
}