From 6cebe30382caba231cdcd03c39da3653146896fe Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 26 Mar 2019 01:24:23 +0300 Subject: [PATCH] Find entities in MESSAGE_ANNOUNCEMENT. GitOrigin-RevId: 3ca4500dea9ba0f3561470416db21bc1cc42616a --- td/telegram/MessageContent.cpp | 2 +- td/telegram/MessageEntity.cpp | 6 +++--- td/telegram/MessageEntity.h | 4 ++-- td/telegram/MessagesManager.cpp | 15 ++++++++------- td/telegram/MessagesManager.h | 3 ++- td/telegram/NotificationManager.cpp | 6 +----- td/telegram/UpdatesManager.cpp | 2 +- 7 files changed, 18 insertions(+), 20 deletions(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 94170ecaa..7fd3b551e 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -1403,7 +1403,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id, auto input_message_media_auto = move_tl_object_as(inline_message); auto caption = get_message_text(td->contacts_manager_.get(), input_message_media_auto->message_, - std::move(input_message_media_auto->entities_), 0, "register_inline_message_content"); + std::move(input_message_media_auto->entities_), true, 0, "register_inline_message_content"); if (allowed_media_content_id == td_api::inputMessageAnimation::ID) { result.message_content = make_unique(file_id, std::move(caption)); } else if (allowed_media_content_id == td_api::inputMessageAudio::ID) { diff --git a/td/telegram/MessageEntity.cpp b/td/telegram/MessageEntity.cpp index c60a4d5b9..f464907c7 100644 --- a/td/telegram/MessageEntity.cpp +++ b/td/telegram/MessageEntity.cpp @@ -2224,10 +2224,10 @@ Status fix_formatted_text(string &text, vector &entities, bool al } FormattedText get_message_text(const ContactsManager *contacts_manager, string message_text, - vector> &&server_entities, int32 send_date, - const char *source) { + vector> &&server_entities, + bool skip_new_entities, int32 send_date, const char *source) { auto entities = get_message_entities(contacts_manager, std::move(server_entities), source); - auto status = fix_formatted_text(message_text, entities, true, true, true, false); + auto status = fix_formatted_text(message_text, entities, true, skip_new_entities, true, false); if (status.is_error()) { if (send_date == 0 || send_date > 1497000000) { // approximate fix date LOG(ERROR) << "Receive error " << status << " while parsing message from " << source << " with content \"" diff --git a/td/telegram/MessageEntity.h b/td/telegram/MessageEntity.h index b91d8f7fa..591ec65b1 100644 --- a/td/telegram/MessageEntity.h +++ b/td/telegram/MessageEntity.h @@ -151,8 +151,8 @@ Status fix_formatted_text(string &text, vector &entities, bool al bool skip_bot_commands, bool for_draft) TD_WARN_UNUSED_RESULT; FormattedText get_message_text(const ContactsManager *contacts_manager, string message_text, - vector> &&server_entities, int32 send_date, - const char *source); + vector> &&server_entities, + bool skip_new_entities, int32 send_date, const char *source); td_api::object_ptr extract_input_caption( tl_object_ptr &input_message_content); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 364a3ee47..1d485168c 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -4858,15 +4858,16 @@ MessagesManager::Dialog *MessagesManager::get_service_notifications_dialog() { return get_dialog(service_notifications_dialog_id); } -void MessagesManager::on_update_service_notification(tl_object_ptr &&update) { +void MessagesManager::on_update_service_notification(tl_object_ptr &&update, + bool skip_new_entities) { int32 ttl = 0; bool has_date = (update->flags_ & telegram_api::updateServiceNotification::INBOX_DATE_MASK) != 0; auto date = has_date ? update->inbox_date_ : G()->unix_time(); + auto message_text = + get_message_text(td_->contacts_manager_.get(), std::move(update->message_), std::move(update->entities_), + skip_new_entities, date, "on_update_service_notification"); auto content = get_message_content( - td_, - get_message_text(td_->contacts_manager_.get(), std::move(update->message_), std::move(update->entities_), date, - "on_update_service_notification"), - std::move(update->media_), + td_, std::move(message_text), std::move(update->media_), td_->auth_manager_->is_bot() ? DialogId() : get_service_notifications_dialog()->dialog_id, false, UserId(), &ttl); bool is_content_secret = is_secret_message_content(ttl, content->get_type()); if ((update->flags_ & telegram_api::updateServiceNotification::POPUP_MASK) != 0) { @@ -9664,7 +9665,7 @@ MessagesManager::MessageInfo MessagesManager::parse_telegram_api_message( message_info.content = get_message_content( td_, get_message_text(td_->contacts_manager_.get(), std::move(message->message_), std::move(message->entities_), - message_info.forward_header ? message_info.forward_header->date_ : message_info.date, + true, message_info.forward_header ? message_info.forward_header->date_ : message_info.date, "parse_telegram_api_message"), std::move(message->media_), message_info.dialog_id, is_content_read, message_info.via_bot_user_id, &message_info.ttl); @@ -10322,7 +10323,7 @@ void MessagesManager::on_update_sent_text_message(int64 random_id, const FormattedText *old_message_text = get_message_content_text(m->content.get()); CHECK(old_message_text != nullptr); FormattedText new_message_text = - get_message_text(td_->contacts_manager_.get(), old_message_text->text, std::move(entities), + get_message_text(td_->contacts_manager_.get(), old_message_text->text, std::move(entities), true, m->forward_info ? m->forward_info->date : m->date, "on_update_sent_text_message"); auto new_content = get_message_content(td_, std::move(new_message_text), std::move(message_media), dialog_id, true /*likely ignored*/, UserId() /*likely ignored*/, nullptr /*ignored*/); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 950bea06f..7acee3ede 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -280,7 +280,8 @@ class MessagesManager : public Actor { void on_update_dialog_pinned_message_id(DialogId dialog_id, MessageId pinned_message_id); - void on_update_service_notification(tl_object_ptr &&update); + void on_update_service_notification(tl_object_ptr &&update, + bool skip_new_entities); void on_update_new_channel_message(tl_object_ptr &&update); diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 89eb0c986..3910e0072 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2322,10 +2322,6 @@ Status NotificationManager::process_push_notification_payload(string payload) { if (!clean_input_string(loc_key)) { return Status::Error(PSLICE() << "Receive invalid loc_key " << format::escaped(loc_key)); } - if (!clean_input_string(announcement_message_text)) { - return Status::Error(PSLICE() << "Receive invalid announcement_message_text " - << format::escaped(announcement_message_text)); - } for (auto &loc_arg : loc_args) { if (!clean_input_string(loc_arg)) { return Status::Error(PSLICE() << "Receive invalid loc_arg " << format::escaped(loc_arg)); @@ -2340,7 +2336,7 @@ Status NotificationManager::process_push_notification_payload(string payload) { auto update = telegram_api::make_object( telegram_api::updateServiceNotification::INBOX_DATE_MASK, false, G()->unix_time(), string(), announcement_message_text, nullptr, vector>()); - send_closure(G()->messages_manager(), &MessagesManager::on_update_service_notification, std::move(update)); + send_closure(G()->messages_manager(), &MessagesManager::on_update_service_notification, std::move(update), false); return Status::OK(); } if (!announcement_message_text.empty()) { diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index de9dae5c7..40b8b3093 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -1458,7 +1458,7 @@ void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) { CHECK(update != nullptr); - td_->messages_manager_->on_update_service_notification(std::move(update)); + td_->messages_manager_->on_update_service_notification(std::move(update), true); } void UpdatesManager::on_update(tl_object_ptr update, bool /*force_apply*/) {