diff options
| author | levlam <levlam@telegram.org> | 2024-04-25 15:52:19 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2024-04-25 15:52:19 +0300 |
| commit | 1f6fdd554aed77cb91f2e5b0bba18d8ceda29922 (patch) | |
| tree | abdb693ab852b874cf37095c18f7f61e1f095811 /td/telegram/RepliedMessageInfo.cpp | |
| parent | 275cf2036286faf9d9acf94b5c26fc12180d1c38 (diff) | |
Add class MessageQuote and use it in MessageInputReplyTo and RepliedMessageInfo.
Diffstat (limited to 'td/telegram/RepliedMessageInfo.cpp')
| -rw-r--r-- | td/telegram/RepliedMessageInfo.cpp | 70 |
1 files changed, 16 insertions, 54 deletions
diff --git a/td/telegram/RepliedMessageInfo.cpp b/td/telegram/RepliedMessageInfo.cpp index 11d27c702..e9e06aad9 100644 --- a/td/telegram/RepliedMessageInfo.cpp +++ b/td/telegram/RepliedMessageInfo.cpp @@ -114,12 +114,8 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, tl_object_ptr<telegram_api::messa } } } - if ((!origin_.is_empty() || message_id_ != MessageId()) && !reply_header->quote_text_.empty()) { - is_quote_manual_ = reply_header->quote_; - quote_ = get_formatted_text(td->user_manager_.get(), std::move(reply_header->quote_text_), - std::move(reply_header->quote_entities_), true, true, false, "RepliedMessageInfo"); - remove_unallowed_quote_entities(quote_); - quote_position_ = max(0, reply_header->quote_offset_); + if (!origin_.is_empty() || message_id_ != MessageId()) { + quote_ = MessageQuote(td, reply_header); } } @@ -128,10 +124,8 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, const MessageInputReplyTo &input_ return; } message_id_ = input_reply_to.message_id_; - if (!input_reply_to.quote_.text.empty()) { - quote_ = input_reply_to.quote_; - quote_position_ = input_reply_to.quote_position_; - is_quote_manual_ = true; + if (!input_reply_to.quote_.is_empty()) { + quote_ = input_reply_to.quote_.clone(); } if (input_reply_to.dialog_id_ != DialogId()) { auto info = @@ -145,11 +139,8 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, const MessageInputReplyTo &input_ content_ = std::move(info.content_); auto content_text = get_message_content_text_mutable(content_.get()); if (content_text != nullptr) { - if (!is_quote_manual_) { - quote_ = std::move(*content_text); - remove_unallowed_quote_entities(quote_); - truncate_formatted_text( - quote_, static_cast<size_t>(td->option_manager_->get_option_integer("message_reply_quote_length_max"))); + if (!quote_.is_manual()) { + quote_ = MessageQuote::create_automatic_quote(td, std::move(*content_text)); } *content_text = FormattedText(); } @@ -175,9 +166,7 @@ RepliedMessageInfo RepliedMessageInfo::clone(Td *td) const { result.content_ = dup_message_content(td, td->dialog_manager_->get_my_dialog_id(), content_.get(), MessageContentDupType::Forward, MessageCopyOptions()); } - result.quote_ = quote_; - result.quote_position_ = quote_position_; - result.is_quote_manual_ = is_quote_manual_; + result.quote_ = quote_.clone(); return result; } @@ -198,22 +187,9 @@ bool RepliedMessageInfo::need_reply_changed_warning( // only signature can change in the message origin return true; } - if (old_info.quote_position_ != new_info.quote_position_ && - max(old_info.quote_position_, new_info.quote_position_) < - static_cast<int32>(min(old_info.quote_.text.size(), new_info.quote_.text.size()))) { - // quote position can't change - return true; - } - if (old_info.is_quote_manual_ != new_info.is_quote_manual_) { - // quote manual property can't change - return true; - } - if (old_info.quote_ != new_info.quote_) { - if (old_info.is_quote_manual_) { - return true; - } - // automatic quote can change if the original message was edited - return false; + auto need_quote_warning = MessageQuote::need_quote_changed_warning(old_info.quote_, new_info.quote_); + if (need_quote_warning != 0) { + return need_quote_warning > 0; } if (old_info.dialog_id_ != new_info.dialog_id_ && old_info.dialog_id_ != DialogId() && new_info.dialog_id_ != DialogId()) { @@ -269,7 +245,7 @@ vector<UserId> RepliedMessageInfo::get_min_user_ids(Td *td) const { user_ids.push_back(dialog_id_.get_user_id()); } origin_.add_user_ids(user_ids); - // not supported server-side: add_formatted_text_user_ids(user_ids, "e_); + // not supported server-side: quote_.add_user_ids(user_ids); if (content_ != nullptr) { append(user_ids, get_message_content_min_user_ids(td, content_.get())); } @@ -291,7 +267,7 @@ vector<ChannelId> RepliedMessageInfo::get_min_channel_ids(Td *td) const { void RepliedMessageInfo::add_dependencies(Dependencies &dependencies, bool is_bot) const { dependencies.add_dialog_and_dependencies(dialog_id_); origin_.add_dependencies(dependencies); - add_formatted_text_dependencies(dependencies, "e_); + quote_.add_dependencies(dependencies); if (content_ != nullptr) { add_message_content_dependencies(dependencies, content_.get(), is_bot); } @@ -309,12 +285,6 @@ td_api::object_ptr<td_api::messageReplyToMessage> RepliedMessageInfo::get_messag chat_id = 0; } - td_api::object_ptr<td_api::textQuote> quote; - if (!quote_.text.empty()) { - quote = td_api::make_object<td_api::textQuote>(get_formatted_text_object(quote_, true, -1), quote_position_, - is_quote_manual_); - } - td_api::object_ptr<td_api::MessageOrigin> origin; if (!origin_.is_empty()) { origin = origin_.get_message_origin_object(td); @@ -341,15 +311,14 @@ td_api::object_ptr<td_api::messageReplyToMessage> RepliedMessageInfo::get_messag } } - return td_api::make_object<td_api::messageReplyToMessage>(chat_id, message_id_.get(), std::move(quote), + return td_api::make_object<td_api::messageReplyToMessage>(chat_id, message_id_.get(), quote_.get_text_quote_object(), std::move(origin), origin_date_, std::move(content)); } MessageInputReplyTo RepliedMessageInfo::get_input_reply_to() const { CHECK(!is_external()); if (message_id_.is_valid()) { - FormattedText quote = quote_; - return MessageInputReplyTo(message_id_, dialog_id_, std::move(quote), quote_position_); + return MessageInputReplyTo(message_id_, dialog_id_, quote_.clone(true)); } return {}; } @@ -388,8 +357,7 @@ void RepliedMessageInfo::unregister_content(Td *td) const { bool operator==(const RepliedMessageInfo &lhs, const RepliedMessageInfo &rhs) { if (!(lhs.message_id_ == rhs.message_id_ && lhs.dialog_id_ == rhs.dialog_id_ && - lhs.origin_date_ == rhs.origin_date_ && lhs.origin_ == rhs.origin_ && lhs.quote_ == rhs.quote_ && - lhs.quote_position_ == rhs.quote_position_ && lhs.is_quote_manual_ == rhs.is_quote_manual_)) { + lhs.origin_date_ == rhs.origin_date_ && lhs.origin_ == rhs.origin_ && lhs.quote_ == rhs.quote_)) { return false; } bool need_update = false; @@ -413,13 +381,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const RepliedMessageInf if (info.origin_date_ != 0) { string_builder << " sent at " << info.origin_date_ << " by " << info.origin_; } - if (!info.quote_.text.empty()) { - string_builder << " with " << info.quote_.text.size() << (info.is_quote_manual_ ? " manually" : "") - << " quoted bytes"; - if (info.quote_position_ != 0) { - string_builder << " at position " << info.quote_position_; - } - } + string_builder << info.quote_; if (info.content_ != nullptr) { string_builder << " and content of the type " << info.content_->get_type(); } |
