Reload objects from server if failed to resolve their dependencies.

This commit is contained in:
levlam 2021-04-04 03:23:22 +03:00
parent c36ed586e2
commit 8039660cfe
9 changed files with 46 additions and 24 deletions

View File

@ -9231,7 +9231,11 @@ void ContactsManager::on_load_user_full_from_database(UserId user_id, string val
Dependencies dependencies;
dependencies.user_ids.insert(user_id);
resolve_dependencies_force(td_, dependencies, "user_full");
if (!resolve_dependencies_force(td_, dependencies, "user_full")) {
users_full_.erase(user_id);
G()->td_db()->get_sqlite_pmc()->erase(get_user_full_database_key(user_id), Auto());
return;
}
if (user_full->need_phone_number_privacy_exception && is_user_contact(user_id)) {
user_full->need_phone_number_privacy_exception = false;
@ -9418,7 +9422,11 @@ void ContactsManager::on_load_chat_full_from_database(ChatId chat_id, string val
dependencies.user_ids.insert(participant.inviter_user_id);
}
dependencies.user_ids.insert(chat_full->invite_link.get_creator_user_id());
resolve_dependencies_force(td_, dependencies, "chat_full");
if (!resolve_dependencies_force(td_, dependencies, "chat_full")) {
chats_full_.erase(chat_id);
G()->td_db()->get_sqlite_pmc()->erase(get_chat_full_database_key(chat_id), Auto());
return;
}
for (auto &participant : chat_full->participants) {
get_bot_info_force(participant.user_id);
@ -9522,7 +9530,11 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
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());
resolve_dependencies_force(td_, dependencies, "channel_full");
if (!resolve_dependencies_force(td_, dependencies, "channel_full")) {
channels_full_.erase(channel_id);
G()->td_db()->get_sqlite_pmc()->erase(get_channel_full_database_key(channel_id), Auto());
return;
}
for (auto &user_id : channel_full->bot_user_ids) {
get_bot_info_force(user_id);

View File

@ -51,38 +51,46 @@ void add_message_sender_dependencies(Dependencies &dependencies, DialogId dialog
}
}
void resolve_dependencies_force(Td *td, const Dependencies &dependencies, const char *source) {
bool resolve_dependencies_force(Td *td, const Dependencies &dependencies, const char *source) {
bool success = true;
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 << " from " << source;
success = false;
}
}
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 << " from " << source;
success = false;
}
}
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 << " from " << source;
success = false;
}
}
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 << " from " << source;
success = false;
}
}
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 << " from " << source;
td->messages_manager_->force_create_dialog(dialog_id, "resolve_dependencies_force");
td->messages_manager_->force_create_dialog(dialog_id, "resolve_dependencies_force", true);
success = false;
}
}
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);
success = false;
}
}
return success;
}
} // namespace td

View File

@ -34,6 +34,6 @@ void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id);
void add_message_sender_dependencies(Dependencies &dependencies, DialogId dialog_id);
void resolve_dependencies_force(Td *td, const Dependencies &dependencies, const char *source);
bool resolve_dependencies_force(Td *td, const Dependencies &dependencies, const char *source);
} // namespace td

View File

@ -16,6 +16,7 @@
#include "td/telegram/ChatId.h"
#include "td/telegram/Contact.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/Document.h"
#include "td/telegram/DocumentsManager.h"
#include "td/telegram/DocumentsManager.hpp"

View File

@ -6,7 +6,6 @@
//
#pragma once
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/files/FileId.h"
#include "td/telegram/FullMessageId.h"
@ -36,6 +35,7 @@
namespace td {
struct Dependencies;
class Game;
struct Photo;
class Td;

View File

@ -7,6 +7,7 @@
#include "td/telegram/MessageEntity.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/misc.h"
#include "td/telegram/SecretChatActor.h"

View File

@ -6,7 +6,6 @@
//
#pragma once
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogId.h"
#include "td/telegram/UserId.h"
@ -25,6 +24,7 @@
namespace td {
class ContactsManager;
struct Dependencies;
class MessageEntity {
public:

View File

@ -10,6 +10,7 @@
#include "td/telegram/ChatId.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogDb.h"
#include "td/telegram/DialogFilter.h"
#include "td/telegram/DialogFilter.hpp"
@ -11396,7 +11397,7 @@ void MessagesManager::repair_channel_server_unread_count(Dialog *d) {
}
LOG(INFO) << "Reload ChannelFull for " << d->dialog_id << " to repair unread message counts";
get_dialog_info_full(d->dialog_id, Promise<Unit>());
get_dialog_info_full(d->dialog_id, Auto());
}
void MessagesManager::read_history_inbox(DialogId dialog_id, MessageId max_message_id, int32 unread_count,
@ -22292,7 +22293,7 @@ void MessagesManager::on_get_history_from_database(DialogId dialog_id, MessageId
is_first = false;
pos++;
}
resolve_dependencies_force(td_, dependencies, "get_history");
resolve_dependencies_force(td_, dependencies, "on_get_history_from_database");
if (from_the_end && !last_added_message_id.is_valid() && last_received_message_id < d->first_database_message_id &&
!d->have_full_history) {
@ -22607,7 +22608,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, "get_scheduled_messages");
resolve_dependencies_force(td_, dependencies, "on_get_scheduled_messages_from_database");
// for (auto message_id : added_message_ids) {
// send_update_new_message(d, get_message(d, message_id));
@ -29323,7 +29324,7 @@ void MessagesManager::on_update_dialog_draft_message(DialogId dialog_id,
if (!have_input_peer(dialog_id, AccessRights::Read)) {
LOG(ERROR) << "Have no read access to " << dialog_id << " to repair chat draft message";
} else {
send_get_dialog_query(dialog_id, Promise<Unit>(), 0, "on_update_dialog_draft_message");
send_get_dialog_query(dialog_id, Auto(), 0, "on_update_dialog_draft_message");
}
return;
}
@ -31849,7 +31850,7 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId
CHECK(d != nullptr);
}
if (!have_input_peer(d->dialog_id, AccessRights::Read)) {
if (!have_input_peer(dialog_id, AccessRights::Read)) {
return nullptr;
}
@ -31872,7 +31873,10 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId
Dependencies dependencies;
add_message_dependencies(dependencies, m.get());
resolve_dependencies_force(td_, dependencies, "on_get_message_from_database");
if (!resolve_dependencies_force(td_, dependencies, "on_get_message_from_database")) {
FullMessageId full_message_id{dialog_id, m->message_id};
get_message_from_server(full_message_id, Auto());
}
m->have_previous = false;
m->have_next = false;
@ -31882,7 +31886,7 @@ MessagesManager::Message *MessagesManager::on_get_message_from_database(DialogId
auto result = add_message_to_dialog(d, std::move(m), false, &need_update, &need_update_dialog_pos, source);
if (need_update_dialog_pos) {
LOG(ERROR) << "Need update dialog pos after load " << (result == nullptr ? MessageId() : result->message_id)
<< " in " << d->dialog_id << " from " << source;
<< " in " << dialog_id << " from " << source;
send_update_chat_last_message(d, source);
}
return result;
@ -34990,7 +34994,9 @@ unique_ptr<MessagesManager::Dialog> 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(td_, dependencies, "parse_dialog");
if (!resolve_dependencies_force(td_, dependencies, "parse_dialog")) {
send_get_dialog_query(dialog_id, Auto(), 0, "parse_dialog");
}
return d;
}
@ -36874,7 +36880,7 @@ void MessagesManager::on_binlog_events(vector<BinlogEvent> &&events) {
break;
}
send_get_dialog_query(dialog_id, Promise<Unit>(), event.id_, "GetDialogFromServerLogEvent");
send_get_dialog_query(dialog_id, Auto(), event.id_, "GetDialogFromServerLogEvent");
break;
}
case LogEvent::HandlerType::UnpinAllDialogMessagesOnServer: {

View File

@ -8,7 +8,6 @@
#include "td/telegram/AccessRights.h"
#include "td/telegram/ChannelId.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/DialogAction.h"
#include "td/telegram/DialogDate.h"
#include "td/telegram/DialogDb.h"
@ -81,17 +80,12 @@
namespace td {
struct BinlogEvent;
struct Dependencies;
class DialogFilter;
class DraftMessage;
struct InputMessageContent;
class MessageContent;
class MultiSequenceDispatcher;
class Td;
class MessagesManager : public Actor {