Improve FileView::get_main_file_id() method name.

This commit is contained in:
levlam 2022-07-03 12:01:08 +03:00
parent 2f17f55305
commit d75791481f
10 changed files with 43 additions and 42 deletions

View File

@ -715,7 +715,7 @@ void AnimationsManager::add_saved_animation_impl(FileId animation_id, bool add_o
return promise.set_error(Status::Error(400, "Animation file not found"));
}
LOG(INFO) << "Add saved animation " << animation_id << " with main file " << file_view.file_id();
LOG(INFO) << "Add saved animation " << animation_id << " with main file " << file_view.get_main_file_id();
if (!are_saved_animations_loaded_) {
load_saved_animations(
PromiseCreator::lambda([animation_id, add_on_server, promise = std::move(promise)](Result<> result) mutable {

View File

@ -857,7 +857,7 @@ void BackgroundManager::do_upload_background_file(FileId file_id, const Backgrou
Promise<Unit> &&promise) {
if (input_file == nullptr) {
FileView file_view = td_->file_manager_->get_file_view(file_id);
file_id = file_view.file_id();
file_id = file_view.get_main_file_id();
auto it = file_id_to_background_id_.find(file_id);
if (it != file_id_to_background_id_.end()) {
set_background(it->second, type, for_dark_theme, std::move(promise));
@ -1022,8 +1022,9 @@ void BackgroundManager::add_background(const Background &background, bool replac
if (result->file_id != background.file_id) {
if (result->file_id.is_valid()) {
if (!background.file_id.is_valid() || td_->file_manager_->get_file_view(result->file_id).file_id() !=
td_->file_manager_->get_file_view(background.file_id).file_id()) {
if (!background.file_id.is_valid() ||
td_->file_manager_->get_file_view(result->file_id).get_main_file_id() !=
td_->file_manager_->get_file_view(background.file_id).get_main_file_id()) {
LOG(ERROR) << "Background file has changed from " << result->file_id << " to " << background.file_id;
file_id_to_background_id_.erase(result->file_id);
result->file_source_id = FileSourceId();

View File

@ -74,7 +74,7 @@ FileView DownloadManagerCallback::get_sync_file_view(FileId file_id) {
td_api::object_ptr<td_api::fileDownload> DownloadManagerCallback::get_file_download_object(
FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date, bool is_paused) {
return td_api::make_object<td_api::fileDownload>(td_->file_manager_->get_file_view(file_id).file_id().get(),
return td_api::make_object<td_api::fileDownload>(td_->file_manager_->get_file_view(file_id).get_main_file_id().get(),
td_->file_reference_manager_->get_message_object(file_source_id),
add_date, complete_date, is_paused);
}

View File

@ -364,7 +364,7 @@ FileReferenceManager::Destination FileReferenceManager::on_query_result(Destinat
}
void FileReferenceManager::repair_file_reference(NodeId node_id, Promise<> promise) {
auto main_file_id = G()->td().get_actor_unsafe()->file_manager_->get_file_view(node_id).file_id();
auto main_file_id = G()->td().get_actor_unsafe()->file_manager_->get_file_view(node_id).get_main_file_id();
VLOG(file_references) << "Repair file reference for file " << node_id << "/" << main_file_id;
node_id = main_file_id;
CHECK(node_id.is_valid());

View File

@ -20692,7 +20692,7 @@ Status MessagesManager::view_messages(DialogId dialog_id, MessageId top_thread_m
for (auto file_id : get_message_file_ids(m)) {
auto file_view = td_->file_manager_->get_file_view(file_id);
CHECK(!file_view.empty());
td_->download_manager_->update_file_viewed(file_view.file_id(), file_source_id);
td_->download_manager_->update_file_viewed(file_view.get_main_file_id(), file_source_id);
}
}
@ -22860,8 +22860,8 @@ void MessagesManager::remove_message_file_sources(DialogId dialog_id, const Mess
if (file_source_id.is_valid()) {
for (auto file_id : file_ids) {
auto file_view = td_->file_manager_->get_file_view(file_id);
send_closure(td_->download_manager_actor_, &DownloadManager::remove_file, file_view.file_id(), file_source_id,
false);
send_closure(td_->download_manager_actor_, &DownloadManager::remove_file, file_view.get_main_file_id(),
file_source_id, false);
td_->file_manager_->remove_file_source(file_id, file_source_id);
}
}
@ -22887,8 +22887,8 @@ void MessagesManager::change_message_files(DialogId dialog_id, const Message *m,
}
if (file_source_id.is_valid()) {
auto file_view = td_->file_manager_->get_file_view(file_id);
send_closure(td_->download_manager_actor_, &DownloadManager::remove_file, file_view.file_id(), file_source_id,
false);
send_closure(td_->download_manager_actor_, &DownloadManager::remove_file, file_view.get_main_file_id(),
file_source_id, false);
}
}
}
@ -35244,7 +35244,7 @@ bool MessagesManager::need_delete_file(FullMessageId full_message_id, FileId fil
return false;
}
auto main_file_id = td_->file_manager_->get_file_view(file_id).file_id();
auto main_file_id = td_->file_manager_->get_file_view(file_id).get_main_file_id();
auto full_message_ids = td_->file_reference_manager_->get_some_message_file_sources(main_file_id);
LOG(INFO) << "Receive " << full_message_ids << " as sources for file " << main_file_id << "/" << file_id << " from "
<< full_message_id;
@ -36011,7 +36011,7 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me
auto search_text = get_message_search_text(old_message);
for (auto file_id : file_ids) {
auto file_view = td_->file_manager_->get_file_view(file_id);
send_closure(td_->download_manager_actor_, &DownloadManager::change_search_text, file_view.file_id(),
send_closure(td_->download_manager_actor_, &DownloadManager::change_search_text, file_view.get_main_file_id(),
file_source_id, search_text);
}
}
@ -40090,12 +40090,12 @@ void MessagesManager::add_message_file_to_downloads(FullMessageId full_message_i
if (file_view.empty()) {
return promise.set_error(Status::Error(400, "File not found"));
}
file_id = file_view.file_id();
file_id = file_view.get_main_file_id();
bool is_found = false;
for (auto message_file_id : get_message_file_ids(m)) {
auto message_file_view = td_->file_manager_->get_file_view(message_file_id);
CHECK(!message_file_view.empty());
if (message_file_view.file_id() == file_id) {
if (message_file_view.get_main_file_id() == file_id) {
is_found = true;
}
}

View File

@ -818,7 +818,7 @@ FileId NotificationSettingsManager::get_saved_ringtone(int64 ringtone_id, Promis
CHECK(file_view.get_type() == FileType::Ringtone);
CHECK(file_view.has_remote_location());
if (file_view.remote_location().get_id() == ringtone_id) {
return file_view.file_id();
return file_view.get_main_file_id();
}
}
return {};
@ -898,7 +898,7 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
return promise.set_error(Status::Error(400, "Can't use web document as notification sound"));
}
FileId ringtone_file_id = file_view.file_id();
FileId ringtone_file_id = file_view.get_main_file_id();
if (file_type != FileType::Ringtone) {
if (file_type != FileType::Audio && file_type != FileType::VoiceNote) {
return promise.set_error(Status::Error(400, "Unsupported file specified"));
@ -920,7 +920,7 @@ void NotificationSettingsManager::add_saved_ringtone(td_api::object_ptr<td_api::
}
send_save_ringtone_query(
file_view.file_id(), false,
file_view.get_main_file_id(), false,
PromiseCreator::lambda(
[actor_id = actor_id(this), file_id = ringtone_file_id, promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&result) mutable {
@ -982,9 +982,9 @@ void NotificationSettingsManager::on_upload_ringtone(FileId file_id,
}
send_save_ringtone_query(
file_view.file_id(), false,
file_view.get_main_file_id(), false,
PromiseCreator::lambda(
[actor_id = actor_id(this), file_id = file_view.file_id(), promise = std::move(promise)](
[actor_id = actor_id(this), file_id = file_view.get_main_file_id(), promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&result) mutable {
if (result.is_error()) {
promise.set_error(result.move_as_error());
@ -1091,7 +1091,7 @@ void NotificationSettingsManager::remove_saved_ringtone(int64 ringtone_id, Promi
CHECK(file_view.has_remote_location());
if (file_view.remote_location().get_id() == ringtone_id) {
send_save_ringtone_query(
file_view.file_id(), true,
file_view.get_main_file_id(), true,
PromiseCreator::lambda(
[actor_id = actor_id(this), ringtone_id, promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::account_SavedRingtone>> &&result) mutable {

View File

@ -412,12 +412,12 @@ void SetSecureValue::start_up() {
// Remove duplicate files
FileId front_side_file_id;
if (secure_value_.front_side.file_id.is_valid()) {
front_side_file_id = file_manager->get_file_view(secure_value_.front_side.file_id).file_id();
front_side_file_id = file_manager->get_file_view(secure_value_.front_side.file_id).get_main_file_id();
front_side_ = SecureInputFile();
}
FileId reverse_side_file_id;
if (secure_value_.reverse_side.file_id.is_valid()) {
reverse_side_file_id = file_manager->get_file_view(secure_value_.reverse_side.file_id).file_id();
reverse_side_file_id = file_manager->get_file_view(secure_value_.reverse_side.file_id).get_main_file_id();
reverse_side_ = SecureInputFile();
if (front_side_file_id == reverse_side_file_id) {
return on_error(Status::Error(400, "Front side and reverse side must be different"));
@ -425,7 +425,7 @@ void SetSecureValue::start_up() {
}
FileId selfie_file_id;
if (secure_value_.selfie.file_id.is_valid()) {
selfie_file_id = file_manager->get_file_view(secure_value_.selfie.file_id).file_id();
selfie_file_id = file_manager->get_file_view(secure_value_.selfie.file_id).get_main_file_id();
selfie_ = SecureInputFile();
if (front_side_file_id == selfie_file_id) {
return on_error(Status::Error(400, "Front side and selfie must be different"));
@ -440,10 +440,10 @@ void SetSecureValue::start_up() {
CHECK(!reverse_side_file_id.is_valid());
CHECK(!selfie_file_id.is_valid());
for (auto it = secure_value_.files.begin(); it != secure_value_.files.end();) {
auto file_id = file_manager->get_file_view(it->file_id).file_id();
auto file_id = file_manager->get_file_view(it->file_id).get_main_file_id();
bool is_duplicate = false;
for (auto other_it = secure_value_.files.begin(); other_it != it; ++other_it) {
if (file_id == file_manager->get_file_view(other_it->file_id).file_id()) {
if (file_id == file_manager->get_file_view(other_it->file_id).get_main_file_id()) {
is_duplicate = true;
break;
}
@ -457,16 +457,16 @@ void SetSecureValue::start_up() {
}
if (!secure_value_.translations.empty()) {
for (auto it = secure_value_.translations.begin(); it != secure_value_.translations.end();) {
auto file_id = file_manager->get_file_view(it->file_id).file_id();
auto file_id = file_manager->get_file_view(it->file_id).get_main_file_id();
bool is_duplicate = file_id == front_side_file_id || file_id == reverse_side_file_id || file_id == selfie_file_id;
for (auto other_it = secure_value_.translations.begin(); other_it != it; ++other_it) {
if (file_id == file_manager->get_file_view(other_it->file_id).file_id()) {
if (file_id == file_manager->get_file_view(other_it->file_id).get_main_file_id()) {
is_duplicate = true;
break;
}
}
for (auto &dated_file : secure_value_.files) {
if (file_id == file_manager->get_file_view(dated_file.file_id).file_id()) {
if (file_id == file_manager->get_file_view(dated_file.file_id).get_main_file_id()) {
is_duplicate = true;
break;
}

View File

@ -393,8 +393,8 @@ telegram_api::object_ptr<telegram_api::InputSecureFile> get_input_secure_file_ob
return nullptr;
}
CHECK(input_file.file_id.is_valid());
CHECK(file_manager->get_file_view(file.file.file_id).file_id() ==
file_manager->get_file_view(input_file.file_id).file_id());
CHECK(file_manager->get_file_view(file.file.file_id).get_main_file_id() ==
file_manager->get_file_view(input_file.file_id).get_main_file_id());
auto res = std::move(input_file.input_file);
if (res == nullptr) {
return file_manager->get_file_view(file.file.file_id).remote_location().as_input_secure_file();

View File

@ -1911,9 +1911,9 @@ void FileManager::flush_to_pmc(FileNodePtr node, bool new_remote, bool new_local
data.encryption_key_ = node->encryption_key_;
data.url_ = node->url_;
data.owner_dialog_id_ = node->owner_dialog_id_;
data.file_source_ids_ = context_->get_some_file_sources(view.file_id());
VLOG(file_references) << "Save file " << view.file_id() << " to database with " << data.file_source_ids_ << " from "
<< source;
data.file_source_ids_ = context_->get_some_file_sources(view.get_main_file_id());
VLOG(file_references) << "Save file " << view.get_main_file_id() << " to database with " << data.file_source_ids_
<< " from " << source;
file_db_->set_file_data(node->pmc_id_, data, (create_flag || new_remote), (create_flag || new_local),
(create_flag || new_generate));
@ -1971,7 +1971,7 @@ void FileManager::load_from_pmc(FileNodePtr node, bool new_remote, bool new_loca
generate = file_view.generate_location();
}
LOG(DEBUG) << "Load from pmc " << file_id << "/" << file_view.file_id() << ", new_remote = " << new_remote
LOG(DEBUG) << "Load from pmc " << file_id << "/" << file_view.get_main_file_id() << ", new_remote = " << new_remote
<< ", new_local = " << new_local << ", new_generate = " << new_generate;
auto load = [&](auto location) {
TRY_RESULT(file_data, file_db_->get_file_data_sync(location));
@ -2142,7 +2142,7 @@ void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char
auto file_view = FileView(node);
send_closure(G()->download_manager(), &DownloadManager::remove_file_if_finished, file_view.file_id());
send_closure(G()->download_manager(), &DownloadManager::remove_file_if_finished, file_view.get_main_file_id());
string path;
if (file_view.has_local_location()) {
if (begins_with(file_view.local_location().path_, get_files_dir(file_view.get_type()))) {
@ -3016,13 +3016,13 @@ td_api::object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bo
auto *file_info = get_file_id_info(result_file_id);
if (with_main_file_id) {
if (!file_info->send_updates_flag_) {
result_file_id = file_view.file_id();
result_file_id = file_view.get_main_file_id();
}
file_info = get_file_id_info(file_view.file_id());
file_info = get_file_id_info(file_view.get_main_file_id());
}
file_info->send_updates_flag_ = true;
VLOG(update_file) << "Send file " << file_id << " as " << result_file_id << " and update send_updates_flag_ for file "
<< (with_main_file_id ? file_view.file_id() : result_file_id);
<< (with_main_file_id ? file_view.get_main_file_id() : result_file_id);
return td_api::make_object<td_api::file>(
result_file_id.get(), size, expected_size,
@ -3040,9 +3040,9 @@ vector<int32> FileManager::get_file_ids_object(const vector<FileId> &file_ids, b
auto *file_info = get_file_id_info(result_file_id);
if (with_main_file_id) {
if (!file_info->sent_file_id_flag_ && !file_info->send_updates_flag_) {
result_file_id = file_view.file_id();
result_file_id = file_view.get_main_file_id();
}
file_info = get_file_id_info(file_view.file_id());
file_info = get_file_id_info(file_view.get_main_file_id());
}
file_info->sent_file_id_flag_ = true;

View File

@ -268,7 +268,7 @@ class FileView {
bool get_by_hash() const;
FileId file_id() const {
FileId get_main_file_id() const {
return node_->main_file_id_;
}