2022-06-09 00:07:53 +02:00
|
|
|
//
|
|
|
|
// 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"
|
|
|
|
|
2022-06-09 00:48:39 +02:00
|
|
|
#include "td/utils/algorithm.h"
|
|
|
|
|
2022-06-09 00:07:53 +02:00
|
|
|
namespace td {
|
|
|
|
|
2022-06-09 00:48:39 +02:00
|
|
|
AvailableReactionType get_reaction_type(const vector<AvailableReaction> &available_reactions, const string &reaction) {
|
2022-08-24 22:31:15 +02:00
|
|
|
if (reaction[0] == '#') {
|
|
|
|
return AvailableReactionType::NeedsPremium;
|
|
|
|
}
|
2022-06-09 00:48:39 +02:00
|
|
|
for (auto &available_reaction : available_reactions) {
|
|
|
|
if (available_reaction.reaction_ == reaction) {
|
|
|
|
return AvailableReactionType::Available;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AvailableReactionType::Unavailable;
|
|
|
|
}
|
|
|
|
|
2022-08-30 10:45:27 +02:00
|
|
|
ChatReactions get_active_reactions(const ChatReactions &available_reactions,
|
|
|
|
const vector<AvailableReaction> &active_reactions) {
|
2022-06-09 00:48:39 +02:00
|
|
|
if (available_reactions.empty()) {
|
|
|
|
// fast path
|
|
|
|
return available_reactions;
|
|
|
|
}
|
2022-08-30 10:45:27 +02:00
|
|
|
CHECK(!available_reactions.allow_all_);
|
|
|
|
CHECK(!available_reactions.allow_custom_);
|
2022-06-09 00:48:39 +02:00
|
|
|
|
|
|
|
vector<string> result;
|
|
|
|
for (const auto &active_reaction : active_reactions) {
|
2022-08-30 10:45:27 +02:00
|
|
|
if (td::contains(available_reactions.reactions_, active_reaction.reaction_)) {
|
2022-06-09 00:48:39 +02:00
|
|
|
result.push_back(active_reaction.reaction_);
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 10:45:27 +02:00
|
|
|
return ChatReactions(std::move(result));
|
2022-06-09 00:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-06-09 00:07:53 +02:00
|
|
|
bool operator==(const AvailableReaction &lhs, const AvailableReaction &rhs) {
|
2022-08-24 22:31:15 +02:00
|
|
|
return lhs.reaction_ == rhs.reaction_;
|
2022-06-09 00:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|