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_)) {
|
if (!clean_input_string(draft->message_)) {
|
||||||
draft->message_.clear();
|
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.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;
|
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_)) {
|
if (!clean_input_string(info->message_)) {
|
||||||
info->message_.clear();
|
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)};
|
FormattedText text{std::move(info->message_), std::move(entities)};
|
||||||
return promise_.set_value(
|
return promise_.set_value(
|
||||||
|
@ -1030,7 +1030,7 @@ static void parse_caption(FormattedText &caption, ParserT &parser) {
|
|||||||
if (!check_utf8(caption.text)) {
|
if (!check_utf8(caption.text)) {
|
||||||
caption.text.clear();
|
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 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()) {
|
if (status.is_error()) {
|
||||||
LOG(WARNING) << "Receive error " << status << " while parsing secret message \"" << message_text
|
LOG(WARNING) << "Receive error " << status << " while parsing secret message \"" << message_text
|
||||||
<< "\" with entities " << format::as_array(entities);
|
<< "\" with entities " << format::as_array(entities);
|
||||||
if (!clean_input_string(message_text)) {
|
if (!clean_input_string(message_text)) {
|
||||||
message_text.clear();
|
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
|
// 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;
|
vector<MessageEntity> entities;
|
||||||
|
|
||||||
auto add_entities = [&entities, &text](MessageEntity::Type type, vector<Slice> (*find_entities_f)(Slice)) mutable {
|
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);
|
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);
|
fix_entity_offsets(text, entities);
|
||||||
|
|
||||||
return 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) {
|
static vector<MessageEntity> find_media_timestamp_entities(Slice text) {
|
||||||
vector<MessageEntity> entities;
|
vector<MessageEntity> entities;
|
||||||
|
|
||||||
auto new_entities = find_media_timestamps(text);
|
auto media_timestamps = find_media_timestamps(text);
|
||||||
for (auto &entity : new_entities) {
|
for (auto &entity : media_timestamps) {
|
||||||
auto offset = narrow_cast<int32>(entity.first.begin() - text.begin());
|
auto offset = narrow_cast<int32>(entity.first.begin() - text.begin());
|
||||||
auto length = narrow_cast<int32>(entity.first.size());
|
auto length = narrow_cast<int32>(entity.first.size());
|
||||||
entities.emplace_back(MessageEntity::Type::MediaTimestamp, offset, length, to_string(entity.second));
|
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) {
|
td::remove_if(found_entities, [](const auto &entity) {
|
||||||
return entity.type == MessageEntity::Type::EmailAddress || entity.type == MessageEntity::Type::Url;
|
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) {
|
if (!skip_new_entities) {
|
||||||
merge_new_entities(entities, find_entities(text, skip_bot_commands));
|
merge_new_entities(entities, find_entities(text, skip_bot_commands, skip_media_timestamps));
|
||||||
}
|
} else if (!skip_media_timestamps) {
|
||||||
if (!skip_media_timestamps) {
|
|
||||||
merge_new_entities(entities, find_media_timestamp_entities(text));
|
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)) {
|
if (!clean_input_string(message_text)) {
|
||||||
message_text.clear();
|
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)};
|
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);
|
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_mentions(Slice str);
|
||||||
vector<Slice> find_bot_commands(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_)) {
|
if (!clean_input_string(poll_results->solution_)) {
|
||||||
poll_results->solution_.clear();
|
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)};
|
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_)) {
|
if (!check_utf8(request.text_)) {
|
||||||
return make_error(400, "Text must be encoded in UTF-8");
|
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));
|
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_)) {
|
if (!clean_input_string(terms->text_)) {
|
||||||
terms->text_.clear();
|
terms->text_.clear();
|
||||||
}
|
}
|
||||||
entities = find_entities(terms->text_, true);
|
entities = find_entities(terms->text_, true, true);
|
||||||
}
|
}
|
||||||
if (terms->text_.empty()) {
|
if (terms->text_.empty()) {
|
||||||
id_.clear();
|
id_.clear();
|
||||||
|
@ -1185,7 +1185,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
|
|||||||
|
|
||||||
FormattedText description;
|
FormattedText description;
|
||||||
description.text = web_page->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);
|
auto r_url = parse_url(web_page->display_url);
|
||||||
if (r_url.is_ok()) {
|
if (r_url.is_ok()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user