diff --git a/td/telegram/ChatReactions.cpp b/td/telegram/ChatReactions.cpp index dc838d5b6..a3a6d6b64 100644 --- a/td/telegram/ChatReactions.cpp +++ b/td/telegram/ChatReactions.cpp @@ -73,7 +73,7 @@ ChatReactions ChatReactions::get_active_reactions(const FlatHashMap get_input_reaction(const string if (reaction.empty()) { return telegram_api::make_object(); } - if (reaction[0] == '#') { + if (is_custom_reaction(reaction)) { return telegram_api::make_object(get_custom_emoji_id(reaction)); } return telegram_api::make_object(reaction); @@ -66,7 +66,7 @@ string get_message_reaction_string(const telegram_api::object_ptr(reaction.get())->emoticon_; - if (emoji[0] == '#') { + if (is_custom_reaction(emoji)) { return string(); } return emoji; @@ -82,7 +82,7 @@ string get_message_reaction_string(const telegram_api::object_ptr get_reaction_type_object(const string &reaction) { CHECK(!reaction.empty()); - if (reaction[0] == '#') { + if (is_custom_reaction(reaction)) { return td_api::make_object(get_custom_emoji_id(reaction)); } return td_api::make_object(reaction); @@ -95,7 +95,7 @@ string get_message_reaction_string(const td_api::object_ptrget_id()) { case td_api::reactionTypeEmoji::ID: { const string &emoji = static_cast(type.get())->emoji_; - if (!check_utf8(emoji) || emoji[0] == '#') { + if (!check_utf8(emoji) || is_custom_reaction(emoji)) { return string(); } return emoji; @@ -675,8 +675,12 @@ StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr &active_reaction_pos) { - return !reaction.empty() && (reaction[0] == '#' || active_reaction_pos.count(reaction) > 0); + return !reaction.empty() && (is_custom_reaction(reaction) || active_reaction_pos.count(reaction) > 0); } void reload_message_reactions(Td *td, DialogId dialog_id, vector &&message_ids) { @@ -726,7 +730,7 @@ void set_default_reaction(Td *td, string reaction, Promise &&promise) { if (reaction.empty()) { return promise.set_error(Status::Error(400, "Default reaction must be non-empty")); } - if (reaction[0] != '#' && !td->stickers_manager_->is_active_reaction(reaction)) { + if (!is_custom_reaction(reaction) && !td->stickers_manager_->is_active_reaction(reaction)) { return promise.set_error(Status::Error(400, "Can't set incative reaction as default")); } diff --git a/td/telegram/MessageReaction.h b/td/telegram/MessageReaction.h index 855b3c6ec..5e8da9939 100644 --- a/td/telegram/MessageReaction.h +++ b/td/telegram/MessageReaction.h @@ -181,6 +181,8 @@ string get_message_reaction_string(const telegram_api::object_ptr &type); +bool is_custom_reaction(const string &reaction); + bool is_active_reaction(const string &reaction, const FlatHashMap &active_reaction_pos); void reload_message_reactions(Td *td, DialogId dialog_id, vector &&message_ids);