Allow to set suggested custom reactions from stories.

This commit is contained in:
levlam 2023-08-25 19:11:24 +03:00
parent fa1b6f33e1
commit 08639b520a
5 changed files with 19 additions and 5 deletions

View File

@ -3208,7 +3208,7 @@ storyAreaTypeLocation location:location = StoryAreaType;
//@description An area pointing to a venue @venue Information about the venue //@description An area pointing to a venue @venue Information about the venue
storyAreaTypeVenue venue:venue = StoryAreaType; storyAreaTypeVenue venue:venue = StoryAreaType;
//@description An area pointing to a suggested reaction //@description An area pointing to a suggested reaction. App needs to show a clickable reaction on the area and call setStoryReaction when the are is clicked
//@reaction_type Type of the reaction //@reaction_type Type of the reaction
//@is_dark True, if reaction has a dark background //@is_dark True, if reaction has a dark background
//@is_flipped True, if reaction corner is flipped //@is_flipped True, if reaction corner is flipped

View File

@ -124,6 +124,10 @@ MediaArea::MediaArea(Td *td, td_api::object_ptr<td_api::inputStoryArea> &&input_
} }
} }
bool MediaArea::has_reaction_type(const ReactionType &reaction_type) const {
return reaction_type_ == reaction_type;
}
td_api::object_ptr<td_api::storyArea> MediaArea::get_story_area_object() const { td_api::object_ptr<td_api::storyArea> MediaArea::get_story_area_object() const {
CHECK(is_valid()); CHECK(is_valid());
td_api::object_ptr<td_api::StoryAreaType> type; td_api::object_ptr<td_api::StoryAreaType> type;

View File

@ -45,6 +45,8 @@ class MediaArea {
MediaArea(Td *td, td_api::object_ptr<td_api::inputStoryArea> &&input_story_area, MediaArea(Td *td, td_api::object_ptr<td_api::inputStoryArea> &&input_story_area,
const vector<MediaArea> &old_media_areas); const vector<MediaArea> &old_media_areas);
bool has_reaction_type(const ReactionType &reaction_type) const;
td_api::object_ptr<td_api::storyArea> get_story_area_object() const; td_api::object_ptr<td_api::storyArea> get_story_area_object() const;
telegram_api::object_ptr<telegram_api::MediaArea> get_input_media_area() const; telegram_api::object_ptr<telegram_api::MediaArea> get_input_media_area() const;

View File

@ -2346,12 +2346,20 @@ void StoryManager::on_story_replied(StoryFullId story_full_id, UserId replier_us
} }
} }
bool StoryManager::can_use_story_reaction(const ReactionType &reaction_type) const { bool StoryManager::can_use_story_reaction(const Story *story, const ReactionType &reaction_type) const {
if (reaction_type.is_empty()) { if (reaction_type.is_empty()) {
return true; return true;
} }
if (reaction_type.is_custom_reaction()) { if (reaction_type.is_custom_reaction()) {
return td_->option_manager_->get_option_boolean("is_premium"); if (td_->option_manager_->get_option_boolean("is_premium")) {
return true;
}
for (auto &area : story->areas_) {
if (area.has_reaction_type(reaction_type)) {
return true;
}
}
return false;
} }
return td_->reaction_manager_->is_active_reaction(reaction_type); return td_->reaction_manager_->is_active_reaction(reaction_type);
} }
@ -2377,7 +2385,7 @@ void StoryManager::set_story_reaction(StoryFullId story_full_id, ReactionType re
return promise.set_error(Status::Error(400, "Story not found")); return promise.set_error(Status::Error(400, "Story not found"));
} }
if (!can_use_story_reaction(reaction_type)) { if (!can_use_story_reaction(story, reaction_type)) {
return promise.set_error(Status::Error(400, "The reaction isn't available for stories")); return promise.set_error(Status::Error(400, "The reaction isn't available for stories"));
} }

View File

@ -521,7 +521,7 @@ class StoryManager final : public Actor {
void read_stories_on_server(DialogId owner_dialog_id, StoryId story_id, uint64 log_event_id); void read_stories_on_server(DialogId owner_dialog_id, StoryId story_id, uint64 log_event_id);
bool can_use_story_reaction(const ReactionType &reaction_type) const; bool can_use_story_reaction(const Story *story, const ReactionType &reaction_type) const;
void schedule_interaction_info_update(); void schedule_interaction_info_update();