Simplify adding dialog dependencies.

GitOrigin-RevId: 27c9fcc1221e60960f0183e9d792121ca5e8fb0a
This commit is contained in:
levlam 2020-09-10 23:24:33 +03:00
parent eb72b64c80
commit 2c0a9367ac
6 changed files with 39 additions and 44 deletions

View File

@ -8764,7 +8764,7 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
Dependencies dependencies;
dependencies.channel_ids.insert(channel_id);
MessagesManager::add_dialog_dependencies(dependencies, DialogId(channel_full->linked_channel_id));
add_dialog_and_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());
resolve_dependencies_force(td_, dependencies);

View File

@ -15,6 +15,33 @@
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 add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id) {
switch (dialog_id.get_type()) {
case DialogType::User:
dependencies.user_ids.insert(dialog_id.get_user_id());
break;
case DialogType::Chat:
dependencies.chat_ids.insert(dialog_id.get_chat_id());
break;
case DialogType::Channel:
dependencies.channel_ids.insert(dialog_id.get_channel_id());
break;
case DialogType::SecretChat:
dependencies.secret_chat_ids.insert(dialog_id.get_secret_chat_id());
break;
case DialogType::None:
break;
default:
UNREACHABLE();
}
}
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)) {

View File

@ -28,6 +28,10 @@ struct Dependencies {
std::unordered_set<WebPageId, WebPageIdHash> web_page_ids;
};
void add_dialog_and_dependencies(Dependencies &dependencies, DialogId dialog_id);
void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id);
void resolve_dependencies_force(Td *td, const Dependencies &dependencies);
} // namespace td

View File

@ -20921,27 +20921,14 @@ bool MessagesManager::is_message_auto_read(DialogId dialog_id, bool is_outgoing)
void MessagesManager::add_message_dependencies(Dependencies &dependencies, DialogId dialog_id, const Message *m) {
dependencies.user_ids.insert(m->sender_user_id);
if (m->sender_dialog_id.is_valid() && dependencies.dialog_ids.insert(m->sender_dialog_id).second) {
add_dialog_dependencies(dependencies, m->sender_dialog_id);
}
if (m->reply_in_dialog_id.is_valid() && dependencies.dialog_ids.insert(m->reply_in_dialog_id).second) {
add_dialog_dependencies(dependencies, m->reply_in_dialog_id);
}
if (m->real_forward_from_dialog_id.is_valid() &&
dependencies.dialog_ids.insert(m->real_forward_from_dialog_id).second) {
add_dialog_dependencies(dependencies, m->real_forward_from_dialog_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.user_ids.insert(m->via_bot_user_id);
if (m->forward_info != nullptr) {
dependencies.user_ids.insert(m->forward_info->sender_user_id);
if (m->forward_info->sender_dialog_id.is_valid() &&
dependencies.dialog_ids.insert(m->forward_info->sender_dialog_id).second) {
add_dialog_dependencies(dependencies, m->forward_info->sender_dialog_id);
}
if (m->forward_info->from_dialog_id.is_valid() &&
dependencies.dialog_ids.insert(m->forward_info->from_dialog_id).second) {
add_dialog_dependencies(dependencies, m->forward_info->from_dialog_id);
}
add_dialog_and_dependencies(dependencies, m->forward_info->sender_dialog_id);
add_dialog_and_dependencies(dependencies, m->forward_info->from_dialog_id);
}
for (auto recent_replier_dialog_id : m->reply_info.recent_replier_dialog_ids) {
if (dialog_id.get_type() == DialogType::User) {
@ -20951,27 +20938,6 @@ void MessagesManager::add_message_dependencies(Dependencies &dependencies, Dialo
add_message_content_dependencies(dependencies, m->content.get());
}
void MessagesManager::add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id) {
switch (dialog_id.get_type()) {
case DialogType::User:
dependencies.user_ids.insert(dialog_id.get_user_id());
break;
case DialogType::Chat:
dependencies.chat_ids.insert(dialog_id.get_chat_id());
break;
case DialogType::Channel:
dependencies.channel_ids.insert(dialog_id.get_channel_id());
break;
case DialogType::SecretChat:
dependencies.secret_chat_ids.insert(dialog_id.get_secret_chat_id());
break;
case DialogType::None:
break;
default:
UNREACHABLE();
}
}
class MessagesManager::SendMessageLogEvent {
public:
DialogId dialog_id;

View File

@ -885,8 +885,6 @@ class MessagesManager : public Actor {
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
static void add_dialog_dependencies(Dependencies &dependencies, DialogId dialog_id);
ActorOwn<MultiSequenceDispatcher> sequence_dispatcher_;
private:

View File

@ -1652,7 +1652,7 @@ void PollManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.full_message_id_.get_dialog_id();
Dependencies dependencies;
MessagesManager::add_dialog_dependencies(dependencies, dialog_id);
add_dialog_dependencies(dependencies, dialog_id); // do not load the dialog itself
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_,
@ -1671,7 +1671,7 @@ void PollManager::on_binlog_events(vector<BinlogEvent> &&events) {
auto dialog_id = log_event.full_message_id_.get_dialog_id();
Dependencies dependencies;
MessagesManager::add_dialog_dependencies(dependencies, dialog_id);
add_dialog_dependencies(dependencies, dialog_id); // do not load the dialog itself
resolve_dependencies_force(td_, dependencies);
do_stop_poll(log_event.poll_id_, log_event.full_message_id_, nullptr, event.id_, Auto());