Move some AvailableReaction methods to AvailableReaction.h.
This commit is contained in:
parent
cb98c0a10a
commit
83fdbd7859
@ -6,8 +6,50 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/AvailableReaction.h"
|
#include "td/telegram/AvailableReaction.h"
|
||||||
|
|
||||||
|
#include "td/utils/algorithm.h"
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
|
AvailableReactionType get_reaction_type(const vector<AvailableReaction> &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<string> get_active_reactions(const vector<string> &available_reactions,
|
||||||
|
const vector<AvailableReaction> &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<string> 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<td_api::availableReaction> AvailableReaction::get_available_reaction_object() const {
|
td_api::object_ptr<td_api::availableReaction> AvailableReaction::get_available_reaction_object() const {
|
||||||
return td_api::make_object<td_api::availableReaction>(reaction_, is_premium_);
|
return td_api::make_object<td_api::availableReaction>(reaction_, is_premium_);
|
||||||
}
|
}
|
||||||
|
@ -28,4 +28,11 @@ inline bool operator!=(const AvailableReaction &lhs, const AvailableReaction &rh
|
|||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class AvailableReactionType { Unavailable, Available, NeedsPremium };
|
||||||
|
|
||||||
|
AvailableReactionType get_reaction_type(const vector<AvailableReaction> &reactions, const string &reaction);
|
||||||
|
|
||||||
|
vector<string> get_active_reactions(const vector<string> &available_reactions,
|
||||||
|
const vector<AvailableReaction> &active_reactions);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -8225,8 +8225,8 @@ void MessagesManager::set_active_reactions(vector<AvailableReaction> active_reac
|
|||||||
break;
|
break;
|
||||||
case DialogType::Chat:
|
case DialogType::Chat:
|
||||||
case DialogType::Channel: {
|
case DialogType::Channel: {
|
||||||
auto old_reactions = get_active_reactions(d->available_reactions, old_active_reactions);
|
auto old_reactions = ::td::get_active_reactions(d->available_reactions, old_active_reactions);
|
||||||
auto new_reactions = get_active_reactions(d->available_reactions, active_reactions_);
|
auto new_reactions = ::td::get_active_reactions(d->available_reactions, active_reactions_);
|
||||||
if (old_reactions != new_reactions) {
|
if (old_reactions != new_reactions) {
|
||||||
if (old_reactions.empty() != new_reactions.empty()) {
|
if (old_reactions.empty() != new_reactions.empty()) {
|
||||||
if (!old_reactions.empty()) {
|
if (!old_reactions.empty()) {
|
||||||
@ -8249,48 +8249,7 @@ void MessagesManager::set_active_reactions(vector<AvailableReaction> active_reac
|
|||||||
}
|
}
|
||||||
|
|
||||||
vector<string> MessagesManager::get_active_reactions(const vector<string> &available_reactions) const {
|
vector<string> MessagesManager::get_active_reactions(const vector<string> &available_reactions) const {
|
||||||
return get_active_reactions(available_reactions, active_reactions_);
|
return ::td::get_active_reactions(available_reactions, active_reactions_);
|
||||||
}
|
|
||||||
|
|
||||||
vector<string> MessagesManager::get_active_reactions(const vector<string> &available_reactions,
|
|
||||||
const vector<AvailableReaction> &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<string> 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<AvailableReaction> &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<string> MessagesManager::get_dialog_active_reactions(const Dialog *d) const {
|
vector<string> MessagesManager::get_dialog_active_reactions(const Dialog *d) const {
|
||||||
|
@ -2659,12 +2659,6 @@ class MessagesManager final : public Actor {
|
|||||||
|
|
||||||
vector<string> get_active_reactions(const vector<string> &available_reactions) const;
|
vector<string> get_active_reactions(const vector<string> &available_reactions) const;
|
||||||
|
|
||||||
static vector<string> get_active_reactions(const vector<string> &available_reactions,
|
|
||||||
const vector<AvailableReaction> &active_reactions);
|
|
||||||
|
|
||||||
enum class AvailableReactionType { Unavailable, Available, NeedsPremium };
|
|
||||||
static AvailableReactionType get_reaction_type(const vector<AvailableReaction> &reactions, const string &reaction);
|
|
||||||
|
|
||||||
vector<string> get_dialog_active_reactions(const Dialog *d) const;
|
vector<string> get_dialog_active_reactions(const Dialog *d) const;
|
||||||
|
|
||||||
vector<string> get_message_active_reactions(const Dialog *d, const Message *m) const;
|
vector<string> get_message_active_reactions(const Dialog *d, const Message *m) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user