From c36d45153c95e1cfc1eb069fc7ed141af3530d81 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 27 Jan 2020 03:09:05 +0300 Subject: [PATCH] Move resolve_dependencies to Dependencies.cpp. GitOrigin-RevId: a14d38050af2a7d24f87642e63147642603a7ea5 --- CMakeLists.txt | 1 + td/telegram/ContactsManager.cpp | 8 ++--- td/telegram/Dependencies.cpp | 52 ++++++++++++++++++++++++++++++ td/telegram/Dependencies.h | 4 +++ td/telegram/MessagesManager.cpp | 57 +++++++-------------------------- td/telegram/MessagesManager.h | 2 -- td/telegram/PollManager.cpp | 8 ++--- 7 files changed, 76 insertions(+), 56 deletions(-) create mode 100644 td/telegram/Dependencies.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 115ce1f7..cd490992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -380,6 +380,7 @@ set(TDLIB_SOURCE td/telegram/Contact.cpp td/telegram/ContactsManager.cpp td/telegram/DelayDispatcher.cpp + td/telegram/Dependencies.cpp td/telegram/DeviceTokenManager.cpp td/telegram/DhCache.cpp td/telegram/DialogAdministrator.cpp diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ba375d3e..d847f5ba 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7535,7 +7535,7 @@ void ContactsManager::on_load_user_full_from_database(UserId user_id, string val Dependencies dependencies; dependencies.user_ids.insert(user_id); - td_->messages_manager_->resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); if (user_full->need_phone_number_privacy_exception && is_user_contact(user_id)) { user_full->need_phone_number_privacy_exception = false; @@ -7705,7 +7705,7 @@ void ContactsManager::on_load_chat_full_from_database(ChatId chat_id, string val dependencies.user_ids.insert(participant.user_id); dependencies.user_ids.insert(participant.inviter_user_id); } - td_->messages_manager_->resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); for (auto &participant : chat_full->participants) { get_bot_info_force(participant.user_id); @@ -7778,10 +7778,10 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s Dependencies dependencies; dependencies.channel_ids.insert(channel_id); - td_->messages_manager_->add_dialog_dependencies(dependencies, DialogId(channel_full->linked_channel_id)); + MessagesManager::add_dialog_dependencies(dependencies, DialogId(channel_full->linked_channel_id)); dependencies.chat_ids.insert(channel_full->migrated_from_chat_id); dependencies.user_ids.insert(channel_full->bot_user_ids.begin(), channel_full->bot_user_ids.end()); - td_->messages_manager_->resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); for (auto &user_id : channel_full->bot_user_ids) { get_bot_info_force(user_id); diff --git a/td/telegram/Dependencies.cpp b/td/telegram/Dependencies.cpp new file mode 100644 index 00000000..d4fc9466 --- /dev/null +++ b/td/telegram/Dependencies.cpp @@ -0,0 +1,52 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020 +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +#include "td/telegram/Dependencies.h" + +#include "td/telegram/ContactsManager.h" +#include "td/telegram/MessagesManager.h" +#include "td/telegram/Td.h" +#include "td/telegram/WebPagesManager.h" + +#include "td/utils/logging.h" + +namespace td { + +void resolve_dependencies_force(Td *td, const Dependencies &dependencies) { + for (auto user_id : dependencies.user_ids) { + if (user_id.is_valid() && !td->contacts_manager_->have_user_force(user_id)) { + LOG(ERROR) << "Can't find " << user_id; + } + } + for (auto chat_id : dependencies.chat_ids) { + if (chat_id.is_valid() && !td->contacts_manager_->have_chat_force(chat_id)) { + LOG(ERROR) << "Can't find " << chat_id; + } + } + for (auto channel_id : dependencies.channel_ids) { + if (channel_id.is_valid() && !td->contacts_manager_->have_channel_force(channel_id)) { + LOG(ERROR) << "Can't find " << channel_id; + } + } + for (auto secret_chat_id : dependencies.secret_chat_ids) { + if (secret_chat_id.is_valid() && !td->contacts_manager_->have_secret_chat_force(secret_chat_id)) { + LOG(ERROR) << "Can't find " << secret_chat_id; + } + } + for (auto dialog_id : dependencies.dialog_ids) { + if (dialog_id.is_valid() && !td->messages_manager_->have_dialog_force(dialog_id)) { + LOG(ERROR) << "Can't find " << dialog_id; + td->messages_manager_->force_create_dialog(dialog_id, "resolve_dependencies_force"); + } + } + for (auto web_page_id : dependencies.web_page_ids) { + if (web_page_id.is_valid()) { + td->web_pages_manager_->have_web_page_force(web_page_id); + } + } +} + +} // namespace td diff --git a/td/telegram/Dependencies.h b/td/telegram/Dependencies.h index 64cc1adf..50760d31 100644 --- a/td/telegram/Dependencies.h +++ b/td/telegram/Dependencies.h @@ -17,6 +17,8 @@ namespace td { +class Td; + struct Dependencies { std::unordered_set user_ids; std::unordered_set chat_ids; @@ -26,4 +28,6 @@ struct Dependencies { std::unordered_set web_page_ids; }; +void resolve_dependencies_force(Td *td, const Dependencies &dependencies); + } // namespace td diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 8bcbdea6..a6e4efde 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -49,7 +49,6 @@ #include "td/telegram/UpdatesManager.h" #include "td/telegram/Version.h" #include "td/telegram/WebPageId.h" -#include "td/telegram/WebPagesManager.h" #include "td/actor/PromiseFuture.h" #include "td/actor/SleepActor.h" @@ -12874,7 +12873,7 @@ void MessagesManager::load_dialogs(vector dialog_ids, Promise && add_dialog_dependencies(dependencies, dialog_id); } } - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); for (auto dialog_id : dialog_ids) { if (dialog_id.is_valid()) { @@ -17164,7 +17163,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId is_first = false; pos++; } - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); if (!added_new_message && !only_local && dialog_id.get_type() != DialogType::SecretChat) { if (from_the_end) { @@ -17441,7 +17440,7 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id added_message_ids.push_back(m->message_id); } } - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); for (auto message_id : added_message_ids) { send_update_new_message(d, get_message(d, message_id)); @@ -18123,40 +18122,6 @@ void MessagesManager::add_dialog_dependencies(Dependencies &dependencies, Dialog } } -void MessagesManager::resolve_dependencies_force(const Dependencies &dependencies) { - for (auto user_id : dependencies.user_ids) { - if (user_id.is_valid() && !td_->contacts_manager_->have_user_force(user_id)) { - LOG(ERROR) << "Can't find " << user_id; - } - } - for (auto chat_id : dependencies.chat_ids) { - if (chat_id.is_valid() && !td_->contacts_manager_->have_chat_force(chat_id)) { - LOG(ERROR) << "Can't find " << chat_id; - } - } - for (auto channel_id : dependencies.channel_ids) { - if (channel_id.is_valid() && !td_->contacts_manager_->have_channel_force(channel_id)) { - LOG(ERROR) << "Can't find " << channel_id; - } - } - for (auto secret_chat_id : dependencies.secret_chat_ids) { - if (secret_chat_id.is_valid() && !td_->contacts_manager_->have_secret_chat_force(secret_chat_id)) { - LOG(ERROR) << "Can't find " << secret_chat_id; - } - } - for (auto dialog_id : dependencies.dialog_ids) { - if (dialog_id.is_valid() && !have_dialog_force(dialog_id)) { - LOG(ERROR) << "Can't find " << dialog_id; - force_create_dialog(dialog_id, "resolve_dependencies_force"); - } - } - for (auto web_page_id : dependencies.web_page_ids) { - if (web_page_id.is_valid()) { - td_->web_pages_manager_->have_web_page_force(web_page_id); - } - } -} - class MessagesManager::SendMessageLogEvent { public: DialogId dialog_id; @@ -25713,7 +25678,7 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId Dependencies dependencies; add_message_dependencies(dependencies, d->dialog_id, m.get()); - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); m->have_previous = false; m->have_next = false; @@ -28339,7 +28304,7 @@ unique_ptr MessagesManager::parse_dialog(DialogId dialo if (d->draft_message != nullptr) { add_formatted_text_dependencies(dependencies, &d->draft_message->input_message_text.text); } - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); return d; } @@ -29227,7 +29192,7 @@ void MessagesManager::on_binlog_events(vector &&events) { Dependencies dependencies; add_dialog_dependencies(dependencies, dialog_id); add_message_dependencies(dependencies, dialog_id, m.get()); - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); m->content = dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::Send); @@ -29255,7 +29220,7 @@ void MessagesManager::on_binlog_events(vector &&events) { Dependencies dependencies; add_dialog_dependencies(dependencies, dialog_id); add_message_dependencies(dependencies, dialog_id, m.get()); - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); auto bot_user_id = log_event.bot_user_id; if (!td_->contacts_manager_->have_user_force(bot_user_id)) { @@ -29292,7 +29257,7 @@ void MessagesManager::on_binlog_events(vector &&events) { Dependencies dependencies; add_dialog_dependencies(dependencies, dialog_id); add_message_dependencies(dependencies, dialog_id, m.get()); - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); m->content = dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::SendViaBot); @@ -29320,7 +29285,7 @@ void MessagesManager::on_binlog_events(vector &&events) { Dependencies dependencies; add_dialog_dependencies(dependencies, dialog_id); add_message_dependencies(dependencies, dialog_id, m.get()); - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); auto result_message = continue_send_message(dialog_id, std::move(m), event.id_); if (result_message != nullptr) { @@ -29347,7 +29312,7 @@ void MessagesManager::on_binlog_events(vector &&events) { for (auto &m : messages) { add_message_dependencies(dependencies, to_dialog_id, m.get()); } - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); Dialog *to_dialog = get_dialog_force(to_dialog_id); if (to_dialog == nullptr) { @@ -29775,7 +29740,7 @@ void MessagesManager::on_binlog_events(vector &&events) { auto dialog_id = log_event.dialog_id_; Dependencies dependencies; add_dialog_dependencies(dependencies, dialog_id); - resolve_dependencies_force(dependencies); + resolve_dependencies_force(td_, dependencies); get_dialog_force(dialog_id); // load it if exists diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index a1750ef4..122d2027 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -824,8 +824,6 @@ class MessagesManager : public Actor { static void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id); - void resolve_dependencies_force(const Dependencies &dependencies); - ActorOwn sequence_dispatcher_; private: diff --git a/td/telegram/PollManager.cpp b/td/telegram/PollManager.cpp index d45d0811..26792f5a 100644 --- a/td/telegram/PollManager.cpp +++ b/td/telegram/PollManager.cpp @@ -1415,8 +1415,8 @@ void PollManager::on_binlog_events(vector &&events) { auto dialog_id = log_event.full_message_id_.get_dialog_id(); Dependencies dependencies; - td_->messages_manager_->add_dialog_dependencies(dependencies, dialog_id); - td_->messages_manager_->resolve_dependencies_force(dependencies); + MessagesManager::add_dialog_dependencies(dependencies, dialog_id); + resolve_dependencies_force(td_, dependencies); do_set_poll_answer(log_event.poll_id_, log_event.full_message_id_, std::move(log_event.options_), event.id_, Auto()); @@ -1434,8 +1434,8 @@ void PollManager::on_binlog_events(vector &&events) { auto dialog_id = log_event.full_message_id_.get_dialog_id(); Dependencies dependencies; - td_->messages_manager_->add_dialog_dependencies(dependencies, dialog_id); - td_->messages_manager_->resolve_dependencies_force(dependencies); + MessagesManager::add_dialog_dependencies(dependencies, dialog_id); + resolve_dependencies_force(td_, dependencies); do_stop_poll(log_event.poll_id_, log_event.full_message_id_, nullptr, event.id_, Auto()); break;