Support weather story areas.
This commit is contained in:
parent
d26e0fab57
commit
6d5d9a19aa
@ -4107,7 +4107,7 @@ emojiCategoryTypeChatPhoto = EmojiCategoryType;
|
||||
storyAreaPosition x_percentage:double y_percentage:double width_percentage:double height_percentage:double rotation_angle:double corner_radius_percentage:double = StoryAreaPosition;
|
||||
|
||||
|
||||
//@class StoryAreaType @description Describes type of clickable rectangle area on a story media
|
||||
//@class StoryAreaType @description Describes type of clickable area on a story media
|
||||
|
||||
//@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;
|
||||
@ -4128,12 +4128,18 @@ storyAreaTypeMessage chat_id:int53 message_id:int53 = StoryAreaType;
|
||||
//@description An area pointing to a HTTP or tg:// link @url HTTP or tg:// URL to be opened when the area is clicked
|
||||
storyAreaTypeLink url:string = StoryAreaType;
|
||||
|
||||
//@description An area with information about weather
|
||||
//@temperature Temperature, in degree Celsius
|
||||
//@emoji Emoji representing the weather
|
||||
//@background_color A color of the area background in the ARGB format
|
||||
storyAreaTypeWeather temperature:double emoji:string background_color:int32 = 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;
|
||||
|
||||
|
||||
//@class InputStoryAreaType @description Describes type of clickable rectangle area on a story media to be added
|
||||
//@class InputStoryAreaType @description Describes type of clickable area on a story media to be added
|
||||
|
||||
//@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;
|
||||
@ -4163,6 +4169,12 @@ inputStoryAreaTypeMessage chat_id:int53 message_id:int53 = InputStoryAreaType;
|
||||
//@url HTTP or tg:// URL to be opened when the area is clicked
|
||||
inputStoryAreaTypeLink url:string = InputStoryAreaType;
|
||||
|
||||
//@description An area with information about weather
|
||||
//@temperature Temperature, in degree Celsius
|
||||
//@emoji Emoji representing the weather
|
||||
//@background_color A color of the area background in the ARGB format
|
||||
inputStoryAreaTypeWeather temperature:double emoji:string background_color:int32 = 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;
|
||||
|
@ -18,8 +18,11 @@
|
||||
#include "td/telegram/ServerMessageId.h"
|
||||
#include "td/telegram/Td.h"
|
||||
|
||||
#include "td/utils/emoji.h"
|
||||
#include "td/utils/logging.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace td {
|
||||
|
||||
MediaArea::MediaArea(Td *td, telegram_api::object_ptr<telegram_api::MediaArea> &&media_area_ptr) {
|
||||
@ -92,7 +95,16 @@ MediaArea::MediaArea(Td *td, telegram_api::object_ptr<telegram_api::MediaArea> &
|
||||
break;
|
||||
}
|
||||
case telegram_api::mediaAreaWeather::ID: {
|
||||
// auto area = telegram_api::move_object_as<telegram_api::mediaAreaWeather>(media_area_ptr);
|
||||
auto area = telegram_api::move_object_as<telegram_api::mediaAreaWeather>(media_area_ptr);
|
||||
coordinates_ = MediaAreaCoordinates(area->coordinates_);
|
||||
if (coordinates_.is_valid() && is_emoji(area->emoji_) && std::isfinite(area->temperature_c_)) {
|
||||
type_ = Type::Weather;
|
||||
url_ = std::move(area->emoji_);
|
||||
temperature_ = area->temperature_c_;
|
||||
color_ = area->color_;
|
||||
} else {
|
||||
LOG(ERROR) << "Receive " << to_string(area);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case telegram_api::inputMediaAreaVenue::ID:
|
||||
@ -206,6 +218,17 @@ MediaArea::MediaArea(Td *td, td_api::object_ptr<td_api::inputStoryArea> &&input_
|
||||
type_ = Type::Url;
|
||||
break;
|
||||
}
|
||||
case td_api::inputStoryAreaTypeWeather::ID: {
|
||||
auto type = td_api::move_object_as<td_api::inputStoryAreaTypeWeather>(input_story_area->type_);
|
||||
if (!clean_input_string(type->emoji_) || !is_emoji(type->emoji_) || !std::isfinite(type->temperature_)) {
|
||||
break;
|
||||
}
|
||||
url_ = std::move(type->emoji_);
|
||||
temperature_ = type->temperature_;
|
||||
color_ = type->background_color_;
|
||||
type_ = Type::Weather;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
@ -249,6 +272,9 @@ td_api::object_ptr<td_api::storyArea> MediaArea::get_story_area_object(
|
||||
case Type::Url:
|
||||
type = td_api::make_object<td_api::storyAreaTypeLink>(url_);
|
||||
break;
|
||||
case Type::Weather:
|
||||
type = td_api::make_object<td_api::storyAreaTypeWeather>(temperature_, url_, color_);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
@ -315,6 +341,9 @@ telegram_api::object_ptr<telegram_api::MediaArea> MediaArea::get_input_media_are
|
||||
case Type::Url:
|
||||
return telegram_api::make_object<telegram_api::mediaAreaUrl>(coordinates_.get_input_media_area_coordinates(),
|
||||
url_);
|
||||
case Type::Weather:
|
||||
return telegram_api::make_object<telegram_api::mediaAreaWeather>(coordinates_.get_input_media_area_coordinates(),
|
||||
url_, temperature_, color_);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
@ -341,8 +370,9 @@ 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.message_full_id_ == rhs.message_full_id_ &&
|
||||
lhs.input_query_id_ == rhs.input_query_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_ && lhs.is_old_message_ == rhs.is_old_message_;
|
||||
lhs.reaction_type_ == rhs.reaction_type_ && std::fabs(lhs.temperature_ - rhs.temperature_) < 1e-6 &&
|
||||
lhs.color_ == rhs.color_ && lhs.is_dark_ == rhs.is_dark_ && lhs.is_flipped_ == rhs.is_flipped_ &&
|
||||
lhs.is_old_message_ == rhs.is_old_message_;
|
||||
}
|
||||
|
||||
bool operator!=(const MediaArea &lhs, const MediaArea &rhs) {
|
||||
@ -352,7 +382,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.reaction_type_ << '/' << media_area.message_full_id_
|
||||
<< ']';
|
||||
<< '/' << media_area.temperature_ << ']';
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -42,7 +42,7 @@ class MediaArea {
|
||||
void parse(ParserT &parser);
|
||||
};
|
||||
|
||||
enum class Type : int32 { None, Location, Venue, Reaction, Message, Url };
|
||||
enum class Type : int32 { None, Location, Venue, Reaction, Message, Url, Weather };
|
||||
Type type_ = Type::None;
|
||||
MediaAreaCoordinates coordinates_;
|
||||
Location location_;
|
||||
@ -53,6 +53,8 @@ class MediaArea {
|
||||
string input_result_id_;
|
||||
ReactionType reaction_type_;
|
||||
string url_;
|
||||
double temperature_ = 0.0;
|
||||
int32 color_ = 0;
|
||||
bool is_dark_ = false;
|
||||
bool is_flipped_ = false;
|
||||
bool is_old_message_ = false;
|
||||
|
@ -99,6 +99,11 @@ void MediaArea::store(StorerT &storer) const {
|
||||
case Type::Url:
|
||||
store(url_, storer);
|
||||
break;
|
||||
case Type::Weather:
|
||||
store(temperature_, storer);
|
||||
store(url_, storer);
|
||||
store(color_, storer);
|
||||
break;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
@ -141,6 +146,11 @@ void MediaArea::parse(ParserT &parser) {
|
||||
case Type::Url:
|
||||
parse(url_, parser);
|
||||
break;
|
||||
case Type::Weather:
|
||||
parse(temperature_, parser);
|
||||
parse(url_, parser);
|
||||
parse(color_, parser);
|
||||
break;
|
||||
default:
|
||||
parser.set_error("Load invalid area type");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user