diff --git a/td/telegram/AvailableReaction.cpp b/td/telegram/AvailableReaction.cpp index 2d7bea14e..dfd794437 100644 --- a/td/telegram/AvailableReaction.cpp +++ b/td/telegram/AvailableReaction.cpp @@ -6,8 +6,50 @@ // #include "td/telegram/AvailableReaction.h" +#include "td/utils/algorithm.h" + namespace td { +AvailableReactionType get_reaction_type(const vector &available_reactions, const string &reaction) { + for (auto &available_reaction : available_reactions) { + if (available_reaction.reaction_ == reaction) { + if (available_reaction.is_premium_) { + return AvailableReactionType::NeedsPremium; + } + return AvailableReactionType::Available; + } + } + return AvailableReactionType::Unavailable; +} + +vector get_active_reactions(const vector &available_reactions, + const vector &active_reactions) { + if (available_reactions.empty()) { + // fast path + return available_reactions; + } + if (available_reactions.size() == active_reactions.size()) { + size_t i; + for (i = 0; i < available_reactions.size(); i++) { + if (available_reactions[i] != active_reactions[i].reaction_) { + break; + } + } + if (i == available_reactions.size()) { + // fast path + return available_reactions; + } + } + + vector result; + for (const auto &active_reaction : active_reactions) { + if (td::contains(available_reactions, active_reaction.reaction_)) { + result.push_back(active_reaction.reaction_); + } + } + return result; +} + td_api::object_ptr AvailableReaction::get_available_reaction_object() const { return td_api::make_object(reaction_, is_premium_); } diff --git a/td/telegram/AvailableReaction.h b/td/telegram/AvailableReaction.h index 31a872334..406f028fb 100644 --- a/td/telegram/AvailableReaction.h +++ b/td/telegram/AvailableReaction.h @@ -28,4 +28,11 @@ inline bool operator!=(const AvailableReaction &lhs, const AvailableReaction &rh return !(lhs == rhs); } +enum class AvailableReactionType { Unavailable, Available, NeedsPremium }; + +AvailableReactionType get_reaction_type(const vector &reactions, const string &reaction); + +vector get_active_reactions(const vector &available_reactions, + const vector &active_reactions); + } // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 3e809b267..dfa6006d0 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -8225,8 +8225,8 @@ void MessagesManager::set_active_reactions(vector active_reac break; case DialogType::Chat: case DialogType::Channel: { - auto old_reactions = get_active_reactions(d->available_reactions, old_active_reactions); - auto new_reactions = get_active_reactions(d->available_reactions, active_reactions_); + auto old_reactions = ::td::get_active_reactions(d->available_reactions, old_active_reactions); + auto new_reactions = ::td::get_active_reactions(d->available_reactions, active_reactions_); if (old_reactions != new_reactions) { if (old_reactions.empty() != new_reactions.empty()) { if (!old_reactions.empty()) { @@ -8249,48 +8249,7 @@ void MessagesManager::set_active_reactions(vector active_reac } vector MessagesManager::get_active_reactions(const vector &available_reactions) const { - return get_active_reactions(available_reactions, active_reactions_); -} - -vector MessagesManager::get_active_reactions(const vector &available_reactions, - const vector &active_reactions) { - if (available_reactions.empty()) { - // fast path - return available_reactions; - } - if (available_reactions.size() == active_reactions.size()) { - size_t i; - for (i = 0; i < available_reactions.size(); i++) { - if (available_reactions[i] != active_reactions[i].reaction_) { - break; - } - } - if (i == available_reactions.size()) { - // fast path - return available_reactions; - } - } - - vector result; - for (const auto &active_reaction : active_reactions) { - if (td::contains(available_reactions, active_reaction.reaction_)) { - result.push_back(active_reaction.reaction_); - } - } - return result; -} - -MessagesManager::AvailableReactionType MessagesManager::get_reaction_type( - const vector &available_reactions, const string &reaction) { - for (auto &available_reaction : available_reactions) { - if (available_reaction.reaction_ == reaction) { - if (available_reaction.is_premium_) { - return AvailableReactionType::NeedsPremium; - } - return AvailableReactionType::Available; - } - } - return AvailableReactionType::Unavailable; + return ::td::get_active_reactions(available_reactions, active_reactions_); } vector MessagesManager::get_dialog_active_reactions(const Dialog *d) const { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index e95ef26fe..02af835ec 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2659,12 +2659,6 @@ class MessagesManager final : public Actor { vector get_active_reactions(const vector &available_reactions) const; - static vector get_active_reactions(const vector &available_reactions, - const vector &active_reactions); - - enum class AvailableReactionType { Unavailable, Available, NeedsPremium }; - static AvailableReactionType get_reaction_type(const vector &reactions, const string &reaction); - vector get_dialog_active_reactions(const Dialog *d) const; vector get_message_active_reactions(const Dialog *d, const Message *m) const;