Add FileManager::get_file_ids_object.

GitOrigin-RevId: a7e76f5e28514e2ccd99ce2316d5e4043836062f
This commit is contained in:
levlam 2019-01-21 20:19:02 +03:00
parent 0697962c3c
commit 8ac921b8e7
4 changed files with 25 additions and 13 deletions

View File

@ -709,7 +709,7 @@ void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::Input
td_api::object_ptr<td_api::updateSavedAnimations> AnimationsManager::get_update_saved_animations_object() const {
return td_api::make_object<td_api::updateSavedAnimations>(
transform(saved_animation_ids_, [](FileId animation_id) { return animation_id.get(); }));
td_->file_manager_->get_file_ids_object(saved_animation_ids_));
}
void AnimationsManager::send_update_saved_animations(bool from_database) {

View File

@ -3857,8 +3857,7 @@ void StickersManager::clear_recent_stickers(bool is_attached, Promise<Unit> &&pr
td_api::object_ptr<td_api::updateRecentStickers> StickersManager::get_update_recent_stickers_object(
int is_attached) const {
return td_api::make_object<td_api::updateRecentStickers>(
is_attached != 0,
transform(recent_sticker_ids_[is_attached], [](FileId sticker_id) { return sticker_id.get(); }));
is_attached != 0, td_->file_manager_->get_file_ids_object(recent_sticker_ids_[is_attached]));
}
void StickersManager::send_update_recent_stickers(bool from_database) {
@ -4177,8 +4176,8 @@ void StickersManager::remove_favorite_sticker(const tl_object_ptr<td_api::InputF
}
td_api::object_ptr<td_api::updateFavoriteStickers> StickersManager::get_update_favorite_stickers_object() const {
return make_tl_object<td_api::updateFavoriteStickers>(
transform(favorite_sticker_ids_, [](FileId sticker_id) { return sticker_id.get(); }));
return td_api::make_object<td_api::updateFavoriteStickers>(
td_->file_manager_->get_file_ids_object(favorite_sticker_ids_));
}
void StickersManager::send_update_favorite_stickers(bool from_database) {

View File

@ -758,9 +758,10 @@ FileId FileManager::create_file_id(int32 file_node_id, FileNode *file_node) {
file_node->file_ids_.push_back(file_id);
return file_id;
}
void FileManager::try_forget_file_id(FileId file_id) {
auto *info = get_file_id_info(file_id);
if (info->send_updates_flag_ || info->pin_flag_) {
if (info->send_updates_flag_ || info->pin_flag_ || info->sent_file_id_flag_) {
return;
}
auto file_node = get_file_node(file_id);
@ -2216,7 +2217,7 @@ FileView FileManager::get_sync_file_view(FileId file_id) {
return FileView(file_node);
}
tl_object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bool with_main_file_id) {
td_api::object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bool with_main_file_id) {
auto file_view = get_sync_file_view(file_id);
if (file_view.empty()) {
@ -2265,10 +2266,21 @@ tl_object_ptr<td_api::file> FileManager::get_file_object(FileId file_id, bool wi
is_uploading_completed, remote_size));
}
vector<tl_object_ptr<td_api::file>> FileManager::get_files_object(const vector<FileId> &file_ids,
bool with_main_file_id) {
return transform(file_ids,
[this, with_main_file_id](FileId file_id) { return get_file_object(file_id, with_main_file_id); });
vector<int32> FileManager::get_file_ids_object(const vector<FileId> &file_ids, bool with_main_file_id) {
return transform(file_ids, [this, with_main_file_id](FileId file_id) {
auto file_view = get_sync_file_view(file_id);
auto result_file_id = file_id;
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();
}
file_info = get_file_id_info(file_view.file_id());
}
file_info->sent_file_id_flag_ = true;
return result_file_id.get();
});
}
Result<FileId> FileManager::check_input_file_id(FileType type, Result<FileId> result, bool is_encrypted,

View File

@ -379,8 +379,8 @@ class FileManager : public FileLoadManager::Callback {
Result<FileId> from_persistent_id(CSlice persistent_id, FileType file_type) TD_WARN_UNUSED_RESULT;
FileView get_file_view(FileId file_id) const;
FileView get_sync_file_view(FileId file_id);
tl_object_ptr<td_api::file> get_file_object(FileId file_id, bool with_main_file_id = true);
vector<tl_object_ptr<td_api::file>> get_files_object(const vector<FileId> &file_ids, bool with_main_file_id = true);
td_api::object_ptr<td_api::file> get_file_object(FileId file_id, bool with_main_file_id = true);
vector<int32> get_file_ids_object(const vector<FileId> &file_ids, bool with_main_file_id = true);
Result<FileId> get_input_thumbnail_file_id(const tl_object_ptr<td_api::InputFile> &thumb_input_file,
DialogId owner_dialog_id, bool is_encrypted) TD_WARN_UNUSED_RESULT;
@ -428,6 +428,7 @@ class FileManager : public FileLoadManager::Callback {
FileNodeId node_id_{0};
bool send_updates_flag_{false};
bool pin_flag_{false};
bool sent_file_id_flag_{false};
int8 download_priority_{0};
int8 upload_priority_{0};