Fimd media timestamp entities in find_entities.
This commit is contained in:
parent
14cf908017
commit
45bf232417
@ -51,7 +51,7 @@ unique_ptr<DraftMessage> get_draft_message(ContactsManager *contacts_manager,
|
||||
if (!clean_input_string(draft->message_)) {
|
||||
draft->message_.clear();
|
||||
}
|
||||
entities = find_entities(draft->message_, false);
|
||||
entities = find_entities(draft->message_, false, true);
|
||||
}
|
||||
result->input_message_text.text = FormattedText{std::move(draft->message_), std::move(entities)};
|
||||
result->input_message_text.disable_web_page_preview = (flags & telegram_api::draftMessage::NO_WEBPAGE_MASK) != 0;
|
||||
|
@ -363,7 +363,7 @@ class GetDeepLinkInfoQuery final : public Td::ResultHandler {
|
||||
if (!clean_input_string(info->message_)) {
|
||||
info->message_.clear();
|
||||
}
|
||||
entities = find_entities(info->message_, true);
|
||||
entities = find_entities(info->message_, true, true);
|
||||
}
|
||||
FormattedText text{std::move(info->message_), std::move(entities)};
|
||||
return promise_.set_value(
|
||||
|
@ -1030,7 +1030,7 @@ static void parse_caption(FormattedText &caption, ParserT &parser) {
|
||||
if (!check_utf8(caption.text)) {
|
||||
caption.text.clear();
|
||||
}
|
||||
caption.entities = find_entities(caption.text, false);
|
||||
caption.entities = find_entities(caption.text, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3823,14 +3823,14 @@ unique_ptr<MessageContent> get_secret_message_content(
|
||||
}
|
||||
|
||||
auto entities = get_message_entities(std::move(secret_entities));
|
||||
auto status = fix_formatted_text(message_text, entities, true, false, true, true, false);
|
||||
auto status = fix_formatted_text(message_text, entities, true, false, true, td->auth_manager_->is_bot(), false);
|
||||
if (status.is_error()) {
|
||||
LOG(WARNING) << "Receive error " << status << " while parsing secret message \"" << message_text
|
||||
<< "\" with entities " << format::as_array(entities);
|
||||
if (!clean_input_string(message_text)) {
|
||||
message_text.clear();
|
||||
}
|
||||
entities = find_entities(message_text, true);
|
||||
entities = find_entities(message_text, true, td->auth_manager_->is_bot());
|
||||
}
|
||||
|
||||
// support of old layer and old constructions
|
||||
|
@ -1593,7 +1593,7 @@ static void fix_entity_offsets(Slice text, vector<MessageEntity> &entities) {
|
||||
}
|
||||
}
|
||||
|
||||
vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands) {
|
||||
vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands, bool skip_media_timestamps) {
|
||||
vector<MessageEntity> entities;
|
||||
|
||||
auto add_entities = [&entities, &text](MessageEntity::Type type, vector<Slice> (*find_entities_f)(Slice)) mutable {
|
||||
@ -1622,6 +1622,15 @@ vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands) {
|
||||
entities.emplace_back(type, offset, length);
|
||||
}
|
||||
|
||||
if (!skip_media_timestamps) {
|
||||
auto media_timestamps = find_media_timestamps(text);
|
||||
for (auto &entity : media_timestamps) {
|
||||
auto offset = narrow_cast<int32>(entity.first.begin() - text.begin());
|
||||
auto length = narrow_cast<int32>(entity.first.size());
|
||||
entities.emplace_back(MessageEntity::Type::MediaTimestamp, offset, length, to_string(entity.second));
|
||||
}
|
||||
}
|
||||
|
||||
fix_entity_offsets(text, entities);
|
||||
|
||||
return entities;
|
||||
@ -1630,8 +1639,8 @@ vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands) {
|
||||
static vector<MessageEntity> find_media_timestamp_entities(Slice text) {
|
||||
vector<MessageEntity> entities;
|
||||
|
||||
auto new_entities = find_media_timestamps(text);
|
||||
for (auto &entity : new_entities) {
|
||||
auto media_timestamps = find_media_timestamps(text);
|
||||
for (auto &entity : media_timestamps) {
|
||||
auto offset = narrow_cast<int32>(entity.first.begin() - text.begin());
|
||||
auto length = narrow_cast<int32>(entity.first.size());
|
||||
entities.emplace_back(MessageEntity::Type::MediaTimestamp, offset, length, to_string(entity.second));
|
||||
@ -2353,7 +2362,7 @@ static vector<MessageEntity> find_splittable_entities_v3(Slice text, const vecto
|
||||
}
|
||||
}
|
||||
|
||||
auto found_entities = find_entities(text, false);
|
||||
auto found_entities = find_entities(text, false, true);
|
||||
td::remove_if(found_entities, [](const auto &entity) {
|
||||
return entity.type == MessageEntity::Type::EmailAddress || entity.type == MessageEntity::Type::Url;
|
||||
});
|
||||
@ -3992,9 +4001,8 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
|
||||
}
|
||||
|
||||
if (!skip_new_entities) {
|
||||
merge_new_entities(entities, find_entities(text, skip_bot_commands));
|
||||
}
|
||||
if (!skip_media_timestamps) {
|
||||
merge_new_entities(entities, find_entities(text, skip_bot_commands, skip_media_timestamps));
|
||||
} else if (!skip_media_timestamps) {
|
||||
merge_new_entities(entities, find_media_timestamp_entities(text));
|
||||
}
|
||||
|
||||
@ -4024,7 +4032,7 @@ FormattedText get_message_text(const ContactsManager *contacts_manager, string m
|
||||
if (!clean_input_string(message_text)) {
|
||||
message_text.clear();
|
||||
}
|
||||
entities = find_entities(message_text, false);
|
||||
entities = find_entities(message_text, false, skip_media_timestamps);
|
||||
}
|
||||
return FormattedText{std::move(message_text), std::move(entities)};
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ vector<tl_object_ptr<td_api::textEntity>> get_text_entities_object(const vector<
|
||||
|
||||
td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const FormattedText &text, bool skip_bot_commands);
|
||||
|
||||
vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands);
|
||||
vector<MessageEntity> find_entities(Slice text, bool skip_bot_commands, bool skip_media_timestamps);
|
||||
|
||||
vector<Slice> find_mentions(Slice str);
|
||||
vector<Slice> find_bot_commands(Slice str);
|
||||
|
@ -1549,7 +1549,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
|
||||
if (!clean_input_string(poll_results->solution_)) {
|
||||
poll_results->solution_.clear();
|
||||
}
|
||||
entities = find_entities(poll_results->solution_, true);
|
||||
entities = find_entities(poll_results->solution_, true, true);
|
||||
}
|
||||
FormattedText explanation{std::move(poll_results->solution_), std::move(entities)};
|
||||
|
||||
|
@ -8319,7 +8319,7 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getTextEn
|
||||
if (!check_utf8(request.text_)) {
|
||||
return make_error(400, "Text must be encoded in UTF-8");
|
||||
}
|
||||
auto text_entities = find_entities(request.text_, false);
|
||||
auto text_entities = find_entities(request.text_, false, false);
|
||||
return make_tl_object<td_api::textEntities>(get_text_entities_object(text_entities, false));
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ TermsOfService::TermsOfService(telegram_api::object_ptr<telegram_api::help_terms
|
||||
if (!clean_input_string(terms->text_)) {
|
||||
terms->text_.clear();
|
||||
}
|
||||
entities = find_entities(terms->text_, true);
|
||||
entities = find_entities(terms->text_, true, true);
|
||||
}
|
||||
if (terms->text_.empty()) {
|
||||
id_.clear();
|
||||
|
@ -1185,7 +1185,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
|
||||
|
||||
FormattedText description;
|
||||
description.text = web_page->description;
|
||||
description.entities = find_entities(web_page->description, true);
|
||||
description.entities = find_entities(web_page->description, true, true);
|
||||
|
||||
auto r_url = parse_url(web_page->display_url);
|
||||
if (r_url.is_ok()) {
|
||||
|
Loading…
Reference in New Issue
Block a user