Move get_active_reactions to ChatReactions.
This commit is contained in:
parent
c6d5bbb151
commit
81159edcd9
@ -20,21 +20,4 @@ AvailableReactionType get_reaction_type(const vector<string> &available_reaction
|
||||
return AvailableReactionType::Unavailable;
|
||||
}
|
||||
|
||||
ChatReactions get_active_reactions(const ChatReactions &available_reactions, const vector<string> &active_reactions) {
|
||||
if (available_reactions.reactions_.empty()) {
|
||||
// fast path
|
||||
return available_reactions;
|
||||
}
|
||||
CHECK(!available_reactions.allow_all_);
|
||||
CHECK(!available_reactions.allow_custom_);
|
||||
|
||||
vector<string> result;
|
||||
for (const auto &active_reaction : active_reactions) {
|
||||
if (td::contains(available_reactions.reactions_, active_reaction)) {
|
||||
result.push_back(active_reaction);
|
||||
}
|
||||
}
|
||||
return ChatReactions(std::move(result));
|
||||
}
|
||||
|
||||
} // namespace td
|
||||
|
@ -17,6 +17,4 @@ enum class AvailableReactionType : int32 { Unavailable, Available, NeedsPremium
|
||||
|
||||
AvailableReactionType get_reaction_type(const vector<string> &reactions, const string &reaction);
|
||||
|
||||
ChatReactions get_active_reactions(const ChatReactions &available_reactions, const vector<string> &active_reactions);
|
||||
|
||||
} // namespace td
|
||||
|
@ -60,6 +60,23 @@ ChatReactions::ChatReactions(td_api::object_ptr<td_api::ChatAvailableReactions>
|
||||
}
|
||||
}
|
||||
|
||||
ChatReactions ChatReactions::get_active_reactions(const vector<string> &active_reactions) const {
|
||||
if (reactions_.empty()) {
|
||||
// fast path
|
||||
return *this;
|
||||
}
|
||||
CHECK(!allow_all_);
|
||||
CHECK(!allow_custom_);
|
||||
|
||||
vector<string> result;
|
||||
for (const auto &active_reaction : active_reactions) {
|
||||
if (td::contains(reactions_, active_reaction)) {
|
||||
result.push_back(active_reaction);
|
||||
}
|
||||
}
|
||||
return ChatReactions(std::move(result));
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::ChatAvailableReactions> ChatReactions::get_chat_available_reactions_object() const {
|
||||
if (allow_all_) {
|
||||
return td_api::make_object<td_api::chatAvailableReactionsAll>();
|
||||
|
@ -32,6 +32,8 @@ struct ChatReactions {
|
||||
ChatReactions(bool allow_all, bool allow_custom) : allow_all_(allow_all), allow_custom_(allow_custom) {
|
||||
}
|
||||
|
||||
ChatReactions get_active_reactions(const vector<string> &active_reactions) const;
|
||||
|
||||
telegram_api::object_ptr<telegram_api::ChatReactions> get_input_chat_reactions() const;
|
||||
|
||||
td_api::object_ptr<td_api::ChatAvailableReactions> get_chat_available_reactions_object() const;
|
||||
|
@ -8263,8 +8263,8 @@ void MessagesManager::set_active_reactions(vector<string> active_reactions) {
|
||||
break;
|
||||
case DialogType::Chat:
|
||||
case DialogType::Channel: {
|
||||
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_);
|
||||
auto old_reactions = d->available_reactions.get_active_reactions(old_active_reactions);
|
||||
auto new_reactions = d->available_reactions.get_active_reactions(active_reactions_);
|
||||
if (old_reactions != new_reactions) {
|
||||
if (old_reactions.empty() != new_reactions.empty()) {
|
||||
if (!old_reactions.empty()) {
|
||||
@ -8287,7 +8287,7 @@ void MessagesManager::set_active_reactions(vector<string> active_reactions) {
|
||||
}
|
||||
|
||||
ChatReactions MessagesManager::get_active_reactions(const ChatReactions &available_reactions) const {
|
||||
return ::td::get_active_reactions(available_reactions, active_reactions_);
|
||||
return available_reactions.get_active_reactions(active_reactions_);
|
||||
}
|
||||
|
||||
ChatReactions MessagesManager::get_dialog_active_reactions(const Dialog *d) const {
|
||||
|
Loading…
x
Reference in New Issue
Block a user