diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index cf8523229..3ccdf3893 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -23,6 +23,11 @@ namespace td { +int MessageEntity::get_type_priority(Type type) { + static const int types[] = {5, 5, 5, 5, 5, 9, 9, 2, 1, 1, 5, 5, 5, 5, 9, 9, 0}; + return types[static_cast(type)]; +} + StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &message_entity) { bool has_argument = false; string_builder << '['; diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index 73b2f1557..b9f20b6d4 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -19,7 +19,6 @@ #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" -#include #include #include @@ -28,8 +27,6 @@ namespace td { class ContactsManager; class MessageEntity { - tl_object_ptr get_text_entity_type_object() const; - public: enum class Type : int32 { Mention, @@ -73,7 +70,15 @@ class MessageEntity { } bool operator<(const MessageEntity &other) const { - return std::tie(offset, length, type) < std::tie(other.offset, other.length, other.type); + if (offset != other.offset) { + return offset < other.offset; + } + if (length != other.length) { + return length > other.length; + } + auto priority = get_type_priority(type); + auto other_priority = get_type_priority(other.type); + return priority < other_priority; } bool operator!=(const MessageEntity &rhs) const { @@ -85,6 +90,11 @@ class MessageEntity { template void parse(ParserT &parser); + + private: + tl_object_ptr get_text_entity_type_object() const; + + static int get_type_priority(Type type); }; StringBuilder &operator<<(StringBuilder &string_builder, const MessageEntity &message_entity);