Skip bot command entities if needed.

This commit is contained in:
levlam 2021-07-22 05:39:16 +03:00
parent 0e244ea67c
commit e0c9efc26b
15 changed files with 91 additions and 54 deletions

View File

@ -91,9 +91,9 @@ const FormattedText &Game::get_text() const {
return text_; return text_;
} }
tl_object_ptr<td_api::game> Game::get_game_object(Td *td) const { tl_object_ptr<td_api::game> Game::get_game_object(Td *td, bool skip_bot_commands) const {
return make_tl_object<td_api::game>( return make_tl_object<td_api::game>(
id_, short_name_, title_, get_formatted_text_object(text_), description_, id_, short_name_, title_, get_formatted_text_object(text_, skip_bot_commands), description_,
get_photo_object(td->file_manager_.get(), photo_), get_photo_object(td->file_manager_.get(), photo_),
td->animations_manager_->get_animation_object(animation_file_id_, "get_game_object")); td->animations_manager_->get_animation_object(animation_file_id_, "get_game_object"));
} }

View File

@ -63,7 +63,7 @@ class Game {
const FormattedText &get_text() const; const FormattedText &get_text() const;
tl_object_ptr<td_api::game> get_game_object(Td *td) const; tl_object_ptr<td_api::game> get_game_object(Td *td, bool skip_bot_commands) const;
bool has_input_media() const; bool has_input_media() const;

View File

@ -1277,7 +1277,7 @@ void InlineQueriesManager::on_get_inline_query_results(DialogId dialog_id, UserI
std::move(result->document_), DialogId()); std::move(result->document_), DialogId());
game->id_ = std::move(result->id_); game->id_ = std::move(result->id_);
game->game_ = inline_game.get_game_object(td_); game->game_ = inline_game.get_game_object(td_, true);
if (!register_inline_message_content(results->query_id_, game->id_, FileId(), if (!register_inline_message_content(results->query_id_, game->id_, FileId(),
std::move(result->send_message_), td_api::inputMessageGame::ID, std::move(result->send_message_), td_api::inputMessageGame::ID,

View File

@ -54,7 +54,7 @@ Result<InputMessageText> process_input_message_text(const ContactsManager *conta
} }
td_api::object_ptr<td_api::inputMessageText> get_input_message_text_object(const InputMessageText &input_message_text) { td_api::object_ptr<td_api::inputMessageText> get_input_message_text_object(const InputMessageText &input_message_text) {
return td_api::make_object<td_api::inputMessageText>(get_formatted_text_object(input_message_text.text), return td_api::make_object<td_api::inputMessageText>(get_formatted_text_object(input_message_text.text, false),
input_message_text.disable_web_page_preview, input_message_text.disable_web_page_preview,
input_message_text.clear_draft); input_message_text.clear_draft);
} }

View File

@ -191,7 +191,8 @@ class LinkManager::InternalLinkMessageDraft final : public InternalLink {
bool contains_link_ = false; bool contains_link_ = false;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final { td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypeMessageDraft>(get_formatted_text_object(text_), contains_link_); return td_api::make_object<td_api::internalLinkTypeMessageDraft>(get_formatted_text_object(text_, true),
contains_link_);
} }
public: public:

View File

@ -2901,9 +2901,9 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
if (old_->text.text != new_->text.text) { if (old_->text.text != new_->text.text) {
if (need_message_changed_warning && need_message_text_changed_warning(old_, new_)) { if (need_message_changed_warning && need_message_text_changed_warning(old_, new_)) {
LOG(ERROR) << "Message text has changed from " LOG(ERROR) << "Message text has changed from "
<< to_string(get_message_content_object(old_content, td, dialog_id, -1, false)) << to_string(get_message_content_object(old_content, td, dialog_id, -1, false, false))
<< ". New content is " << ". New content is "
<< to_string(get_message_content_object(new_content, td, dialog_id, -1, false)); << to_string(get_message_content_object(new_content, td, dialog_id, -1, false, false));
} }
need_update = true; need_update = true;
} }
@ -2913,9 +2913,9 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
old_->text.entities.size() <= MAX_CUSTOM_ENTITIES_COUNT && old_->text.entities.size() <= MAX_CUSTOM_ENTITIES_COUNT &&
need_message_entities_changed_warning(old_->text.entities, new_->text.entities)) { need_message_entities_changed_warning(old_->text.entities, new_->text.entities)) {
LOG(WARNING) << "Entities has changed from " LOG(WARNING) << "Entities has changed from "
<< to_string(get_message_content_object(old_content, td, dialog_id, -1, false)) << to_string(get_message_content_object(old_content, td, dialog_id, -1, false, false))
<< ". New content is " << ". New content is "
<< to_string(get_message_content_object(new_content, td, dialog_id, -1, false)); << to_string(get_message_content_object(new_content, td, dialog_id, -1, false, false));
} }
need_update = true; need_update = true;
} }
@ -4634,19 +4634,19 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td, tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td,
DialogId dialog_id, int32 message_date, DialogId dialog_id, int32 message_date,
bool is_content_secret) { bool is_content_secret, bool skip_bot_commands) {
CHECK(content != nullptr); CHECK(content != nullptr);
switch (content->get_type()) { switch (content->get_type()) {
case MessageContentType::Animation: { case MessageContentType::Animation: {
const MessageAnimation *m = static_cast<const MessageAnimation *>(content); const MessageAnimation *m = static_cast<const MessageAnimation *>(content);
return make_tl_object<td_api::messageAnimation>( return make_tl_object<td_api::messageAnimation>(
td->animations_manager_->get_animation_object(m->file_id, "get_message_content_object"), td->animations_manager_->get_animation_object(m->file_id, "get_message_content_object"),
get_formatted_text_object(m->caption), is_content_secret); get_formatted_text_object(m->caption, skip_bot_commands), is_content_secret);
} }
case MessageContentType::Audio: { case MessageContentType::Audio: {
const MessageAudio *m = static_cast<const MessageAudio *>(content); const MessageAudio *m = static_cast<const MessageAudio *>(content);
return make_tl_object<td_api::messageAudio>(td->audios_manager_->get_audio_object(m->file_id), return make_tl_object<td_api::messageAudio>(td->audios_manager_->get_audio_object(m->file_id),
get_formatted_text_object(m->caption)); get_formatted_text_object(m->caption, skip_bot_commands));
} }
case MessageContentType::Contact: { case MessageContentType::Contact: {
const MessageContact *m = static_cast<const MessageContact *>(content); const MessageContact *m = static_cast<const MessageContact *>(content);
@ -4656,11 +4656,11 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
const MessageDocument *m = static_cast<const MessageDocument *>(content); const MessageDocument *m = static_cast<const MessageDocument *>(content);
return make_tl_object<td_api::messageDocument>( return make_tl_object<td_api::messageDocument>(
td->documents_manager_->get_document_object(m->file_id, PhotoFormat::Jpeg), td->documents_manager_->get_document_object(m->file_id, PhotoFormat::Jpeg),
get_formatted_text_object(m->caption)); get_formatted_text_object(m->caption, skip_bot_commands));
} }
case MessageContentType::Game: { case MessageContentType::Game: {
const MessageGame *m = static_cast<const MessageGame *>(content); const MessageGame *m = static_cast<const MessageGame *>(content);
return make_tl_object<td_api::messageGame>(m->game.get_game_object(td)); return make_tl_object<td_api::messageGame>(m->game.get_game_object(td, skip_bot_commands));
} }
case MessageContentType::Invoice: { case MessageContentType::Invoice: {
const MessageInvoice *m = static_cast<const MessageInvoice *>(content); const MessageInvoice *m = static_cast<const MessageInvoice *>(content);
@ -4682,7 +4682,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::Photo: { case MessageContentType::Photo: {
const MessagePhoto *m = static_cast<const MessagePhoto *>(content); const MessagePhoto *m = static_cast<const MessagePhoto *>(content);
return make_tl_object<td_api::messagePhoto>(get_photo_object(td->file_manager_.get(), m->photo), return make_tl_object<td_api::messagePhoto>(get_photo_object(td->file_manager_.get(), m->photo),
get_formatted_text_object(m->caption), is_content_secret); get_formatted_text_object(m->caption, skip_bot_commands),
is_content_secret);
} }
case MessageContentType::Sticker: { case MessageContentType::Sticker: {
const MessageSticker *m = static_cast<const MessageSticker *>(content); const MessageSticker *m = static_cast<const MessageSticker *>(content);
@ -4690,7 +4691,7 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
} }
case MessageContentType::Text: { case MessageContentType::Text: {
const MessageText *m = static_cast<const MessageText *>(content); const MessageText *m = static_cast<const MessageText *>(content);
return make_tl_object<td_api::messageText>(get_formatted_text_object(m->text), return make_tl_object<td_api::messageText>(get_formatted_text_object(m->text, skip_bot_commands),
td->web_pages_manager_->get_web_page_object(m->web_page_id)); td->web_pages_manager_->get_web_page_object(m->web_page_id));
} }
case MessageContentType::Unsupported: case MessageContentType::Unsupported:
@ -4702,7 +4703,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::Video: { case MessageContentType::Video: {
const MessageVideo *m = static_cast<const MessageVideo *>(content); const MessageVideo *m = static_cast<const MessageVideo *>(content);
return make_tl_object<td_api::messageVideo>(td->videos_manager_->get_video_object(m->file_id), return make_tl_object<td_api::messageVideo>(td->videos_manager_->get_video_object(m->file_id),
get_formatted_text_object(m->caption), is_content_secret); get_formatted_text_object(m->caption, skip_bot_commands),
is_content_secret);
} }
case MessageContentType::VideoNote: { case MessageContentType::VideoNote: {
const MessageVideoNote *m = static_cast<const MessageVideoNote *>(content); const MessageVideoNote *m = static_cast<const MessageVideoNote *>(content);
@ -4712,7 +4714,8 @@ tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageCo
case MessageContentType::VoiceNote: { case MessageContentType::VoiceNote: {
const MessageVoiceNote *m = static_cast<const MessageVoiceNote *>(content); const MessageVoiceNote *m = static_cast<const MessageVoiceNote *>(content);
return make_tl_object<td_api::messageVoiceNote>(td->voice_notes_manager_->get_voice_note_object(m->file_id), return make_tl_object<td_api::messageVoiceNote>(td->voice_notes_manager_->get_voice_note_object(m->file_id),
get_formatted_text_object(m->caption), m->is_listened); get_formatted_text_object(m->caption, skip_bot_commands),
m->is_listened);
} }
case MessageContentType::ChatCreate: { case MessageContentType::ChatCreate: {
const MessageChatCreate *m = static_cast<const MessageChatCreate *>(content); const MessageChatCreate *m = static_cast<const MessageChatCreate *>(content);

View File

@ -195,7 +195,7 @@ unique_ptr<MessageContent> get_action_message_content(Td *td, tl_object_ptr<tele
tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td, tl_object_ptr<td_api::MessageContent> get_message_content_object(const MessageContent *content, Td *td,
DialogId dialog_id, int32 message_date, DialogId dialog_id, int32 message_date,
bool is_content_secret); bool is_content_secret, bool skip_bot_commands);
const FormattedText *get_message_content_text(const MessageContent *content); const FormattedText *get_message_content_text(const MessageContent *content);

View File

@ -140,11 +140,15 @@ tl_object_ptr<td_api::textEntity> MessageEntity::get_text_entity_object() const
return make_tl_object<td_api::textEntity>(offset, length, get_text_entity_type_object()); return make_tl_object<td_api::textEntity>(offset, length, get_text_entity_type_object());
} }
vector<tl_object_ptr<td_api::textEntity>> get_text_entities_object(const vector<MessageEntity> &entities) { vector<tl_object_ptr<td_api::textEntity>> get_text_entities_object(const vector<MessageEntity> &entities,
bool skip_bot_commands) {
vector<tl_object_ptr<td_api::textEntity>> result; vector<tl_object_ptr<td_api::textEntity>> result;
result.reserve(entities.size()); result.reserve(entities.size());
for (auto &entity : entities) { for (auto &entity : entities) {
if (skip_bot_commands && entity.type == MessageEntity::Type::BotCommand) {
continue;
}
auto entity_object = entity.get_text_entity_object(); auto entity_object = entity.get_text_entity_object();
if (entity_object->type_ != nullptr) { if (entity_object->type_ != nullptr) {
result.push_back(std::move(entity_object)); result.push_back(std::move(entity_object));
@ -158,8 +162,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const FormattedText &te
return string_builder << '"' << text.text << "\" with entities " << text.entities; return string_builder << '"' << text.text << "\" with entities " << text.entities;
} }
td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const FormattedText &text) { td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const FormattedText &text, bool skip_bot_commands) {
return td_api::make_object<td_api::formattedText>(text.text, get_text_entities_object(text.entities)); return td_api::make_object<td_api::formattedText>(text.text,
get_text_entities_object(text.entities, skip_bot_commands));
} }
static bool is_word_character(uint32 code) { static bool is_word_character(uint32 code) {

View File

@ -131,9 +131,10 @@ Result<vector<MessageEntity>> get_message_entities(const ContactsManager *contac
vector<tl_object_ptr<td_api::textEntity>> &&input_entities, vector<tl_object_ptr<td_api::textEntity>> &&input_entities,
bool allow_all = false); bool allow_all = false);
vector<tl_object_ptr<td_api::textEntity>> get_text_entities_object(const vector<MessageEntity> &entities); vector<tl_object_ptr<td_api::textEntity>> get_text_entities_object(const vector<MessageEntity> &entities,
bool skip_bot_commands);
td_api::object_ptr<td_api::formattedText> get_formatted_text_object(const FormattedText &text); 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);

View File

@ -6534,10 +6534,10 @@ void MessagesManager::on_update_service_notification(tl_object_ptr<telegram_api:
bool is_content_secret = is_secret_message_content(ttl, content->get_type()); bool is_content_secret = is_secret_message_content(ttl, content->get_type());
if ((update->flags_ & telegram_api::updateServiceNotification::POPUP_MASK) != 0) { if ((update->flags_ & telegram_api::updateServiceNotification::POPUP_MASK) != 0) {
send_closure( send_closure(G()->td(), &Td::send_update,
G()->td(), &Td::send_update,
td_api::make_object<td_api::updateServiceNotification>( td_api::make_object<td_api::updateServiceNotification>(
update->type_, get_message_content_object(content.get(), td_, owner_dialog_id, date, is_content_secret))); update->type_,
get_message_content_object(content.get(), td_, owner_dialog_id, date, is_content_secret, true)));
} }
if (has_date && is_user) { if (has_date && is_user) {
Dialog *d = get_service_notifications_dialog(); Dialog *d = get_service_notifications_dialog();
@ -6937,14 +6937,28 @@ void MessagesManager::on_update_some_live_location_viewed(Promise<Unit> &&promis
promise.set_value(Unit()); promise.set_value(Unit());
} }
bool MessagesManager::need_skip_bot_commands(DialogId dialog_id, const Message *m) const {
if (td_->auth_manager_->is_bot()) {
return false;
}
if (m != nullptr && m->message_id.is_scheduled()) {
return true;
}
auto d = get_dialog(dialog_id);
CHECK(d != nullptr);
return (d->is_has_bots_inited && !d->has_bots) || is_broadcast_channel(dialog_id);
}
void MessagesManager::on_external_update_message_content(FullMessageId full_message_id) { void MessagesManager::on_external_update_message_content(FullMessageId full_message_id) {
const Dialog *d = get_dialog(full_message_id.get_dialog_id()); const Dialog *d = get_dialog(full_message_id.get_dialog_id());
CHECK(d != nullptr); CHECK(d != nullptr);
const Message *m = get_message(d, full_message_id.get_message_id()); const Message *m = get_message(d, full_message_id.get_message_id());
CHECK(m != nullptr); CHECK(m != nullptr);
auto live_location_date = m->is_failed_to_send ? 0 : m->date; auto live_location_date = m->is_failed_to_send ? 0 : m->date;
send_update_message_content(full_message_id.get_dialog_id(), m->message_id, m->content.get(), live_location_date, send_update_message_content(d->dialog_id, m->message_id, m->content.get(), live_location_date, m->is_content_secret,
m->is_content_secret, "on_external_update_message_content"); need_skip_bot_commands(d->dialog_id, m), "on_external_update_message_content");
if (m->message_id == d->last_message_id) { if (m->message_id == d->last_message_id) {
send_update_chat_last_message_impl(d, "on_external_update_message_content"); send_update_chat_last_message_impl(d, "on_external_update_message_content");
} }
@ -12099,7 +12113,7 @@ void MessagesManager::on_message_ttl_expired(Dialog *d, Message *m) {
remove_message_file_sources(d->dialog_id, m); remove_message_file_sources(d->dialog_id, m);
on_message_ttl_expired_impl(d, m); on_message_ttl_expired_impl(d, m);
register_message_content(td_, m->content.get(), {d->dialog_id, m->message_id}, "on_message_ttl_expired"); register_message_content(td_, m->content.get(), {d->dialog_id, m->message_id}, "on_message_ttl_expired");
send_update_message_content(d->dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret, send_update_message_content(d->dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret, true,
"on_message_ttl_expired"); "on_message_ttl_expired");
} }
@ -13477,7 +13491,7 @@ std::pair<DialogId, unique_ptr<MessagesManager::Message>> MessagesManager::creat
LOG(ERROR) << "Receive media group identifier " << message_info.media_album_id << " in " << message_id << " from " LOG(ERROR) << "Receive media group identifier " << message_info.media_album_id << " in " << message_id << " from "
<< dialog_id << " with content " << dialog_id << " with content "
<< oneline(to_string(get_message_content_object(message->content.get(), td_, dialog_id, message->date, << oneline(to_string(get_message_content_object(message->content.get(), td_, dialog_id, message->date,
is_content_secret))); is_content_secret, false)));
} else { } else {
message->media_album_id = message_info.media_album_id; message->media_album_id = message_info.media_album_id;
} }
@ -14153,12 +14167,12 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
} }
auto full_message_id = it->second; auto full_message_id = it->second;
auto dialog_id = full_message_id.get_dialog_id();
auto m = get_message_force(full_message_id, "on_update_sent_text_message"); auto m = get_message_force(full_message_id, "on_update_sent_text_message");
if (m == nullptr) { if (m == nullptr) {
// message has already been deleted // message has already been deleted
return; return;
} }
auto dialog_id = full_message_id.get_dialog_id();
full_message_id = FullMessageId(dialog_id, m->message_id); full_message_id = FullMessageId(dialog_id, m->message_id);
if (m->content->get_type() != MessageContentType::Text) { if (m->content->get_type() != MessageContentType::Text) {
@ -14191,7 +14205,7 @@ void MessagesManager::on_update_sent_text_message(int64 random_id,
} }
if (need_update) { if (need_update) {
send_update_message_content(dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret, send_update_message_content(dialog_id, m->message_id, m->content.get(), m->date, m->is_content_secret,
"on_update_sent_text_message"); need_skip_bot_commands(dialog_id, m), "on_update_sent_text_message");
} }
} }
@ -22708,6 +22722,7 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
auto date = is_scheduled ? 0 : m->date; auto date = is_scheduled ? 0 : m->date;
auto edit_date = m->hide_edit_date ? 0 : m->edit_date; auto edit_date = m->hide_edit_date ? 0 : m->edit_date;
auto is_pinned = for_event_log || is_scheduled ? false : m->is_pinned; auto is_pinned = for_event_log || is_scheduled ? false : m->is_pinned;
bool skip_bot_commands = for_event_log || need_skip_bot_commands(dialog_id, m);
return make_tl_object<td_api::message>( return make_tl_object<td_api::message>(
m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id), dialog_id.get(), m->message_id.get(), get_message_sender_object_const(m->sender_user_id, m->sender_dialog_id), dialog_id.get(),
std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited, can_be_forwarded, std::move(sending_state), std::move(scheduling_state), is_outgoing, is_pinned, can_be_edited, can_be_forwarded,
@ -22716,7 +22731,8 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
get_message_interaction_info_object(dialog_id, m), reply_in_dialog_id.get(), reply_to_message_id, get_message_interaction_info_object(dialog_id, m), reply_in_dialog_id.get(), reply_to_message_id,
top_thread_message_id, ttl, ttl_expires_in, via_bot_user_id, m->author_signature, media_album_id, top_thread_message_id, ttl, ttl_expires_in, via_bot_user_id, m->author_signature, media_album_id,
get_restriction_reason_description(m->restriction_reasons), get_restriction_reason_description(m->restriction_reasons),
get_message_content_object(m->content.get(), td_, dialog_id, live_location_date, m->is_content_secret), get_message_content_object(m->content.get(), td_, dialog_id, live_location_date, m->is_content_secret,
skip_bot_commands),
get_reply_markup_object(m->reply_markup)); get_reply_markup_object(m->reply_markup));
} }
@ -23905,8 +23921,8 @@ void MessagesManager::do_send_message_group(int64 media_album_id) {
<< file_view.has_alive_remote_location() << " " << file_view.has_active_upload_remote_location() << " " << file_view.has_alive_remote_location() << " " << file_view.has_active_upload_remote_location() << " "
<< file_view.has_active_download_remote_location() << " " << file_view.is_encrypted() << " " << is_web << file_view.has_active_download_remote_location() << " " << file_view.is_encrypted() << " " << is_web
<< " " << file_view.has_url() << " " << " " << file_view.has_url() << " "
<< to_string( << to_string(get_message_content_object(m->content.get(), td_, dialog_id, m->date,
get_message_content_object(m->content.get(), td_, dialog_id, m->date, m->is_content_secret)); m->is_content_secret, false));
} }
auto entities = get_input_message_entities(td_->contacts_manager_.get(), caption, "do_send_message_group"); auto entities = get_input_message_entities(td_->contacts_manager_.get(), caption, "do_send_message_group");
int32 input_single_media_flags = 0; int32 input_single_media_flags = 0;
@ -27971,11 +27987,13 @@ void MessagesManager::send_update_message_send_succeeded(Dialog *d, MessageId ol
void MessagesManager::send_update_message_content(DialogId dialog_id, MessageId message_id, void MessagesManager::send_update_message_content(DialogId dialog_id, MessageId message_id,
const MessageContent *content, int32 message_date, const MessageContent *content, int32 message_date,
bool is_content_secret, const char *source) const { bool is_content_secret, bool skip_bot_commands,
const char *source) const {
LOG(INFO) << "Send updateMessageContent for " << message_id << " in " << dialog_id << " from " << source; LOG(INFO) << "Send updateMessageContent for " << message_id << " in " << dialog_id << " from " << source;
LOG_CHECK(have_dialog(dialog_id)) << "Send updateMessageContent in unknown " << dialog_id << " from " << source LOG_CHECK(have_dialog(dialog_id)) << "Send updateMessageContent in unknown " << dialog_id << " from " << source
<< " with load count " << loaded_dialogs_.count(dialog_id); << " with load count " << loaded_dialogs_.count(dialog_id);
auto content_object = get_message_content_object(content, td_, dialog_id, message_date, is_content_secret); auto content_object =
get_message_content_object(content, td_, dialog_id, message_date, is_content_secret, skip_bot_commands);
send_closure( send_closure(
G()->td(), &Td::send_update, G()->td(), &Td::send_update,
td_api::make_object<td_api::updateMessageContent>(dialog_id.get(), message_id.get(), std::move(content_object))); td_api::make_object<td_api::updateMessageContent>(dialog_id.get(), message_id.get(), std::move(content_object)));
@ -28491,7 +28509,8 @@ FullMessageId MessagesManager::on_send_message_success(int64 random_id, MessageI
if (merge_message_content_file_id(td_, sent_message->content.get(), new_file_id)) { if (merge_message_content_file_id(td_, sent_message->content.get(), new_file_id)) {
send_update_message_content(dialog_id, old_message_id, sent_message->content.get(), sent_message->date, send_update_message_content(dialog_id, old_message_id, sent_message->content.get(), sent_message->date,
sent_message->is_content_secret, source); sent_message->is_content_secret, need_skip_bot_commands(dialog_id, sent_message.get()),
source);
} }
set_message_id(sent_message, new_message_id); set_message_id(sent_message, new_message_id);
@ -30293,8 +30312,8 @@ void MessagesManager::on_send_dialog_action_timeout(DialogId dialog_id) {
auto file_id = get_message_content_upload_file_id(m->content.get()); auto file_id = get_message_content_upload_file_id(m->content.get());
if (!file_id.is_valid()) { if (!file_id.is_valid()) {
LOG(ERROR) << "Have no file in " LOG(ERROR) << "Have no file in "
<< to_string( << to_string(get_message_content_object(m->content.get(), td_, dialog_id, m->date, m->is_content_secret,
get_message_content_object(m->content.get(), td_, dialog_id, m->date, m->is_content_secret)); false));
return; return;
} }
auto file_view = td_->file_manager_->get_file_view(file_id); auto file_view = td_->file_manager_->get_file_view(file_id);
@ -33437,7 +33456,8 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me
if (need_update && need_send_update_message_content) { if (need_update && need_send_update_message_content) {
send_update_message_content(dialog_id, old_message->message_id, old_content.get(), old_message->date, send_update_message_content(dialog_id, old_message->message_id, old_content.get(), old_message->date,
old_message->is_content_secret, "update_message_content"); old_message->is_content_secret, need_skip_bot_commands(dialog_id, old_message),
"update_message_content");
} }
return is_content_changed || need_update; return is_content_changed || need_update;
} }
@ -33613,7 +33633,8 @@ MessagesManager::Dialog *MessagesManager::add_new_dialog(unique_ptr<Dialog> &&d,
d->last_read_inbox_message_id = d->last_new_message_id; d->last_read_inbox_message_id = d->last_new_message_id;
d->last_read_outbox_message_id = d->last_new_message_id; d->last_read_outbox_message_id = d->last_new_message_id;
} }
d->has_bots = td_->contacts_manager_->is_user_bot(dialog_id.get_user_id()); d->has_bots = dialog_id.get_user_id() != ContactsManager::get_replies_bot_user_id() &&
td_->contacts_manager_->is_user_bot(dialog_id.get_user_id());
d->is_has_bots_inited = true; d->is_has_bots_inited = true;
break; break;
case DialogType::Chat: case DialogType::Chat:

View File

@ -2183,10 +2183,13 @@ class MessagesManager final : public Actor {
void remove_message_dialog_notifications(Dialog *d, MessageId max_message_id, bool from_mentions, const char *source); void remove_message_dialog_notifications(Dialog *d, MessageId max_message_id, bool from_mentions, const char *source);
bool need_skip_bot_commands(DialogId dialog_id, const Message *m) const;
void send_update_message_send_succeeded(Dialog *d, MessageId old_message_id, const Message *m) const; void send_update_message_send_succeeded(Dialog *d, MessageId old_message_id, const Message *m) const;
void send_update_message_content(DialogId dialog_id, MessageId message_id, const MessageContent *content, void send_update_message_content(DialogId dialog_id, MessageId message_id, const MessageContent *content,
int32 message_date, bool is_content_secret, const char *source) const; int32 message_date, bool is_content_secret, bool skip_bot_commands,
const char *source) const;
void send_update_message_edited(DialogId dialog_id, const Message *m); void send_update_message_edited(DialogId dialog_id, const Message *m);

View File

@ -557,7 +557,8 @@ td_api::object_ptr<td_api::poll> PollManager::get_poll_object(PollId poll_id, co
if (poll->is_quiz) { if (poll->is_quiz) {
auto correct_option_id = is_local_poll_id(poll_id) ? -1 : poll->correct_option_id; auto correct_option_id = is_local_poll_id(poll_id) ? -1 : poll->correct_option_id;
poll_type = td_api::make_object<td_api::pollTypeQuiz>( poll_type = td_api::make_object<td_api::pollTypeQuiz>(
correct_option_id, get_formatted_text_object(is_local_poll_id(poll_id) ? FormattedText() : poll->explanation)); correct_option_id,
get_formatted_text_object(is_local_poll_id(poll_id) ? FormattedText() : poll->explanation, true));
} else { } else {
poll_type = td_api::make_object<td_api::pollTypeRegular>(poll->allow_multiple_answers); poll_type = td_api::make_object<td_api::pollTypeRegular>(poll->allow_multiple_answers);
} }

View File

@ -485,7 +485,7 @@ class GetDeepLinkInfoQuery final : public Td::ResultHandler {
} }
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(
td_api::make_object<td_api::deepLinkInfo>(get_formatted_text_object(text), need_update)); td_api::make_object<td_api::deepLinkInfo>(get_formatted_text_object(text, true), need_update));
} }
default: default:
UNREACHABLE(); UNREACHABLE();
@ -8360,7 +8360,7 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getTextEn
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);
return make_tl_object<td_api::textEntities>(get_text_entities_object(text_entities)); return make_tl_object<td_api::textEntities>(get_text_entities_object(text_entities, false));
} }
td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::parseTextEntities &request) { td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::parseTextEntities &request) {
@ -8394,7 +8394,8 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::parseTextEntiti
return make_error(400, PSLICE() << "Can't parse entities: " << r_entities.error().message()); return make_error(400, PSLICE() << "Can't parse entities: " << r_entities.error().message());
} }
return make_tl_object<td_api::formattedText>(std::move(request.text_), get_text_entities_object(r_entities.ok())); return make_tl_object<td_api::formattedText>(std::move(request.text_),
get_text_entities_object(r_entities.ok(), false));
} }
td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::parseMarkdown &request) { td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::parseMarkdown &request) {
@ -8414,7 +8415,7 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::parseMarkdown &
auto parsed_text = parse_markdown_v3({std::move(request.text_->text_), std::move(entities)}); auto parsed_text = parse_markdown_v3({std::move(request.text_->text_), std::move(entities)});
fix_formatted_text(parsed_text.text, parsed_text.entities, true, true, true, true).ensure(); fix_formatted_text(parsed_text.text, parsed_text.entities, true, true, true, true).ensure();
return get_formatted_text_object(parsed_text); return get_formatted_text_object(parsed_text, true);
} }
td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::getMarkdownText &request) { td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::getMarkdownText &request) {
@ -8432,7 +8433,7 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::getMarkdownText
return make_error(400, status.error().message()); return make_error(400, status.error().message());
} }
return get_formatted_text_object(get_markdown_v3({std::move(request.text_->text_), std::move(entities)})); return get_formatted_text_object(get_markdown_v3({std::move(request.text_->text_), std::move(entities)}), true);
} }
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getFileMimeType &request) { td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getFileMimeType &request) {

View File

@ -42,7 +42,8 @@ class TermsOfService {
return nullptr; return nullptr;
} }
return td_api::make_object<td_api::termsOfService>(get_formatted_text_object(text_), min_user_age_, show_popup_); return td_api::make_object<td_api::termsOfService>(get_formatted_text_object(text_, true), min_user_age_,
show_popup_);
} }
template <class StorerT> template <class StorerT>

View File

@ -1256,7 +1256,7 @@ tl_object_ptr<td_api::webPage> WebPagesManager::get_web_page_object(WebPageId we
return make_tl_object<td_api::webPage>( return make_tl_object<td_api::webPage>(
web_page->url, web_page->display_url, web_page->type, web_page->site_name, web_page->title, web_page->url, web_page->display_url, web_page->type, web_page->site_name, web_page->title,
get_formatted_text_object(description), get_photo_object(td_->file_manager_.get(), web_page->photo), get_formatted_text_object(description, true), get_photo_object(td_->file_manager_.get(), web_page->photo),
web_page->embed_url, web_page->embed_type, web_page->embed_dimensions.width, web_page->embed_dimensions.height, web_page->embed_url, web_page->embed_type, web_page->embed_dimensions.width, web_page->embed_dimensions.height,
web_page->duration, web_page->author, web_page->duration, web_page->author,
web_page->document.type == Document::Type::Animation web_page->document.type == Document::Type::Animation