Move methods inside Dependencies class.

This commit is contained in:
levlam 2022-03-11 15:10:24 +03:00
parent 3eda5b17ac
commit a136a9d22b
10 changed files with 75 additions and 74 deletions

View File

@ -7784,10 +7784,10 @@ void ContactsManager::get_created_public_dialogs(PublicDialogType type,
vector<ChannelId> channel_ids;
for (auto &r_channel_id : r_channel_ids) {
auto channel_id = r_channel_id.move_as_ok();
add_dialog_and_dependencies(dependencies, DialogId(channel_id));
dependencies.add_dialog_and_dependencies(DialogId(channel_id));
channel_ids.push_back(channel_id);
}
if (!resolve_dependencies_force(td_, dependencies, "get_created_public_dialogs")) {
if (!dependencies.resolve_force(td_, "get_created_public_dialogs")) {
G()->td_db()->get_binlog_pmc()->erase(pmc_key);
} else {
created_public_channels_[index] = std::move(channel_ids);
@ -9634,7 +9634,7 @@ void ContactsManager::on_load_user_full_from_database(UserId user_id, string val
Dependencies dependencies;
dependencies.user_ids.insert(user_id);
if (!resolve_dependencies_force(td_, dependencies, "on_load_user_full_from_database")) {
if (!dependencies.resolve_force(td_, "on_load_user_full_from_database")) {
users_full_.erase(user_id);
G()->td_db()->get_sqlite_pmc()->erase(get_user_full_database_key(user_id), Auto());
return;
@ -9734,11 +9734,11 @@ void ContactsManager::on_load_chat_full_from_database(ChatId chat_id, string val
dependencies.chat_ids.insert(chat_id);
dependencies.user_ids.insert(chat_full->creator_user_id);
for (auto &participant : chat_full->participants) {
add_message_sender_dependencies(dependencies, participant.dialog_id_);
dependencies.add_message_sender_dependencies(participant.dialog_id_);
dependencies.user_ids.insert(participant.inviter_user_id_);
}
dependencies.user_ids.insert(chat_full->invite_link.get_creator_user_id());
if (!resolve_dependencies_force(td_, dependencies, "on_load_chat_full_from_database")) {
if (!dependencies.resolve_force(td_, "on_load_chat_full_from_database")) {
chats_full_.erase(chat_id);
G()->td_db()->get_sqlite_pmc()->erase(get_chat_full_database_key(chat_id), Auto());
return;
@ -9843,11 +9843,11 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
dependencies.channel_ids.insert(channel_id);
// must not depend on the linked_dialog_id itself, because message database can be disabled
// the Dialog will be forcely created in update_channel_full
add_dialog_dependencies(dependencies, DialogId(channel_full->linked_channel_id));
dependencies.add_dialog_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());
dependencies.user_ids.insert(channel_full->invite_link.get_creator_user_id());
if (!resolve_dependencies_force(td_, dependencies, source)) {
if (!dependencies.resolve_force(td_, source)) {
channels_full_.erase(channel_id);
G()->td_db()->get_sqlite_pmc()->erase(get_channel_full_database_key(channel_id), Auto());
return;

View File

@ -16,25 +16,25 @@
namespace td {
void add_dialog_and_dependencies(Dependencies &dependencies, DialogId dialog_id) {
if (dialog_id.is_valid() && dependencies.dialog_ids.insert(dialog_id).second) {
add_dialog_dependencies(dependencies, dialog_id);
void Dependencies::add_dialog_and_dependencies(DialogId dialog_id) {
if (dialog_id.is_valid() && dialog_ids.insert(dialog_id).second) {
add_dialog_dependencies(dialog_id);
}
}
void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id) {
void Dependencies::add_dialog_dependencies(DialogId dialog_id) {
switch (dialog_id.get_type()) {
case DialogType::User:
dependencies.user_ids.insert(dialog_id.get_user_id());
user_ids.insert(dialog_id.get_user_id());
break;
case DialogType::Chat:
dependencies.chat_ids.insert(dialog_id.get_chat_id());
chat_ids.insert(dialog_id.get_chat_id());
break;
case DialogType::Channel:
dependencies.channel_ids.insert(dialog_id.get_channel_id());
channel_ids.insert(dialog_id.get_channel_id());
break;
case DialogType::SecretChat:
dependencies.secret_chat_ids.insert(dialog_id.get_secret_chat_id());
secret_chat_ids.insert(dialog_id.get_secret_chat_id());
break;
case DialogType::None:
break;
@ -43,29 +43,29 @@ void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id) {
}
}
void add_message_sender_dependencies(Dependencies &dependencies, DialogId dialog_id) {
void Dependencies::add_message_sender_dependencies(DialogId dialog_id) {
if (dialog_id.get_type() == DialogType::User) {
dependencies.user_ids.insert(dialog_id.get_user_id());
user_ids.insert(dialog_id.get_user_id());
} else {
add_dialog_and_dependencies(dependencies, dialog_id);
add_dialog_and_dependencies(dialog_id);
}
}
bool resolve_dependencies_force(Td *td, const Dependencies &dependencies, const char *source) {
bool Dependencies::resolve_force(Td *td, const char *source) const {
bool success = true;
for (auto user_id : dependencies.user_ids) {
for (auto user_id : user_ids) {
if (user_id.is_valid() && !td->contacts_manager_->have_user_force(user_id)) {
LOG(ERROR) << "Can't find " << user_id << " from " << source;
success = false;
}
}
for (auto chat_id : dependencies.chat_ids) {
for (auto chat_id : chat_ids) {
if (chat_id.is_valid() && !td->contacts_manager_->have_chat_force(chat_id)) {
LOG(ERROR) << "Can't find " << chat_id << " from " << source;
success = false;
}
}
for (auto channel_id : dependencies.channel_ids) {
for (auto channel_id : channel_ids) {
if (channel_id.is_valid() && !td->contacts_manager_->have_channel_force(channel_id)) {
if (td->contacts_manager_->have_min_channel(channel_id)) {
LOG(INFO) << "Can't find " << channel_id << " from " << source << ", but have it as a min-channel";
@ -75,20 +75,20 @@ bool resolve_dependencies_force(Td *td, const Dependencies &dependencies, const
success = false;
}
}
for (auto secret_chat_id : dependencies.secret_chat_ids) {
for (auto secret_chat_id : 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 << " from " << source;
success = false;
}
}
for (auto dialog_id : dependencies.dialog_ids) {
for (auto dialog_id : dialog_ids) {
if (dialog_id.is_valid() && !td->messages_manager_->have_dialog_force(dialog_id, source)) {
LOG(ERROR) << "Can't find " << dialog_id << " from " << source;
td->messages_manager_->force_create_dialog(dialog_id, "resolve_dependencies_force", true);
success = false;
}
}
for (auto web_page_id : dependencies.web_page_ids) {
for (auto web_page_id : web_page_ids) {
if (web_page_id.is_valid() && !td->web_pages_manager_->have_web_page_force(web_page_id)) {
LOG(INFO) << "Can't find " << web_page_id << " from " << source;
success = false;

View File

@ -19,21 +19,22 @@ namespace td {
class Td;
struct Dependencies {
class Dependencies {
public:
std::unordered_set<UserId, UserIdHash> user_ids;
std::unordered_set<ChatId, ChatIdHash> chat_ids;
std::unordered_set<ChannelId, ChannelIdHash> channel_ids;
std::unordered_set<SecretChatId, SecretChatIdHash> secret_chat_ids;
std::unordered_set<DialogId, DialogIdHash> dialog_ids;
std::unordered_set<WebPageId, WebPageIdHash> web_page_ids;
void add_dialog_and_dependencies(DialogId dialog_id);
void add_dialog_dependencies(DialogId dialog_id);
void add_message_sender_dependencies(DialogId dialog_id);
bool resolve_force(Td *td, const char *source) const;
};
void add_dialog_and_dependencies(Dependencies &dependencies, DialogId dialog_id);
void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id);
void add_message_sender_dependencies(Dependencies &dependencies, DialogId dialog_id);
bool resolve_dependencies_force(Td *td, const Dependencies &dependencies, const char *source);
} // namespace td

View File

@ -5584,7 +5584,7 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
break;
case MessageContentType::PaymentSuccessful: {
const auto *content = static_cast<const MessagePaymentSuccessful *>(message_content);
add_dialog_and_dependencies(dependencies, content->invoice_dialog_id);
dependencies.add_dialog_and_dependencies(content->invoice_dialog_id);
break;
}
case MessageContentType::ContactRegistered:
@ -5608,8 +5608,8 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
break;
case MessageContentType::ProximityAlertTriggered: {
const auto *content = static_cast<const MessageProximityAlertTriggered *>(message_content);
add_message_sender_dependencies(dependencies, content->traveler_dialog_id);
add_message_sender_dependencies(dependencies, content->watcher_dialog_id);
dependencies.add_message_sender_dependencies(content->traveler_dialog_id);
dependencies.add_message_sender_dependencies(content->watcher_dialog_id);
break;
}
case MessageContentType::GroupCall:

View File

@ -37,7 +37,7 @@
namespace td {
struct Dependencies;
class Dependencies;
class DialogAction;
class Game;
struct Photo;

View File

@ -23,7 +23,7 @@
namespace td {
class ContactsManager;
struct Dependencies;
class Dependencies;
class MessageEntity {
public:

View File

@ -16563,10 +16563,10 @@ void MessagesManager::load_dialogs(vector<DialogId> dialog_ids, Promise<vector<D
Dependencies dependencies;
for (auto dialog_id : dialog_ids) {
if (dialog_id.is_valid() && !have_dialog(dialog_id)) {
add_dialog_dependencies(dependencies, dialog_id);
dependencies.add_dialog_dependencies(dialog_id);
}
}
resolve_dependencies_force(td_, dependencies, "load_dialogs");
dependencies.resolve_force(td_, "load_dialogs");
td::remove_if(dialog_ids, [this](DialogId dialog_id) { return !have_dialog_info(dialog_id); });
@ -24121,7 +24121,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
is_first = false;
pos++;
}
resolve_dependencies_force(td_, dependencies, "on_get_history_from_database");
dependencies.resolve_force(td_, "on_get_history_from_database");
if (from_the_end && !last_added_message_id.is_valid() && d->first_database_message_id.is_valid() &&
!d->have_full_history) {
@ -24502,7 +24502,7 @@ void MessagesManager::on_get_scheduled_messages_from_database(DialogId dialog_id
added_message_ids.push_back(m->message_id);
}
}
resolve_dependencies_force(td_, dependencies, "on_get_scheduled_messages_from_database");
dependencies.resolve_force(td_, "on_get_scheduled_messages_from_database");
// for (auto message_id : added_message_ids) {
// send_update_new_message(d, get_message(d, message_id));
@ -25357,14 +25357,14 @@ bool MessagesManager::is_message_auto_read(DialogId dialog_id, bool is_outgoing)
void MessagesManager::add_message_dependencies(Dependencies &dependencies, const Message *m) {
dependencies.user_ids.insert(m->sender_user_id);
add_dialog_and_dependencies(dependencies, m->sender_dialog_id);
add_dialog_and_dependencies(dependencies, m->reply_in_dialog_id);
add_dialog_and_dependencies(dependencies, m->real_forward_from_dialog_id);
dependencies.add_dialog_and_dependencies(m->sender_dialog_id);
dependencies.add_dialog_and_dependencies(m->reply_in_dialog_id);
dependencies.add_dialog_and_dependencies(m->real_forward_from_dialog_id);
dependencies.user_ids.insert(m->via_bot_user_id);
if (m->forward_info != nullptr) {
dependencies.user_ids.insert(m->forward_info->sender_user_id);
add_dialog_and_dependencies(dependencies, m->forward_info->sender_dialog_id);
add_dialog_and_dependencies(dependencies, m->forward_info->from_dialog_id);
dependencies.add_dialog_and_dependencies(m->forward_info->sender_dialog_id);
dependencies.add_dialog_and_dependencies(m->forward_info->from_dialog_id);
}
for (const auto &replier_min_channel : m->reply_info.replier_min_channels) {
LOG(INFO) << "Add min replied " << replier_min_channel.first;
@ -25373,7 +25373,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, const
for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) {
// don't load the dialog itself
// it will be created in get_message_reply_info_object if needed
add_dialog_dependencies(dependencies, recent_replier_dialog_id);
dependencies.add_dialog_dependencies(recent_replier_dialog_id);
}
if (m->reactions != nullptr) {
for (const auto &reaction : m->reactions->reactions_) {
@ -25385,7 +25385,7 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, const
for (auto dialog_id : dialog_ids) {
// don't load the dialog itself
// it will be created in get_message_reaction_object if needed
add_dialog_dependencies(dependencies, dialog_id);
dependencies.add_dialog_dependencies(dialog_id);
}
}
}
@ -34183,7 +34183,7 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(Dialog *
Dependencies dependencies;
add_message_dependencies(dependencies, m.get());
if (!resolve_dependencies_force(td_, dependencies, "on_get_message_from_database") &&
if (!dependencies.resolve_force(td_, "on_get_message_from_database") &&
dialog_id.get_type() != DialogType::SecretChat) {
get_message_from_server({dialog_id, m->message_id}, Auto(), "on_get_message_from_database 2");
}
@ -37506,12 +37506,12 @@ unique_ptr<MessagesManager::Dialog> MessagesManager::parse_dialog(DialogId dialo
CHECK(dialog_id == d->dialog_id);
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id);
dependencies.add_dialog_dependencies(dialog_id);
if (d->default_join_group_call_as_dialog_id != dialog_id) {
add_message_sender_dependencies(dependencies, d->default_join_group_call_as_dialog_id);
dependencies.add_message_sender_dependencies(d->default_join_group_call_as_dialog_id);
}
if (d->default_send_message_as_dialog_id != dialog_id) {
add_message_sender_dependencies(dependencies, d->default_send_message_as_dialog_id);
dependencies.add_message_sender_dependencies(d->default_send_message_as_dialog_id);
}
if (d->messages != nullptr) {
add_message_dependencies(dependencies, d->messages.get());
@ -37522,7 +37522,7 @@ unique_ptr<MessagesManager::Dialog> MessagesManager::parse_dialog(DialogId dialo
for (auto user_id : d->pending_join_request_user_ids) {
dependencies.user_ids.insert(user_id);
}
if (!resolve_dependencies_force(td_, dependencies, source)) {
if (!dependencies.resolve_force(td_, source)) {
send_get_dialog_query(dialog_id, Auto(), 0, source);
}
@ -38991,9 +38991,9 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
}
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id);
dependencies.add_dialog_dependencies(dialog_id);
add_message_dependencies(dependencies, m.get());
resolve_dependencies_force(td_, dependencies, "SendMessageLogEvent");
dependencies.resolve_force(td_, "SendMessageLogEvent");
m->content =
dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::Send, MessageCopyOptions());
@ -39021,9 +39021,9 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
CHECK(m->content->get_type() == MessageContentType::Text);
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id);
dependencies.add_dialog_dependencies(dialog_id);
add_message_dependencies(dependencies, m.get());
resolve_dependencies_force(td_, dependencies, "SendBotStartMessageLogEvent");
dependencies.resolve_force(td_, "SendBotStartMessageLogEvent");
auto bot_user_id = log_event.bot_user_id;
if (!td_->contacts_manager_->have_user_force(bot_user_id)) {
@ -39058,9 +39058,9 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
}
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id);
dependencies.add_dialog_dependencies(dialog_id);
add_message_dependencies(dependencies, m.get());
resolve_dependencies_force(td_, dependencies, "SendInlineQueryResultMessageLogEvent");
dependencies.resolve_force(td_, "SendInlineQueryResultMessageLogEvent");
m->content = dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::SendViaBot,
MessageCopyOptions());
@ -39087,9 +39087,9 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
CHECK(m->content->get_type() == MessageContentType::ScreenshotTaken);
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id);
dependencies.add_dialog_dependencies(dialog_id);
add_message_dependencies(dependencies, m.get());
resolve_dependencies_force(td_, dependencies, "SendScreenshotTakenNotificationMessageLogEvent");
dependencies.resolve_force(td_, "SendScreenshotTakenNotificationMessageLogEvent");
auto result_message = continue_send_message(dialog_id, std::move(m), event.id_);
if (result_message != nullptr) {
@ -39111,12 +39111,12 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto messages = std::move(log_event.messages_out);
Dependencies dependencies;
add_dialog_dependencies(dependencies, to_dialog_id);
add_dialog_dependencies(dependencies, from_dialog_id);
dependencies.add_dialog_dependencies(to_dialog_id);
dependencies.add_dialog_dependencies(from_dialog_id);
for (auto &m : messages) {
add_message_dependencies(dependencies, m.get());
}
resolve_dependencies_force(td_, dependencies, "ForwardMessagesLogEvent");
dependencies.resolve_force(td_, "ForwardMessagesLogEvent");
Dialog *to_dialog = get_dialog_force(to_dialog_id, "ForwardMessagesLogEvent to");
if (to_dialog == nullptr) {
@ -39647,8 +39647,8 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.dialog_id_;
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id);
resolve_dependencies_force(td_, dependencies, "RegetDialogLogEvent");
dependencies.add_dialog_dependencies(dialog_id);
dependencies.resolve_force(td_, "RegetDialogLogEvent");
get_dialog_force(dialog_id, "RegetDialogLogEvent"); // load it if exists

View File

@ -86,7 +86,7 @@
namespace td {
struct BinlogEvent;
struct Dependencies;
class Dependencies;
class DialogActionBar;
class DialogFilter;
class DraftMessage;

View File

@ -1693,8 +1693,8 @@ void PollManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.full_message_id_.get_dialog_id();
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id); // do not load the dialog itself
resolve_dependencies_force(td_, dependencies, "SetPollAnswerLogEvent");
dependencies.add_dialog_dependencies(dialog_id); // do not load the dialog itself
dependencies.resolve_force(td_, "SetPollAnswerLogEvent");
do_set_poll_answer(log_event.poll_id_, log_event.full_message_id_, std::move(log_event.options_), event.id_,
Auto());
@ -1712,8 +1712,8 @@ void PollManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.full_message_id_.get_dialog_id();
Dependencies dependencies;
add_dialog_dependencies(dependencies, dialog_id); // do not load the dialog itself
resolve_dependencies_force(td_, dependencies, "StopPollLogEvent");
dependencies.add_dialog_dependencies(dialog_id); // do not load the dialog itself
dependencies.resolve_force(td_, "StopPollLogEvent");
do_stop_poll(log_event.poll_id_, log_event.full_message_id_, nullptr, event.id_, Auto());
break;

View File

@ -16,7 +16,7 @@
namespace td {
struct Dependencies;
class Dependencies;
struct KeyboardButton {
// append only