From 47611d582e005f3680ad79ec4d75c27bfcf856cc Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 13 Apr 2018 19:10:24 +0300 Subject: [PATCH] Fix add_dialog_dependencies. GitOrigin-RevId: 070c00847699580432d29ee7ba3c4ff38c468a66 --- td/telegram/MessagesManager.cpp | 31 ++++++++++++++----------------- td/telegram/MessagesManager.h | 6 ++++-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index a70215be6..eb1d90ed3 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -15663,6 +15663,14 @@ bool MessagesManager::is_message_auto_read(DialogId dialog_id, bool is_outgoing, } } +void MessagesManager::add_formatted_text_dependencies(Dependencies &dependencies, const FormattedText &text) { + for (auto &entity : text.entities) { + if (entity.user_id.is_valid()) { + dependencies.user_ids.insert(entity.user_id); + } + } +} + void MessagesManager::add_message_dependencies(Dependencies &dependencies, DialogId dialog_id, const Message *m) { dependencies.user_ids.insert(m->sender_user_id); dependencies.user_ids.insert(m->via_bot_user_id); @@ -15679,11 +15687,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, Dialo switch (m->content->get_id()) { case MessageText::ID: { auto content = static_cast(m->content.get()); - for (auto &entity : content->text.entities) { - if (entity.user_id.is_valid()) { - dependencies.user_ids.insert(entity.user_id); - } - } + add_formatted_text_dependencies(dependencies, content->text); dependencies.web_page_ids.insert(content->web_page_id); break; } @@ -15701,12 +15705,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, Dialo case MessageGame::ID: { auto content = static_cast(m->content.get()); dependencies.user_ids.insert(content->game.get_bot_user_id()); - const FormattedText &formatted_text = content->game.get_message_text(); - for (auto &entity : formatted_text.entities) { - if (entity.user_id.is_valid()) { - dependencies.user_ids.insert(entity.user_id); - } - } + add_formatted_text_dependencies(dependencies, content->game.get_message_text()); break; } case MessageInvoice::ID: @@ -15796,12 +15795,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, Dialo UNREACHABLE(); break; } - auto caption = get_message_content_caption(m->content.get()); - for (auto &entity : caption.entities) { - if (entity.user_id.is_valid()) { - dependencies.user_ids.insert(entity.user_id); - } - } + add_formatted_text_dependencies(dependencies, get_message_content_caption(m->content.get())); } void MessagesManager::add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id) { @@ -24102,6 +24096,9 @@ unique_ptr MessagesManager::parse_dialog(DialogId dialo if (d->messages != nullptr) { add_message_dependencies(dependencies, dialog_id, d->messages.get()); } + if (d->draft_message != nullptr) { + add_formatted_text_dependencies(dependencies, d->draft_message->input_message_text.text); + } resolve_dependencies_force(dependencies); return d; diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 23b69c93f..a9577e34d 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -2581,9 +2581,11 @@ class MessagesManager : public Actor { static void dump_debug_message_op(const Dialog *d, int priority = 0); - void add_message_dependencies(Dependencies &dependencies, DialogId dialog_id, const Message *m); + static void add_formatted_text_dependencies(Dependencies &dependencies, const FormattedText &text); - void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id); + static void add_message_dependencies(Dependencies &dependencies, DialogId dialog_id, const Message *m); + + static void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id); void resolve_dependencies_force(const Dependencies &dependencies);