Improve ChatReactions field names.

This commit is contained in:
levlam 2023-11-19 02:03:19 +03:00
parent ec788c7505
commit 3e3fe5f9bb
5 changed files with 34 additions and 33 deletions

View File

@ -19,8 +19,8 @@ ChatReactions::ChatReactions(telegram_api::object_ptr<telegram_api::ChatReaction
break; break;
case telegram_api::chatReactionsAll::ID: { case telegram_api::chatReactionsAll::ID: {
auto chat_reactions = move_tl_object_as<telegram_api::chatReactionsAll>(chat_reactions_ptr); auto chat_reactions = move_tl_object_as<telegram_api::chatReactionsAll>(chat_reactions_ptr);
allow_all_ = true; allow_all_regular_ = true;
allow_custom_ = chat_reactions->allow_custom_; allow_all_custom_ = chat_reactions->allow_custom_;
break; break;
} }
case telegram_api::chatReactionsSome::ID: { case telegram_api::chatReactionsSome::ID: {
@ -36,14 +36,14 @@ ChatReactions::ChatReactions(telegram_api::object_ptr<telegram_api::ChatReaction
} }
ChatReactions::ChatReactions(td_api::object_ptr<td_api::ChatAvailableReactions> &&chat_reactions_ptr, ChatReactions::ChatReactions(td_api::object_ptr<td_api::ChatAvailableReactions> &&chat_reactions_ptr,
bool allow_custom) { bool allow_all_custom) {
if (chat_reactions_ptr == nullptr) { if (chat_reactions_ptr == nullptr) {
return; return;
} }
switch (chat_reactions_ptr->get_id()) { switch (chat_reactions_ptr->get_id()) {
case td_api::chatAvailableReactionsAll::ID: case td_api::chatAvailableReactionsAll::ID:
allow_all_ = true; allow_all_regular_ = true;
allow_custom_ = allow_custom; allow_all_custom_ = allow_all_custom;
break; break;
case td_api::chatAvailableReactionsSome::ID: { case td_api::chatAvailableReactionsSome::ID: {
auto chat_reactions = move_tl_object_as<td_api::chatAvailableReactionsSome>(chat_reactions_ptr); auto chat_reactions = move_tl_object_as<td_api::chatAvailableReactionsSome>(chat_reactions_ptr);
@ -61,8 +61,8 @@ ChatReactions ChatReactions::get_active_reactions(
const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos) const { const FlatHashMap<ReactionType, size_t, ReactionTypeHash> &active_reaction_pos) const {
ChatReactions result = *this; ChatReactions result = *this;
if (!reaction_types_.empty()) { if (!reaction_types_.empty()) {
CHECK(!allow_all_); CHECK(!allow_all_regular_);
CHECK(!allow_custom_); CHECK(!allow_all_custom_);
td::remove_if(result.reaction_types_, [&](const ReactionType &reaction_type) { td::remove_if(result.reaction_types_, [&](const ReactionType &reaction_type) {
return !reaction_type.is_active_reaction(active_reaction_pos); return !reaction_type.is_active_reaction(active_reaction_pos);
}); });
@ -71,15 +71,15 @@ ChatReactions ChatReactions::get_active_reactions(
} }
bool ChatReactions::is_allowed_reaction_type(const ReactionType &reaction_type) const { bool ChatReactions::is_allowed_reaction_type(const ReactionType &reaction_type) const {
CHECK(!allow_all_); CHECK(!allow_all_regular_);
if (allow_custom_ && reaction_type.is_custom_reaction()) { if (allow_all_custom_ && reaction_type.is_custom_reaction()) {
return true; return true;
} }
return td::contains(reaction_types_, reaction_type); return td::contains(reaction_types_, reaction_type);
} }
td_api::object_ptr<td_api::ChatAvailableReactions> ChatReactions::get_chat_available_reactions_object() const { td_api::object_ptr<td_api::ChatAvailableReactions> ChatReactions::get_chat_available_reactions_object() const {
if (allow_all_) { if (allow_all_regular_) {
return td_api::make_object<td_api::chatAvailableReactionsAll>(); return td_api::make_object<td_api::chatAvailableReactionsAll>();
} }
return td_api::make_object<td_api::chatAvailableReactionsSome>(transform( return td_api::make_object<td_api::chatAvailableReactionsSome>(transform(
@ -87,12 +87,12 @@ td_api::object_ptr<td_api::ChatAvailableReactions> ChatReactions::get_chat_avail
} }
telegram_api::object_ptr<telegram_api::ChatReactions> ChatReactions::get_input_chat_reactions() const { telegram_api::object_ptr<telegram_api::ChatReactions> ChatReactions::get_input_chat_reactions() const {
if (allow_all_) { if (allow_all_regular_) {
int32 flags = 0; int32 flags = 0;
if (allow_custom_) { if (allow_all_custom_) {
flags |= telegram_api::chatReactionsAll::ALLOW_CUSTOM_MASK; flags |= telegram_api::chatReactionsAll::ALLOW_CUSTOM_MASK;
} }
return telegram_api::make_object<telegram_api::chatReactionsAll>(flags, allow_custom_); return telegram_api::make_object<telegram_api::chatReactionsAll>(flags, allow_all_custom_);
} }
if (!reaction_types_.empty()) { if (!reaction_types_.empty()) {
return telegram_api::make_object<telegram_api::chatReactionsSome>(transform( return telegram_api::make_object<telegram_api::chatReactionsSome>(transform(
@ -102,13 +102,13 @@ telegram_api::object_ptr<telegram_api::ChatReactions> ChatReactions::get_input_c
} }
bool operator==(const ChatReactions &lhs, const ChatReactions &rhs) { bool operator==(const ChatReactions &lhs, const ChatReactions &rhs) {
// don't compare allow_custom_ // don't compare allow_all_custom_
return lhs.reaction_types_ == rhs.reaction_types_ && lhs.allow_all_ == rhs.allow_all_; return lhs.reaction_types_ == rhs.reaction_types_ && lhs.allow_all_regular_ == rhs.allow_all_regular_;
} }
StringBuilder &operator<<(StringBuilder &string_builder, const ChatReactions &reactions) { StringBuilder &operator<<(StringBuilder &string_builder, const ChatReactions &reactions) {
if (reactions.allow_all_) { if (reactions.allow_all_regular_) {
if (reactions.allow_custom_) { if (reactions.allow_all_custom_) {
return string_builder << "AllReactions"; return string_builder << "AllReactions";
} }
return string_builder << "AllRegularReactions"; return string_builder << "AllRegularReactions";

View File

@ -18,8 +18,8 @@ namespace td {
struct ChatReactions { struct ChatReactions {
vector<ReactionType> reaction_types_; vector<ReactionType> reaction_types_;
bool allow_all_ = false; // implies empty reaction_types_ bool allow_all_regular_ = false; // implies empty reaction_types_
bool allow_custom_ = false; // implies allow_all_ bool allow_all_custom_ = false; // implies allow_all_regular_
ChatReactions() = default; ChatReactions() = default;
@ -28,9 +28,10 @@ struct ChatReactions {
explicit ChatReactions(telegram_api::object_ptr<telegram_api::ChatReactions> &&chat_reactions_ptr); explicit ChatReactions(telegram_api::object_ptr<telegram_api::ChatReactions> &&chat_reactions_ptr);
ChatReactions(td_api::object_ptr<td_api::ChatAvailableReactions> &&chat_reactions_ptr, bool allow_custom); ChatReactions(td_api::object_ptr<td_api::ChatAvailableReactions> &&chat_reactions_ptr, bool allow_all_custom);
ChatReactions(bool allow_all, bool allow_custom) : allow_all_(allow_all), allow_custom_(allow_custom) { ChatReactions(bool allow_all_regular, bool allow_all_custom)
: allow_all_regular_(allow_all_regular), allow_all_custom_(allow_all_custom) {
} }
ChatReactions get_active_reactions( ChatReactions get_active_reactions(
@ -43,7 +44,7 @@ struct ChatReactions {
td_api::object_ptr<td_api::ChatAvailableReactions> get_chat_available_reactions_object() const; td_api::object_ptr<td_api::ChatAvailableReactions> get_chat_available_reactions_object() const;
bool empty() const { bool empty() const {
return reaction_types_.empty() && !allow_all_; return reaction_types_.empty() && !allow_all_regular_;
} }
template <class StorerT> template <class StorerT>

View File

@ -18,8 +18,8 @@ template <class StorerT>
void ChatReactions::store(StorerT &storer) const { void ChatReactions::store(StorerT &storer) const {
bool has_reactions = !reaction_types_.empty(); bool has_reactions = !reaction_types_.empty();
BEGIN_STORE_FLAGS(); BEGIN_STORE_FLAGS();
STORE_FLAG(allow_all_); STORE_FLAG(allow_all_regular_);
STORE_FLAG(allow_custom_); STORE_FLAG(allow_all_custom_);
STORE_FLAG(has_reactions); STORE_FLAG(has_reactions);
END_STORE_FLAGS(); END_STORE_FLAGS();
if (has_reactions) { if (has_reactions) {
@ -31,8 +31,8 @@ template <class ParserT>
void ChatReactions::parse(ParserT &parser) { void ChatReactions::parse(ParserT &parser) {
bool has_reactions; bool has_reactions;
BEGIN_PARSE_FLAGS(); BEGIN_PARSE_FLAGS();
PARSE_FLAG(allow_all_); PARSE_FLAG(allow_all_regular_);
PARSE_FLAG(allow_custom_); PARSE_FLAG(allow_all_custom_);
PARSE_FLAG(has_reactions); PARSE_FLAG(has_reactions);
END_PARSE_FLAGS(); END_PARSE_FLAGS();
if (has_reactions) { if (has_reactions) {

View File

@ -23816,9 +23816,9 @@ ChatReactions MessagesManager::get_message_available_reactions(const Dialog *d,
active_reactions = ChatReactions(); active_reactions = ChatReactions();
} }
if (active_reactions.allow_all_) { if (active_reactions.allow_all_regular_) {
active_reactions.reaction_types_ = active_reaction_types_; active_reactions.reaction_types_ = active_reaction_types_;
active_reactions.allow_all_ = false; active_reactions.allow_all_regular_ = false;
} }
if (can_use_reactions && m->reactions != nullptr) { if (can_use_reactions && m->reactions != nullptr) {
for (const auto &reaction : m->reactions->reactions_) { for (const auto &reaction : m->reactions->reactions_) {
@ -23831,7 +23831,7 @@ ChatReactions MessagesManager::get_message_available_reactions(const Dialog *d,
} }
} }
if (disallow_custom_for_non_premium && !td_->option_manager_->get_option_boolean("is_premium")) { if (disallow_custom_for_non_premium && !td_->option_manager_->get_option_boolean("is_premium")) {
active_reactions.allow_custom_ = false; active_reactions.allow_all_custom_ = false;
} }
return active_reactions; return active_reactions;
} }

View File

@ -238,7 +238,7 @@ td_api::object_ptr<td_api::availableReactions> ReactionManager::get_sorted_avail
auto top_reactions = top_reactions_.reaction_types_; auto top_reactions = top_reactions_.reaction_types_;
LOG(INFO) << "Have available reactions " << available_reactions << " to be sorted by top reactions " << top_reactions LOG(INFO) << "Have available reactions " << available_reactions << " to be sorted by top reactions " << top_reactions
<< " and recent reactions " << recent_reactions; << " and recent reactions " << recent_reactions;
if (active_reactions.allow_custom_ && active_reactions.allow_all_) { if (active_reactions.allow_all_custom_ && active_reactions.allow_all_regular_) {
for (auto &reaction_type : recent_reactions) { for (auto &reaction_type : recent_reactions) {
if (reaction_type.is_custom_reaction()) { if (reaction_type.is_custom_reaction()) {
show_premium = true; show_premium = true;
@ -273,7 +273,7 @@ td_api::object_ptr<td_api::availableReactions> ReactionManager::get_sorted_avail
} }
reaction_objects.push_back( reaction_objects.push_back(
td_api::make_object<td_api::availableReaction>(reaction_type.get_reaction_type_object(), false)); td_api::make_object<td_api::availableReaction>(reaction_type.get_reaction_type_object(), false));
} else if (reaction_type.is_custom_reaction() && available_reactions.allow_custom_ && } else if (reaction_type.is_custom_reaction() && available_reactions.allow_all_custom_ &&
added_custom_reaction_types.insert(reaction_type).second) { added_custom_reaction_types.insert(reaction_type).second) {
// add implicitly available custom reaction // add implicitly available custom reaction
reaction_objects.push_back( reaction_objects.push_back(
@ -320,13 +320,13 @@ td_api::object_ptr<td_api::availableReactions> ReactionManager::get_sorted_avail
return td_api::make_object<td_api::availableReactions>( return td_api::make_object<td_api::availableReactions>(
std::move(top_reaction_objects), std::move(recent_reaction_objects), std::move(popular_reaction_objects), std::move(top_reaction_objects), std::move(recent_reaction_objects), std::move(popular_reaction_objects),
available_reactions.allow_custom_); available_reactions.allow_all_custom_);
} }
td_api::object_ptr<td_api::availableReactions> ReactionManager::get_available_reactions(int32 row_size) { td_api::object_ptr<td_api::availableReactions> ReactionManager::get_available_reactions(int32 row_size) {
ChatReactions available_reactions; ChatReactions available_reactions;
available_reactions.reaction_types_ = active_reaction_types_; available_reactions.reaction_types_ = active_reaction_types_;
available_reactions.allow_custom_ = true; available_reactions.allow_all_custom_ = true;
return get_sorted_available_reactions(std::move(available_reactions), ChatReactions(true, true), row_size); return get_sorted_available_reactions(std::move(available_reactions), ChatReactions(true, true), row_size);
} }