From 4e6046b9ec848caa3c0a22445a8e231583556208 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 24 Aug 2022 23:31:15 +0300 Subject: [PATCH] Treat all emoji reactions as non-premium. --- td/generate/scheme/td_api.tl | 10 +++------- td/telegram/AvailableReaction.cpp | 12 ++++-------- td/telegram/AvailableReaction.h | 5 +---- td/telegram/MessageReaction.cpp | 4 ++-- td/telegram/MessageReaction.h | 4 ++++ td/telegram/MessagesManager.cpp | 4 ++-- td/telegram/StickersManager.cpp | 15 +++++++++------ td/telegram/StickersManager.hpp | 2 ++ td/telegram/Td.cpp | 2 +- 9 files changed, 28 insertions(+), 30 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7944bacb9..23959e9a5 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2563,18 +2563,14 @@ addedReaction type:ReactionType sender_id:MessageSender = AddedReaction; //@description Represents a list of reactions added to a message @total_count The total number of found reactions @reactions The list of added reactions @next_offset The offset for the next request. If empty, there are no more results addedReactions total_count:int32 reactions:vector next_offset:string = AddedReactions; -//@description Represents an available reaction @reaction Text representation of the reaction @needs_premium True, if Telegram Premium is needed to send the reaction -availableReaction reaction:string needs_premium:Bool = AvailableReaction; - -//@description Represents a list of available reactions @reactions List of reactions -availableReactions reactions:vector = AvailableReactions; +//@description Represents a list of available reactions @reactions List of available reactions +availableReactions reactions:vector = AvailableReactions; //@description Contains stickers which must be used for emoji reaction animation rendering //@reaction Text representation of the reaction //@title Reaction title //@is_active True, if the reaction can be added to new messages and enabled in chats -//@is_premium True, if the reaction is available only for Premium users //@static_icon Static icon for the reaction //@appear_animation Appear animation for the reaction //@select_animation Select animation for the reaction @@ -2582,7 +2578,7 @@ availableReactions reactions:vector = AvailableReactions; //@effect_animation Effect animation for the reaction //@around_animation Around animation for the reaction; may be null //@center_animation Center animation for the reaction; may be null -reaction reaction:string title:string is_active:Bool is_premium:Bool static_icon:sticker appear_animation:sticker select_animation:sticker activate_animation:sticker effect_animation:sticker around_animation:sticker center_animation:sticker = Reaction; +reaction reaction:string title:string is_active:Bool static_icon:sticker appear_animation:sticker select_animation:sticker activate_animation:sticker effect_animation:sticker around_animation:sticker center_animation:sticker = Reaction; //@description Represents a list of animations @animations List of animations diff --git a/td/telegram/AvailableReaction.cpp b/td/telegram/AvailableReaction.cpp index dfd794437..045a15903 100644 --- a/td/telegram/AvailableReaction.cpp +++ b/td/telegram/AvailableReaction.cpp @@ -11,11 +11,11 @@ namespace td { AvailableReactionType get_reaction_type(const vector &available_reactions, const string &reaction) { + if (reaction[0] == '#') { + return AvailableReactionType::NeedsPremium; + } for (auto &available_reaction : available_reactions) { if (available_reaction.reaction_ == reaction) { - if (available_reaction.is_premium_) { - return AvailableReactionType::NeedsPremium; - } return AvailableReactionType::Available; } } @@ -50,12 +50,8 @@ vector get_active_reactions(const vector &available_reactions, return result; } -td_api::object_ptr AvailableReaction::get_available_reaction_object() const { - return td_api::make_object(reaction_, is_premium_); -} - bool operator==(const AvailableReaction &lhs, const AvailableReaction &rhs) { - return lhs.reaction_ == rhs.reaction_ && lhs.is_premium_ == rhs.is_premium_; + return lhs.reaction_ == rhs.reaction_; } } // namespace td diff --git a/td/telegram/AvailableReaction.h b/td/telegram/AvailableReaction.h index e3196382d..a5a56e3b7 100644 --- a/td/telegram/AvailableReaction.h +++ b/td/telegram/AvailableReaction.h @@ -14,12 +14,9 @@ namespace td { struct AvailableReaction { string reaction_; - bool is_premium_; - AvailableReaction(const string &reaction, bool is_premium) : reaction_(reaction), is_premium_(is_premium) { + explicit AvailableReaction(const string &reaction) : reaction_(reaction) { } - - td_api::object_ptr get_available_reaction_object() const; }; bool operator==(const AvailableReaction &lhs, const AvailableReaction &rhs); diff --git a/td/telegram/MessageReaction.cpp b/td/telegram/MessageReaction.cpp index 01ad9b0c9..a51488a54 100644 --- a/td/telegram/MessageReaction.cpp +++ b/td/telegram/MessageReaction.cpp @@ -47,7 +47,7 @@ static string get_custom_emoji_string(int64 custom_emoji_id) { return PSTRING() << '#' << base64_encode(Slice(s, 8)); } -static telegram_api::object_ptr get_input_reaction(const string &reaction) { +telegram_api::object_ptr get_input_reaction(const string &reaction) { if (reaction.empty()) { return telegram_api::make_object(); } @@ -80,7 +80,7 @@ string get_message_reaction_string(const telegram_api::object_ptr get_reaction_type_object(const string &reaction) { +td_api::object_ptr get_reaction_type_object(const string &reaction) { CHECK(!reaction.empty()); if (reaction[0] == '#') { return td_api::make_object(get_custom_emoji_id(reaction)); diff --git a/td/telegram/MessageReaction.h b/td/telegram/MessageReaction.h index ba92d32a1..75ab1726e 100644 --- a/td/telegram/MessageReaction.h +++ b/td/telegram/MessageReaction.h @@ -173,6 +173,10 @@ StringBuilder &operator<<(StringBuilder &string_builder, const MessageReactions StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr &reactions); +telegram_api::object_ptr get_input_reaction(const string &reaction); + +td_api::object_ptr get_reaction_type_object(const string &reaction); + string get_message_reaction_string(const telegram_api::object_ptr &reaction); string get_message_reaction_string(const td_api::object_ptr &type); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 087671272..e6ba03bba 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -24399,7 +24399,7 @@ vector MessagesManager::get_message_available_reactions(const // can add the reaction if it has already been used for the message or is available in the chat bool is_set = (m->reactions != nullptr && m->reactions->get_reaction(active_reaction.reaction_) != nullptr); if (is_set || (can_add_new_reactions && td::contains(active_reactions, active_reaction.reaction_))) { - result.emplace_back(active_reaction.reaction_, !is_premium && active_reaction.is_premium_ && !is_set); + result.emplace_back(active_reaction.reaction_); } } } @@ -24409,7 +24409,7 @@ vector MessagesManager::get_message_available_reactions(const get_reaction_type(result, reaction.get_reaction()) == AvailableReactionType::Unavailable) { CHECK(!can_use_reactions || get_reaction_type(active_reactions_, reaction.get_reaction()) == AvailableReactionType::Unavailable); - result.emplace_back(reaction.get_reaction(), false); + result.emplace_back(reaction.get_reaction()); } } } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 2d6b0d23a..0d3e245f9 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -3640,11 +3640,10 @@ void StickersManager::on_get_special_sticker_set(const SpecialStickerSetType &ty td_api::object_ptr StickersManager::get_update_reactions_object() const { auto reactions = transform(reactions_.reactions_, [this](const Reaction &reaction) { return td_api::make_object( - reaction.reaction_, reaction.title_, reaction.is_active_, reaction.is_premium_, - get_sticker_object(reaction.static_icon_), get_sticker_object(reaction.appear_animation_), - get_sticker_object(reaction.select_animation_), get_sticker_object(reaction.activate_animation_), - get_sticker_object(reaction.effect_animation_), get_sticker_object(reaction.around_animation_), - get_sticker_object(reaction.center_animation_)); + reaction.reaction_, reaction.title_, reaction.is_active_, get_sticker_object(reaction.static_icon_), + get_sticker_object(reaction.appear_animation_), get_sticker_object(reaction.select_animation_), + get_sticker_object(reaction.activate_animation_), get_sticker_object(reaction.effect_animation_), + get_sticker_object(reaction.around_animation_), get_sticker_object(reaction.center_animation_)); }); return td_api::make_object(std::move(reactions)); } @@ -3685,7 +3684,7 @@ void StickersManager::update_active_reactions() { vector active_reactions; for (auto &reaction : reactions_.reactions_) { if (reaction.is_active_) { - active_reactions.emplace_back(reaction.reaction_, reaction.is_premium_); + active_reactions.emplace_back(reaction.reaction_); } } td_->messages_manager_->set_active_reactions(std::move(active_reactions)); @@ -3735,6 +3734,10 @@ void StickersManager::on_get_available_reactions( LOG(ERROR) << "Receive invalid reaction " << reaction.reaction_; continue; } + if (reaction.is_premium_) { + LOG(ERROR) << "Receive premium reaction " << reaction.reaction_; + continue; + } new_reactions.push_back(std::move(reaction)); } diff --git a/td/telegram/StickersManager.hpp b/td/telegram/StickersManager.hpp index 683f8d6c3..14b78eb61 100644 --- a/td/telegram/StickersManager.hpp +++ b/td/telegram/StickersManager.hpp @@ -499,6 +499,8 @@ void StickersManager::Reaction::parse(ParserT &parser) { if (has_center_animation) { center_animation_ = stickers_manager->parse_sticker(false, parser); } + + is_premium_ = false; } template diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index a923fb951..7a201b950 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5242,7 +5242,7 @@ void Td::on_request(uint64 id, const td_api::getMessageAvailableReactions &reque send_closure(actor_id(this), &Td::send_error, id, r_reactions.move_as_error()); } else { auto reactions = - transform(r_reactions.ok(), [](auto &reaction) { return reaction.get_available_reaction_object(); }); + transform(r_reactions.ok(), [](auto &reaction) { return get_reaction_type_object(reaction.reaction_); }); send_closure(actor_id(this), &Td::send_result, id, td_api::make_object(std::move(reactions))); }