Add MediaArea::get_input_media_areas.

This commit is contained in:
levlam 2023-12-18 14:24:07 +03:00
parent 50f20c8a0c
commit 15b8ad5c66
3 changed files with 25 additions and 17 deletions

View File

@ -186,6 +186,18 @@ telegram_api::object_ptr<telegram_api::MediaArea> MediaArea::get_input_media_are
}
}
vector<telegram_api::object_ptr<telegram_api::MediaArea>> MediaArea::get_input_media_areas(
const vector<MediaArea> &media_areas) {
vector<telegram_api::object_ptr<telegram_api::MediaArea>> input_media_areas;
for (const auto &media_area : media_areas) {
auto input_media_area = media_area.get_input_media_area();
if (input_media_area != nullptr) {
input_media_areas.push_back(std::move(input_media_area));
}
}
return input_media_areas;
}
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_ &&

View File

@ -39,6 +39,8 @@ class MediaArea {
friend StringBuilder &operator<<(StringBuilder &string_builder, const MediaArea &media_area);
telegram_api::object_ptr<telegram_api::MediaArea> get_input_media_area() const;
public:
MediaArea() = default;
@ -52,7 +54,8 @@ class MediaArea {
td_api::object_ptr<td_api::storyArea> get_story_area_object(
const vector<std::pair<ReactionType, int32>> &reaction_counts) const;
telegram_api::object_ptr<telegram_api::MediaArea> get_input_media_area() const;
static vector<telegram_api::object_ptr<telegram_api::MediaArea>> get_input_media_areas(
const vector<MediaArea> &media_areas);
bool is_valid() const {
return type_ != Type::None;

View File

@ -887,17 +887,14 @@ class StoryManager::SendStoryQuery final : public Td::ResultHandler {
if (story->noforwards_) {
flags |= telegram_api::stories_sendStory::NOFORWARDS_MASK;
}
vector<telegram_api::object_ptr<telegram_api::MediaArea>> media_areas;
for (const auto &media_area : story->areas_) {
media_areas.push_back(media_area.get_input_media_area());
}
if (!media_areas.empty()) {
auto input_media_areas = MediaArea::get_input_media_areas(story->areas_);
if (!input_media_areas.empty()) {
flags |= telegram_api::stories_sendStory::MEDIA_AREAS_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::stories_sendStory(flags, false /*ignored*/, false /*ignored*/, false /*ignored*/,
std::move(input_peer), std::move(input_media), std::move(media_areas),
std::move(input_peer), std::move(input_media), std::move(input_media_areas),
caption.text, std::move(entities), std::move(privacy_rules),
pending_story_->random_id_, period, std::move(fwd_input_peer), fwd_story_id),
{{pending_story_->dialog_id_}}));
@ -965,17 +962,13 @@ class StoryManager::EditStoryQuery final : public Td::ResultHandler {
CHECK(input_media != nullptr);
flags |= telegram_api::stories_editStory::MEDIA_MASK;
}
vector<telegram_api::object_ptr<telegram_api::MediaArea>> media_areas;
vector<telegram_api::object_ptr<telegram_api::MediaArea>> input_media_areas;
if (edited_story->edit_media_areas_) {
for (const auto &media_area : edited_story->areas_) {
media_areas.push_back(media_area.get_input_media_area());
}
input_media_areas = MediaArea::get_input_media_areas(edited_story->areas_);
} else if (content != nullptr) {
for (const auto &media_area : story->areas_) {
media_areas.push_back(media_area.get_input_media_area());
}
input_media_areas = MediaArea::get_input_media_areas(story->areas_);
}
if (!media_areas.empty()) {
if (!input_media_areas.empty()) {
flags |= telegram_api::stories_editStory::MEDIA_AREAS_MASK;
}
vector<telegram_api::object_ptr<telegram_api::MessageEntity>> entities;
@ -989,8 +982,8 @@ class StoryManager::EditStoryQuery final : public Td::ResultHandler {
send_query(G()->net_query_creator().create(
telegram_api::stories_editStory(flags, std::move(input_peer), pending_story_->story_id_.get(),
std::move(input_media), std::move(media_areas), edited_story->caption_.text,
std::move(entities), Auto()),
std::move(input_media), std::move(input_media_areas),
edited_story->caption_.text, std::move(entities), Auto()),
{{StoryFullId{pending_story_->dialog_id_, pending_story_->story_id_}}}));
}