From ac5e8e7eda7ae006bf88ec03726ed09bf2b4f94a Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 8 Sep 2022 18:25:12 +0300 Subject: [PATCH] Remove class AvailableReactionType. --- CMakeLists.txt | 2 -- td/telegram/AvailableReaction.cpp | 23 ----------------------- td/telegram/AvailableReaction.h | 20 -------------------- td/telegram/MessagesManager.cpp | 17 ++++------------- 4 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 td/telegram/AvailableReaction.cpp delete mode 100644 td/telegram/AvailableReaction.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 218012006..779763bb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,7 +289,6 @@ set(TDLIB_SOURCE td/telegram/AudiosManager.cpp td/telegram/AuthManager.cpp td/telegram/AutoDownloadSettings.cpp - td/telegram/AvailableReaction.cpp td/telegram/BackgroundManager.cpp td/telegram/BackgroundType.cpp td/telegram/BotCommand.cpp @@ -493,7 +492,6 @@ set(TDLIB_SOURCE td/telegram/AudiosManager.h td/telegram/AuthManager.h td/telegram/AutoDownloadSettings.h - td/telegram/AvailableReaction.h td/telegram/BackgroundId.h td/telegram/BackgroundManager.h td/telegram/BackgroundType.h diff --git a/td/telegram/AvailableReaction.cpp b/td/telegram/AvailableReaction.cpp deleted file mode 100644 index 10eae8663..000000000 --- a/td/telegram/AvailableReaction.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -#include "td/telegram/AvailableReaction.h" - -#include "td/utils/algorithm.h" - -namespace td { - -AvailableReactionType get_reaction_type(const vector &available_reactions, const string &reaction) { - if (reaction[0] == '#') { - return AvailableReactionType::NeedsPremium; - } - if (contains(available_reactions, reaction)) { - return AvailableReactionType::Available; - } - return AvailableReactionType::Unavailable; -} - -} // namespace td diff --git a/td/telegram/AvailableReaction.h b/td/telegram/AvailableReaction.h deleted file mode 100644 index b0f5950e0..000000000 --- a/td/telegram/AvailableReaction.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -#pragma once - -#include "td/telegram/ChatReactions.h" -#include "td/telegram/td_api.h" - -#include "td/utils/common.h" - -namespace td { - -enum class AvailableReactionType : int32 { Unavailable, Available, NeedsPremium }; - -AvailableReactionType get_reaction_type(const vector &reactions, const string &reaction); - -} // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 0fc376cfd..917475e5f 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -7,7 +7,6 @@ #include "td/telegram/MessagesManager.h" #include "td/telegram/AuthManager.h" -#include "td/telegram/AvailableReaction.h" #include "td/telegram/ChainId.h" #include "td/telegram/ChannelType.h" #include "td/telegram/ChatId.h" @@ -24508,10 +24507,8 @@ vector MessagesManager::get_message_available_reactions(const Dialog *d, } if (m->reactions != nullptr) { for (const auto &reaction : m->reactions->reactions_) { - if (reaction.is_chosen() && - get_reaction_type(result, reaction.get_reaction()) == AvailableReactionType::Unavailable) { - CHECK(!can_use_reactions || - get_reaction_type(active_reactions_, reaction.get_reaction()) == AvailableReactionType::Unavailable); + if (reaction.is_chosen() && !td::contains(result, reaction.get_reaction())) { + CHECK(!can_use_reactions || !td::contains(active_reactions_, reaction.get_reaction())); result.push_back(reaction.get_reaction()); } } @@ -24532,14 +24529,8 @@ void MessagesManager::set_message_reaction(FullMessageId full_message_id, string return promise.set_error(Status::Error(400, "Message not found")); } - if (!reaction.empty()) { - auto reaction_type = get_reaction_type(get_message_available_reactions(d, m), reaction); - if (reaction_type == AvailableReactionType::Unavailable) { - return promise.set_error(Status::Error(400, "The reaction isn't available for the message")); - } - if (reaction_type == AvailableReactionType::NeedsPremium) { - return promise.set_error(Status::Error(400, "The reaction is available only for Telegram Premium users")); - } + if (!reaction.empty() && !td::contains(get_message_available_reactions(d, m), reaction)) { + return promise.set_error(Status::Error(400, "The reaction isn't available for the message")); } bool can_get_added_reactions = !is_broadcast_channel(dialog_id) && dialog_id.get_type() != DialogType::User &&