From 62d1a85ab646d5532d9c31cb297ff59d32bab1bd Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 26 Jul 2024 16:39:30 +0300 Subject: [PATCH] Add more checks for paid reactions. --- td/generate/scheme/td_api.tl | 4 ++-- td/telegram/ConfigManager.cpp | 2 +- td/telegram/MediaArea.cpp | 4 ++-- td/telegram/MessageReaction.cpp | 2 +- td/telegram/MessagesManager.cpp | 2 +- td/telegram/ReactionManager.cpp | 3 +++ td/telegram/StoryInteractionInfo.cpp | 6 ++++-- td/telegram/StoryManager.cpp | 11 ++++++++++- 8 files changed, 24 insertions(+), 10 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 141d7fee4..58b61f7e4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -9026,7 +9026,7 @@ clearRecentReactions = Ok; //@update_recent_reactions Pass true if the reaction needs to be added to recent reactions; tags are never added to the list of recent reactions addMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType is_big:Bool update_recent_reactions:Bool = Ok; -//@description Removes a reaction from a message. A chosen reaction can always be removed +//@description Removes a reaction from a message. The paid reaction can't be removed. A chosen reaction can always be removed //@chat_id Identifier of the chat to which the message belongs //@message_id Identifier of the message //@reaction_type Type of the reaction to remove @@ -9047,7 +9047,7 @@ setMessageReactions chat_id:int53 message_id:int53 reaction_types:vector config) { if (is_from_main_dc && !options.have_option("default_reaction_need_sync")) { ReactionType reaction_type(config->reactions_default_); - if (!reaction_type.is_empty()) { + if (!reaction_type.is_empty() && !reaction_type.is_paid_reaction()) { options.set_option_string("default_reaction", reaction_type.get_string()); } } diff --git a/td/telegram/MediaArea.cpp b/td/telegram/MediaArea.cpp index e4db70240..c20fab148 100644 --- a/td/telegram/MediaArea.cpp +++ b/td/telegram/MediaArea.cpp @@ -63,7 +63,7 @@ MediaArea::MediaArea(Td *td, telegram_api::object_ptr & reaction_type_ = ReactionType(area->reaction_); is_dark_ = area->dark_; is_flipped_ = area->flipped_; - if (coordinates_.is_valid() && !reaction_type_.is_empty()) { + if (coordinates_.is_valid() && !reaction_type_.is_empty() && !reaction_type_.is_paid_reaction()) { type_ = Type::Reaction; } else { LOG(ERROR) << "Receive " << to_string(area); @@ -182,7 +182,7 @@ MediaArea::MediaArea(Td *td, td_api::object_ptr &&input_ reaction_type_ = ReactionType(type->reaction_type_); is_dark_ = type->is_dark_; is_flipped_ = type->is_flipped_; - if (!reaction_type_.is_empty()) { + if (!reaction_type_.is_empty() && !reaction_type_.is_paid_reaction()) { type_ = Type::Reaction; } break; diff --git a/td/telegram/MessageReaction.cpp b/td/telegram/MessageReaction.cpp index 144ca7fd7..497cf446b 100644 --- a/td/telegram/MessageReaction.cpp +++ b/td/telegram/MessageReaction.cpp @@ -903,7 +903,7 @@ void set_message_reactions(Td *td, MessageFullId message_full_id, vector added_reaction_types; for (auto &reaction : story_views->reactions_) { ReactionType reaction_type(reaction->reaction_); - if (reaction_type.is_empty()) { - LOG(ERROR) << "Receive empty " << to_string(reaction); + if (reaction_type.is_empty() || reaction_type.is_paid_reaction()) { + LOG(ERROR) << "Receive " << to_string(reaction); continue; } if (!added_reaction_types.insert(reaction_type).second) { @@ -81,6 +81,7 @@ void StoryInteractionInfo::add_dependencies(Dependencies &dependencies) const { void StoryInteractionInfo::set_chosen_reaction_type(const ReactionType &new_reaction_type, const ReactionType &old_reaction_type) { if (!old_reaction_type.is_empty()) { + CHECK(!old_reaction_type.is_paid_reaction()); for (auto it = reaction_counts_.begin(); it != reaction_counts_.end(); ++it) { if (it->first == old_reaction_type) { it->second--; @@ -92,6 +93,7 @@ void StoryInteractionInfo::set_chosen_reaction_type(const ReactionType &new_reac } } if (!new_reaction_type.is_empty()) { + CHECK(!new_reaction_type.is_paid_reaction()); bool is_found = false; for (auto it = reaction_counts_.begin(); it != reaction_counts_.end(); ++it) { if (it->first == old_reaction_type) { diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index e847c480f..d1bafb0fe 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -310,6 +310,7 @@ class SendStoryReactionQuery final : public Td::ResultHandler { if (input_peer == nullptr) { return on_error(Status::Error(400, "Can't access the chat")); } + CHECK(!reaction_type.is_paid_reaction()); int32 flags = 0; if (!reaction_type.is_empty() && add_to_recent) { @@ -411,6 +412,7 @@ class GetStoryReactionsListQuery final : public Td::ResultHandler { if (input_peer == nullptr) { return on_error(Status::Error(400, "Can't access the chat")); } + CHECK(!reaction_type.is_paid_reaction()); int32 flags = 0; if (!reaction_type.is_empty()) { @@ -2890,7 +2892,7 @@ void StoryManager::on_story_replied(StoryFullId story_full_id, UserId replier_us } bool StoryManager::has_suggested_reaction(const Story *story, const ReactionType &reaction_type) { - if (reaction_type.is_empty()) { + if (reaction_type.is_empty() || reaction_type.is_paid_reaction()) { return false; } CHECK(story != nullptr); @@ -3278,6 +3280,9 @@ void StoryManager::get_dialog_story_interactions(StoryFullId story_full_id, Reac if (!story_full_id.get_story_id().is_server()) { return promise.set_value(td_api::make_object()); } + if (reaction_type.is_paid_reaction()) { + return promise.set_error(Status::Error(400, "Stories can't have paid reactions")); + } auto query_promise = PromiseCreator::lambda( [actor_id = actor_id(this), story_full_id, promise = std::move(promise)]( @@ -4578,6 +4583,10 @@ void StoryManager::on_update_story_chosen_reaction_type(DialogId owner_dialog_id if (!td_->dialog_manager_->have_dialog_info_force(owner_dialog_id, "on_update_story_chosen_reaction_type")) { return; } + if (chosen_reaction_type.is_paid_reaction()) { + LOG(ERROR) << "Receive paid reaction for " << story_id << " in " << owner_dialog_id; + return; + } StoryFullId story_full_id{owner_dialog_id, story_id}; auto pending_reaction_it = being_set_story_reactions_.find(story_full_id); if (pending_reaction_it != being_set_story_reactions_.end()) {