diff --git a/td/telegram/ChatReactions.cpp b/td/telegram/ChatReactions.cpp index 879be05f3..ffe20108f 100644 --- a/td/telegram/ChatReactions.cpp +++ b/td/telegram/ChatReactions.cpp @@ -25,9 +25,7 @@ ChatReactions::ChatReactions(telegram_api::object_ptr(chat_reactions_ptr); - reaction_types_ = transform( - chat_reactions->reactions_, - [](const telegram_api::object_ptr &reaction) { return ReactionType(reaction); }); + reaction_types_ = ReactionType::get_reaction_types(chat_reactions->reactions_); break; } default: @@ -47,9 +45,7 @@ ChatReactions::ChatReactions(td_api::object_ptr break; case td_api::chatAvailableReactionsSome::ID: { auto chat_reactions = move_tl_object_as(chat_reactions_ptr); - reaction_types_ = - transform(chat_reactions->reactions_, - [](const td_api::object_ptr &reaction) { return ReactionType(reaction); }); + reaction_types_ = ReactionType::get_reaction_types(chat_reactions->reactions_); break; } default: @@ -82,8 +78,8 @@ td_api::object_ptr ChatReactions::get_chat_avail if (allow_all_regular_) { return td_api::make_object(); } - return td_api::make_object(transform( - reaction_types_, [](const ReactionType &reaction_type) { return reaction_type.get_reaction_type_object(); })); + return td_api::make_object( + ReactionType::get_reaction_types_object(reaction_types_)); } telegram_api::object_ptr ChatReactions::get_input_chat_reactions() const { @@ -95,8 +91,8 @@ telegram_api::object_ptr ChatReactions::get_input_c return telegram_api::make_object(flags, allow_all_custom_); } if (!reaction_types_.empty()) { - return telegram_api::make_object(transform( - reaction_types_, [](const ReactionType &reaction_type) { return reaction_type.get_input_reaction(); })); + return telegram_api::make_object( + ReactionType::get_input_reactions(reaction_types_)); } return telegram_api::make_object(); } diff --git a/td/telegram/MessageReaction.cpp b/td/telegram/MessageReaction.cpp index 91649f8db..865d02b94 100644 --- a/td/telegram/MessageReaction.cpp +++ b/td/telegram/MessageReaction.cpp @@ -123,11 +123,9 @@ class SendReactionQuery final : public Td::ResultHandler { } send_query(G()->net_query_creator().create( - telegram_api::messages_sendReaction( - flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), - message_full_id.get_message_id().get_server_message_id().get(), - transform(reaction_types, - [](const ReactionType &reaction_type) { return reaction_type.get_input_reaction(); })), + telegram_api::messages_sendReaction(flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), + message_full_id.get_message_id().get_server_message_id().get(), + ReactionType::get_input_reactions(reaction_types)), {{dialog_id_}, {message_full_id}})); } diff --git a/td/telegram/ReactionManager.cpp b/td/telegram/ReactionManager.cpp index 017e055aa..f95a028e1 100644 --- a/td/telegram/ReactionManager.cpp +++ b/td/telegram/ReactionManager.cpp @@ -627,9 +627,7 @@ void ReactionManager::on_get_recent_reactions(tl_object_ptr(reactions_ptr); - auto new_reaction_types = transform( - reactions->reactions_, - [](const telegram_api::object_ptr &reaction) { return ReactionType(reaction); }); + auto new_reaction_types = ReactionType::get_reaction_types(reactions->reactions_); if (new_reaction_types == recent_reactions_.reaction_types_ && recent_reactions_.hash_ == reactions->hash_) { LOG(INFO) << "Top reactions are not modified"; return; @@ -663,9 +661,7 @@ void ReactionManager::on_get_top_reactions(tl_object_ptr(reactions_ptr); - auto new_reaction_types = transform( - reactions->reactions_, - [](const telegram_api::object_ptr &reaction) { return ReactionType(reaction); }); + auto new_reaction_types = ReactionType::get_reaction_types(reactions->reactions_); if (new_reaction_types == top_reactions_.reaction_types_ && top_reactions_.hash_ == reactions->hash_) { LOG(INFO) << "Top reactions are not modified"; return; diff --git a/td/telegram/ReactionType.cpp b/td/telegram/ReactionType.cpp index c273f9c0b..d9168db4a 100644 --- a/td/telegram/ReactionType.cpp +++ b/td/telegram/ReactionType.cpp @@ -8,6 +8,7 @@ #include "td/telegram/misc.h" +#include "td/utils/algorithm.h" #include "td/utils/as.h" #include "td/utils/base64.h" #include "td/utils/crypto.h" @@ -84,6 +85,28 @@ ReactionType::ReactionType(const td_api::object_ptr &type) } } +vector ReactionType::get_reaction_types( + const vector> &reactions) { + return transform(reactions, [](const auto &reaction) { return ReactionType(reaction); }); +} + +vector ReactionType::get_reaction_types( + const vector> &reactions) { + return transform(reactions, [](const auto &reaction) { return ReactionType(reaction); }); +} + +vector> ReactionType::get_input_reactions( + const vector &reaction_types) { + return transform(reaction_types, + [](const ReactionType &reaction_type) { return reaction_type.get_input_reaction(); }); +} + +vector> ReactionType::get_reaction_types_object( + const vector &reaction_types) { + return transform(reaction_types, + [](const ReactionType &reaction_type) { return reaction_type.get_reaction_type_object(); }); +} + telegram_api::object_ptr ReactionType::get_input_reaction() const { if (is_empty()) { return telegram_api::make_object(); diff --git a/td/telegram/ReactionType.h b/td/telegram/ReactionType.h index d78b27926..888b55d78 100644 --- a/td/telegram/ReactionType.h +++ b/td/telegram/ReactionType.h @@ -38,6 +38,17 @@ class ReactionType { explicit ReactionType(const td_api::object_ptr &type); + static vector get_reaction_types( + const vector> &reactions); + + static vector get_reaction_types(const vector> &reactions); + + static vector> get_input_reactions( + const vector &reaction_types); + + static vector> get_reaction_types_object( + const vector &reaction_types); + telegram_api::object_ptr get_input_reaction() const; td_api::object_ptr get_reaction_type_object() const;