2020-01-27 01:09:05 +01:00
|
|
|
//
|
2022-12-31 22:28:08 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
2020-01-27 01:09:05 +01:00
|
|
|
//
|
|
|
|
// 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"
|
2023-07-10 14:36:38 +02:00
|
|
|
#include "td/telegram/StoryManager.h"
|
2020-01-27 01:09:05 +01:00
|
|
|
#include "td/telegram/Td.h"
|
|
|
|
#include "td/telegram/WebPagesManager.h"
|
|
|
|
|
2020-09-24 18:15:42 +02:00
|
|
|
#include "td/utils/common.h"
|
2020-01-27 01:09:05 +01:00
|
|
|
#include "td/utils/logging.h"
|
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
2022-03-11 13:31:28 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 14:36:38 +02:00
|
|
|
void Dependencies::add(StoryFullId story_full_id) {
|
|
|
|
if (story_full_id.is_valid()) {
|
|
|
|
add_dialog_and_dependencies(story_full_id.get_dialog_id());
|
|
|
|
story_full_ids.insert(story_full_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 13:10:24 +01:00
|
|
|
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);
|
2020-09-10 22:24:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 13:10:24 +01:00
|
|
|
void Dependencies::add_dialog_dependencies(DialogId dialog_id) {
|
2020-09-10 22:24:33 +02:00
|
|
|
switch (dialog_id.get_type()) {
|
|
|
|
case DialogType::User:
|
2022-03-11 13:31:28 +01:00
|
|
|
add(dialog_id.get_user_id());
|
2020-09-10 22:24:33 +02:00
|
|
|
break;
|
|
|
|
case DialogType::Chat:
|
2022-03-11 13:31:28 +01:00
|
|
|
add(dialog_id.get_chat_id());
|
2020-09-10 22:24:33 +02:00
|
|
|
break;
|
|
|
|
case DialogType::Channel:
|
2022-03-11 13:31:28 +01:00
|
|
|
add(dialog_id.get_channel_id());
|
2020-09-10 22:24:33 +02:00
|
|
|
break;
|
|
|
|
case DialogType::SecretChat:
|
2022-03-11 13:31:28 +01:00
|
|
|
add(dialog_id.get_secret_chat_id());
|
2020-09-10 22:24:33 +02:00
|
|
|
break;
|
|
|
|
case DialogType::None:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 13:10:24 +01:00
|
|
|
void Dependencies::add_message_sender_dependencies(DialogId dialog_id) {
|
2020-10-19 18:17:56 +02:00
|
|
|
if (dialog_id.get_type() == DialogType::User) {
|
2022-03-11 13:31:28 +01:00
|
|
|
add(dialog_id.get_user_id());
|
2020-10-19 18:17:56 +02:00
|
|
|
} else {
|
2022-03-11 13:10:24 +01:00
|
|
|
add_dialog_and_dependencies(dialog_id);
|
2020-10-19 18:17:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-11 13:10:24 +01:00
|
|
|
bool Dependencies::resolve_force(Td *td, const char *source) const {
|
2021-04-04 02:23:22 +02:00
|
|
|
bool success = true;
|
2022-03-11 13:10:24 +01:00
|
|
|
for (auto user_id : user_ids) {
|
2022-03-11 13:31:28 +01:00
|
|
|
if (!td->contacts_manager_->have_user_force(user_id)) {
|
2020-10-08 21:54:24 +02:00
|
|
|
LOG(ERROR) << "Can't find " << user_id << " from " << source;
|
2021-04-04 02:23:22 +02:00
|
|
|
success = false;
|
2020-01-27 01:09:05 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 13:10:24 +01:00
|
|
|
for (auto chat_id : chat_ids) {
|
2022-03-11 13:31:28 +01:00
|
|
|
if (!td->contacts_manager_->have_chat_force(chat_id)) {
|
2020-10-08 21:54:24 +02:00
|
|
|
LOG(ERROR) << "Can't find " << chat_id << " from " << source;
|
2021-04-04 02:23:22 +02:00
|
|
|
success = false;
|
2020-01-27 01:09:05 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 13:10:24 +01:00
|
|
|
for (auto channel_id : channel_ids) {
|
2022-03-11 13:31:28 +01:00
|
|
|
if (!td->contacts_manager_->have_channel_force(channel_id)) {
|
2021-12-22 18:15:18 +01:00
|
|
|
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;
|
|
|
|
}
|
2020-10-08 21:54:24 +02:00
|
|
|
LOG(ERROR) << "Can't find " << channel_id << " from " << source;
|
2021-04-04 02:23:22 +02:00
|
|
|
success = false;
|
2020-01-27 01:09:05 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 13:10:24 +01:00
|
|
|
for (auto secret_chat_id : secret_chat_ids) {
|
2022-03-11 13:31:28 +01:00
|
|
|
if (!td->contacts_manager_->have_secret_chat_force(secret_chat_id)) {
|
2020-10-08 21:54:24 +02:00
|
|
|
LOG(ERROR) << "Can't find " << secret_chat_id << " from " << source;
|
2021-04-04 02:23:22 +02:00
|
|
|
success = false;
|
2020-01-27 01:09:05 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 13:10:24 +01:00
|
|
|
for (auto dialog_id : dialog_ids) {
|
2022-03-11 13:31:28 +01:00
|
|
|
if (!td->messages_manager_->have_dialog_force(dialog_id, source)) {
|
2020-10-08 21:54:24 +02:00
|
|
|
LOG(ERROR) << "Can't find " << dialog_id << " from " << source;
|
2023-07-03 13:09:17 +02:00
|
|
|
td->messages_manager_->force_create_dialog(dialog_id, source, true);
|
2021-04-04 02:23:22 +02:00
|
|
|
success = false;
|
2020-01-27 01:09:05 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-11 13:10:24 +01:00
|
|
|
for (auto web_page_id : web_page_ids) {
|
2022-03-11 13:31:28 +01:00
|
|
|
if (!td->web_pages_manager_->have_web_page_force(web_page_id)) {
|
2021-07-08 16:37:23 +02:00
|
|
|
LOG(INFO) << "Can't find " << web_page_id << " from " << source;
|
2023-07-10 14:36:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (auto story_full_id : story_full_ids) {
|
|
|
|
if (!td->story_manager_->have_story_force(story_full_id)) {
|
|
|
|
LOG(INFO) << "Can't find " << story_full_id << " from " << source;
|
2020-01-27 01:09:05 +01:00
|
|
|
}
|
|
|
|
}
|
2021-04-04 02:23:22 +02:00
|
|
|
return success;
|
2020-01-27 01:09:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|