Make all fields in Dependencies class private.
This commit is contained in:
parent
a136a9d22b
commit
8b16cf7271
@ -9633,7 +9633,7 @@ void ContactsManager::on_load_user_full_from_database(UserId user_id, string val
|
||||
}
|
||||
|
||||
Dependencies dependencies;
|
||||
dependencies.user_ids.insert(user_id);
|
||||
dependencies.add(user_id);
|
||||
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());
|
||||
@ -9731,13 +9731,13 @@ void ContactsManager::on_load_chat_full_from_database(ChatId chat_id, string val
|
||||
}
|
||||
|
||||
Dependencies dependencies;
|
||||
dependencies.chat_ids.insert(chat_id);
|
||||
dependencies.user_ids.insert(chat_full->creator_user_id);
|
||||
dependencies.add(chat_id);
|
||||
dependencies.add(chat_full->creator_user_id);
|
||||
for (auto &participant : chat_full->participants) {
|
||||
dependencies.add_message_sender_dependencies(participant.dialog_id_);
|
||||
dependencies.user_ids.insert(participant.inviter_user_id_);
|
||||
dependencies.add(participant.inviter_user_id_);
|
||||
}
|
||||
dependencies.user_ids.insert(chat_full->invite_link.get_creator_user_id());
|
||||
dependencies.add(chat_full->invite_link.get_creator_user_id());
|
||||
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());
|
||||
@ -9840,13 +9840,15 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
|
||||
}
|
||||
|
||||
Dependencies dependencies;
|
||||
dependencies.channel_ids.insert(channel_id);
|
||||
dependencies.add(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
|
||||
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());
|
||||
dependencies.add(channel_full->migrated_from_chat_id);
|
||||
for (auto bot_user_id : channel_full->bot_user_ids) {
|
||||
dependencies.add(bot_user_id);
|
||||
}
|
||||
dependencies.add(channel_full->invite_link.get_creator_user_id());
|
||||
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());
|
||||
|
@ -16,6 +16,36 @@
|
||||
|
||||
namespace td {
|
||||
|
||||
void Dependencies::add(UserId user_id) {
|
||||
if (user_id.is_valid()) {
|
||||
user_ids.insert(user_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Dependencies::add(ChatId chat_id) {
|
||||
if (chat_id.is_valid()) {
|
||||
chat_ids.insert(chat_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Dependencies::add(ChannelId channel_id) {
|
||||
if (channel_id.is_valid()) {
|
||||
channel_ids.insert(channel_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Dependencies::add(SecretChatId secret_chat_id) {
|
||||
if (secret_chat_id.is_valid()) {
|
||||
secret_chat_ids.insert(secret_chat_id);
|
||||
}
|
||||
}
|
||||
|
||||
void Dependencies::add(WebPageId web_page_id) {
|
||||
if (web_page_id.is_valid()) {
|
||||
web_page_ids.insert(web_page_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);
|
||||
@ -25,16 +55,16 @@ void Dependencies::add_dialog_and_dependencies(DialogId dialog_id) {
|
||||
void Dependencies::add_dialog_dependencies(DialogId dialog_id) {
|
||||
switch (dialog_id.get_type()) {
|
||||
case DialogType::User:
|
||||
user_ids.insert(dialog_id.get_user_id());
|
||||
add(dialog_id.get_user_id());
|
||||
break;
|
||||
case DialogType::Chat:
|
||||
chat_ids.insert(dialog_id.get_chat_id());
|
||||
add(dialog_id.get_chat_id());
|
||||
break;
|
||||
case DialogType::Channel:
|
||||
channel_ids.insert(dialog_id.get_channel_id());
|
||||
add(dialog_id.get_channel_id());
|
||||
break;
|
||||
case DialogType::SecretChat:
|
||||
secret_chat_ids.insert(dialog_id.get_secret_chat_id());
|
||||
add(dialog_id.get_secret_chat_id());
|
||||
break;
|
||||
case DialogType::None:
|
||||
break;
|
||||
@ -45,7 +75,7 @@ void Dependencies::add_dialog_dependencies(DialogId dialog_id) {
|
||||
|
||||
void Dependencies::add_message_sender_dependencies(DialogId dialog_id) {
|
||||
if (dialog_id.get_type() == DialogType::User) {
|
||||
user_ids.insert(dialog_id.get_user_id());
|
||||
add(dialog_id.get_user_id());
|
||||
} else {
|
||||
add_dialog_and_dependencies(dialog_id);
|
||||
}
|
||||
@ -54,19 +84,19 @@ void Dependencies::add_message_sender_dependencies(DialogId dialog_id) {
|
||||
bool Dependencies::resolve_force(Td *td, const char *source) const {
|
||||
bool success = true;
|
||||
for (auto user_id : user_ids) {
|
||||
if (user_id.is_valid() && !td->contacts_manager_->have_user_force(user_id)) {
|
||||
if (!td->contacts_manager_->have_user_force(user_id)) {
|
||||
LOG(ERROR) << "Can't find " << user_id << " from " << source;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
for (auto chat_id : chat_ids) {
|
||||
if (chat_id.is_valid() && !td->contacts_manager_->have_chat_force(chat_id)) {
|
||||
if (!td->contacts_manager_->have_chat_force(chat_id)) {
|
||||
LOG(ERROR) << "Can't find " << chat_id << " from " << source;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
for (auto channel_id : channel_ids) {
|
||||
if (channel_id.is_valid() && !td->contacts_manager_->have_channel_force(channel_id)) {
|
||||
if (!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";
|
||||
continue;
|
||||
@ -76,20 +106,20 @@ bool Dependencies::resolve_force(Td *td, const char *source) const {
|
||||
}
|
||||
}
|
||||
for (auto secret_chat_id : secret_chat_ids) {
|
||||
if (secret_chat_id.is_valid() && !td->contacts_manager_->have_secret_chat_force(secret_chat_id)) {
|
||||
if (!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 : dialog_ids) {
|
||||
if (dialog_id.is_valid() && !td->messages_manager_->have_dialog_force(dialog_id, source)) {
|
||||
if (!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 : web_page_ids) {
|
||||
if (web_page_id.is_valid() && !td->web_pages_manager_->have_web_page_force(web_page_id)) {
|
||||
if (!td->web_pages_manager_->have_web_page_force(web_page_id)) {
|
||||
LOG(INFO) << "Can't find " << web_page_id << " from " << source;
|
||||
success = false;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ namespace td {
|
||||
class Td;
|
||||
|
||||
class Dependencies {
|
||||
public:
|
||||
std::unordered_set<UserId, UserIdHash> user_ids;
|
||||
std::unordered_set<ChatId, ChatIdHash> chat_ids;
|
||||
std::unordered_set<ChannelId, ChannelIdHash> channel_ids;
|
||||
@ -28,6 +27,17 @@ class Dependencies {
|
||||
std::unordered_set<DialogId, DialogIdHash> dialog_ids;
|
||||
std::unordered_set<WebPageId, WebPageIdHash> web_page_ids;
|
||||
|
||||
public:
|
||||
void add(UserId user_id);
|
||||
|
||||
void add(ChatId chat_id);
|
||||
|
||||
void add(ChannelId channel_id);
|
||||
|
||||
void add(SecretChatId secret_chat_id);
|
||||
|
||||
void add(WebPageId web_page_id);
|
||||
|
||||
void add_dialog_and_dependencies(DialogId dialog_id);
|
||||
|
||||
void add_dialog_dependencies(DialogId dialog_id);
|
||||
@ -35,6 +45,10 @@ class Dependencies {
|
||||
void add_message_sender_dependencies(DialogId dialog_id);
|
||||
|
||||
bool resolve_force(Td *td, const char *source) const;
|
||||
|
||||
const std::unordered_set<DialogId, DialogIdHash> &get_dialog_ids() const {
|
||||
return dialog_ids;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -5496,7 +5496,7 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
|
||||
switch (message_content->get_type()) {
|
||||
case MessageContentType::Text: {
|
||||
const auto *content = static_cast<const MessageText *>(message_content);
|
||||
dependencies.web_page_ids.insert(content->web_page_id);
|
||||
dependencies.add(content->web_page_id);
|
||||
break;
|
||||
}
|
||||
case MessageContentType::Animation:
|
||||
@ -5505,14 +5505,14 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
|
||||
break;
|
||||
case MessageContentType::Contact: {
|
||||
const auto *content = static_cast<const MessageContact *>(message_content);
|
||||
dependencies.user_ids.insert(content->contact.get_user_id());
|
||||
dependencies.add(content->contact.get_user_id());
|
||||
break;
|
||||
}
|
||||
case MessageContentType::Document:
|
||||
break;
|
||||
case MessageContentType::Game: {
|
||||
const auto *content = static_cast<const MessageGame *>(message_content);
|
||||
dependencies.user_ids.insert(content->game.get_bot_user_id());
|
||||
dependencies.add(content->game.get_bot_user_id());
|
||||
break;
|
||||
}
|
||||
case MessageContentType::Invoice:
|
||||
@ -5535,7 +5535,9 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
|
||||
break;
|
||||
case MessageContentType::ChatCreate: {
|
||||
const auto *content = static_cast<const MessageChatCreate *>(message_content);
|
||||
dependencies.user_ids.insert(content->participant_user_ids.begin(), content->participant_user_ids.end());
|
||||
for (auto &participant_user_id : content->participant_user_ids) {
|
||||
dependencies.add(participant_user_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MessageContentType::ChatChangeTitle:
|
||||
@ -5548,26 +5550,28 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
|
||||
break;
|
||||
case MessageContentType::ChatAddUsers: {
|
||||
const auto *content = static_cast<const MessageChatAddUsers *>(message_content);
|
||||
dependencies.user_ids.insert(content->user_ids.begin(), content->user_ids.end());
|
||||
for (auto &user_id : content->user_ids) {
|
||||
dependencies.add(user_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MessageContentType::ChatJoinedByLink:
|
||||
break;
|
||||
case MessageContentType::ChatDeleteUser: {
|
||||
const auto *content = static_cast<const MessageChatDeleteUser *>(message_content);
|
||||
dependencies.user_ids.insert(content->user_id);
|
||||
dependencies.add(content->user_id);
|
||||
break;
|
||||
}
|
||||
case MessageContentType::ChatMigrateTo: {
|
||||
const auto *content = static_cast<const MessageChatMigrateTo *>(message_content);
|
||||
dependencies.channel_ids.insert(content->migrated_to_channel_id);
|
||||
dependencies.add(content->migrated_to_channel_id);
|
||||
break;
|
||||
}
|
||||
case MessageContentType::ChannelCreate:
|
||||
break;
|
||||
case MessageContentType::ChannelMigrateFrom: {
|
||||
const auto *content = static_cast<const MessageChannelMigrateFrom *>(message_content);
|
||||
dependencies.chat_ids.insert(content->migrated_from_chat_id);
|
||||
dependencies.add(content->migrated_from_chat_id);
|
||||
break;
|
||||
}
|
||||
case MessageContentType::PinMessage:
|
||||
@ -5616,7 +5620,9 @@ void add_message_content_dependencies(Dependencies &dependencies, const MessageC
|
||||
break;
|
||||
case MessageContentType::InviteToGroupCall: {
|
||||
const auto *content = static_cast<const MessageInviteToGroupCall *>(message_content);
|
||||
dependencies.user_ids.insert(content->user_ids.begin(), content->user_ids.end());
|
||||
for (auto &user_id : content->user_ids) {
|
||||
dependencies.add(user_id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MessageContentType::ChatSetTheme:
|
||||
|
@ -4141,7 +4141,7 @@ void add_formatted_text_dependencies(Dependencies &dependencies, const Formatted
|
||||
}
|
||||
for (auto &entity : text->entities) {
|
||||
if (entity.user_id.is_valid()) {
|
||||
dependencies.user_ids.insert(entity.user_id);
|
||||
dependencies.add(entity.user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25356,13 +25356,13 @@ 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);
|
||||
dependencies.add(m->sender_user_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);
|
||||
dependencies.add(m->via_bot_user_id);
|
||||
if (m->forward_info != nullptr) {
|
||||
dependencies.user_ids.insert(m->forward_info->sender_user_id);
|
||||
dependencies.add(m->forward_info->sender_user_id);
|
||||
dependencies.add_dialog_and_dependencies(m->forward_info->sender_dialog_id);
|
||||
dependencies.add_dialog_and_dependencies(m->forward_info->from_dialog_id);
|
||||
}
|
||||
@ -36677,7 +36677,7 @@ void MessagesManager::fix_new_dialog(Dialog *d, unique_ptr<Message> &&last_datab
|
||||
add_message_dependencies(dependencies, last_database_message.get());
|
||||
|
||||
int32 dependent_dialog_count = 0;
|
||||
for (auto &other_dialog_id : dependencies.dialog_ids) {
|
||||
for (const auto &other_dialog_id : dependencies.get_dialog_ids()) {
|
||||
if (other_dialog_id.is_valid() && !have_dialog(other_dialog_id)) {
|
||||
LOG(INFO) << "Postpone adding of last message in " << dialog_id << " because of cyclic dependency with "
|
||||
<< other_dialog_id;
|
||||
@ -37520,7 +37520,7 @@ unique_ptr<MessagesManager::Dialog> MessagesManager::parse_dialog(DialogId dialo
|
||||
add_formatted_text_dependencies(dependencies, &d->draft_message->input_message_text.text);
|
||||
}
|
||||
for (auto user_id : d->pending_join_request_user_ids) {
|
||||
dependencies.user_ids.insert(user_id);
|
||||
dependencies.add(user_id);
|
||||
}
|
||||
if (!dependencies.resolve_force(td_, source)) {
|
||||
send_get_dialog_query(dialog_id, Auto(), 0, source);
|
||||
|
@ -910,7 +910,7 @@ void add_reply_markup_dependencies(Dependencies &dependencies, const ReplyMarkup
|
||||
for (auto &row : reply_markup->inline_keyboard) {
|
||||
for (auto &button : row) {
|
||||
if (button.user_id.is_valid()) {
|
||||
dependencies.user_ids.insert(button.user_id);
|
||||
dependencies.add(button.user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user