Find entities in MESSAGE_ANNOUNCEMENT.

GitOrigin-RevId: 3ca4500dea9ba0f3561470416db21bc1cc42616a
This commit is contained in:
levlam 2019-03-26 01:24:23 +03:00
parent 54aaea0e13
commit 6cebe30382
7 changed files with 18 additions and 20 deletions

View File

@ -1403,7 +1403,7 @@ InlineMessageContent create_inline_message_content(Td *td, FileId file_id,
auto input_message_media_auto = move_tl_object_as<telegram_api::botInlineMessageMediaAuto>(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<MessageAnimation>(file_id, std::move(caption));
} else if (allowed_media_content_id == td_api::inputMessageAudio::ID) {

View File

@ -2224,10 +2224,10 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &entities, bool al
}
FormattedText get_message_text(const ContactsManager *contacts_manager, string message_text,
vector<tl_object_ptr<telegram_api::MessageEntity>> &&server_entities, int32 send_date,
const char *source) {
vector<tl_object_ptr<telegram_api::MessageEntity>> &&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 \""

View File

@ -151,8 +151,8 @@ Status fix_formatted_text(string &text, vector<MessageEntity> &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<tl_object_ptr<telegram_api::MessageEntity>> &&server_entities, int32 send_date,
const char *source);
vector<tl_object_ptr<telegram_api::MessageEntity>> &&server_entities,
bool skip_new_entities, int32 send_date, const char *source);
td_api::object_ptr<td_api::formattedText> extract_input_caption(
tl_object_ptr<td_api::InputMessageContent> &input_message_content);

View File

@ -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<telegram_api::updateServiceNotification> &&update) {
void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&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*/);

View File

@ -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<telegram_api::updateServiceNotification> &&update);
void on_update_service_notification(tl_object_ptr<telegram_api::updateServiceNotification> &&update,
bool skip_new_entities);
void on_update_new_channel_message(tl_object_ptr<telegram_api::updateNewChannelMessage> &&update);

View File

@ -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>(
telegram_api::updateServiceNotification::INBOX_DATE_MASK, false, G()->unix_time(), string(),
announcement_message_text, nullptr, vector<telegram_api::object_ptr<telegram_api::MessageEntity>>());
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()) {

View File

@ -1458,7 +1458,7 @@ void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateReadHistoryOutb
void UpdatesManager::on_update(tl_object_ptr<telegram_api::updateServiceNotification> 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<telegram_api::updateReadChannelInbox> update, bool /*force_apply*/) {