Add new updates about file downloads.
This commit is contained in:
parent
04aabd8825
commit
a79ae236bc
@ -3950,7 +3950,15 @@ updateFileGenerationStop generation_id:int64 = Update;
|
||||
//@downloaded_size Total downloaded size of files in the file download list, in bytes
|
||||
updateFileDownloads total_size:int53 total_count:int32 downloaded_size:int53 = Update;
|
||||
|
||||
//@description A file was removed from the file download list @file_id File identifier
|
||||
//@description A file was added to the file download list. This update is sent only after file download list is loaded for the first time @file_download The added file download
|
||||
updateFileAddedToDownloads file_download:fileDownload = Update;
|
||||
|
||||
//@description A file download was changed. This update is sent only after file download list is loaded for the first time @file_id File identifier
|
||||
//@complete_date Point in time (Unix timestamp) when the file downloading was completed; 0 if the file downloading isn't completed
|
||||
//@is_paused True, if downloading of the file is paused
|
||||
updateFileDownload file_id:int32 complete_date:int32 is_paused:Bool = Update;
|
||||
|
||||
//@description A file was removed from the file download list. This update is sent only after file download list is loaded for the first time @file_id File identifier
|
||||
updateFileRemovedFromDownloads file_id:int32 = Update;
|
||||
|
||||
//@description New call was created or information about a call was updated @call New data about a call
|
||||
|
@ -117,7 +117,9 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
|
||||
remove_from_database(file_info);
|
||||
files_.erase(download_id);
|
||||
if (is_search_inited_) {
|
||||
callback_->update_file_removed(file_id);
|
||||
}
|
||||
|
||||
update_counters();
|
||||
on_file_viewed(download_id);
|
||||
@ -306,6 +308,10 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
if (is_paused && file_info.is_paused != is_paused) {
|
||||
file_info.is_paused = is_paused;
|
||||
file_info.need_save_to_database = true;
|
||||
|
||||
if (is_search_inited_) {
|
||||
callback_->update_file_changed(file_info.file_id, file_info.completed_at, file_info.is_paused);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -569,6 +575,10 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
actor_shared(this, it->second->link_token));
|
||||
}
|
||||
}
|
||||
if (is_search_inited_) {
|
||||
callback_->update_file_added(it->second->file_id, it->second->file_source_id, it->second->created_at,
|
||||
it->second->completed_at, it->second->is_paused);
|
||||
}
|
||||
}
|
||||
|
||||
void timeout_expired() final {
|
||||
@ -613,6 +623,9 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
} else {
|
||||
callback_->start_file(file_info.internal_file_id, file_info.priority, actor_shared(this, file_info.link_token));
|
||||
}
|
||||
if (is_search_inited_) {
|
||||
callback_->update_file_changed(file_info.file_id, file_info.completed_at, file_info.is_paused);
|
||||
}
|
||||
}
|
||||
|
||||
void update_counters() {
|
||||
@ -689,6 +702,10 @@ class DownloadManagerImpl final : public DownloadManager {
|
||||
if (file_info.is_counted) {
|
||||
unviewed_completed_download_ids_.insert(file_info.download_id);
|
||||
}
|
||||
|
||||
if (is_search_inited_) {
|
||||
callback_->update_file_changed(file_info.file_id, file_info.completed_at, file_info.is_paused);
|
||||
}
|
||||
}
|
||||
if (file_info.is_counted && (is_completed(file_info) || !file_info.is_paused)) {
|
||||
counters_.downloaded_size += file_info.downloaded_size;
|
||||
|
@ -45,6 +45,9 @@ class DownloadManager : public Actor {
|
||||
public:
|
||||
virtual ~Callback() = default;
|
||||
virtual void update_counters(Counters counters) = 0;
|
||||
virtual void update_file_added(FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date,
|
||||
bool is_paused) = 0;
|
||||
virtual void update_file_changed(FileId file_id, int32 complete_date, bool is_paused) = 0;
|
||||
virtual void update_file_removed(FileId file_id) = 0;
|
||||
virtual void start_file(FileId file_id, int8 priority, ActorShared<DownloadManager> download_manager) = 0;
|
||||
virtual void pause_file(FileId file_id) = 0;
|
||||
|
@ -22,6 +22,18 @@ void DownloadManagerCallback::update_counters(DownloadManager::Counters counters
|
||||
send_closure(td_->actor_id(td_), &Td::send_update, counters.get_update_file_downloads_object());
|
||||
}
|
||||
|
||||
void DownloadManagerCallback::update_file_added(FileId file_id, FileSourceId file_source_id, int32 add_date,
|
||||
int32 complete_date, bool is_paused) {
|
||||
send_closure(td_->actor_id(td_), &Td::send_update,
|
||||
td_api::make_object<td_api::updateFileAddedToDownloads>(
|
||||
get_file_download_object(file_id, file_source_id, add_date, complete_date, is_paused)));
|
||||
}
|
||||
|
||||
void DownloadManagerCallback::update_file_changed(FileId file_id, int32 complete_date, bool is_paused) {
|
||||
send_closure(td_->actor_id(td_), &Td::send_update,
|
||||
td_api::make_object<td_api::updateFileDownload>(file_id.get(), complete_date, is_paused));
|
||||
}
|
||||
|
||||
void DownloadManagerCallback::update_file_removed(FileId file_id) {
|
||||
send_closure(td_->actor_id(td_), &Td::send_update,
|
||||
td_api::make_object<td_api::updateFileRemovedFromDownloads>(file_id.get()));
|
||||
@ -73,7 +85,7 @@ std::shared_ptr<FileManager::DownloadCallback> DownloadManagerCallback::make_dow
|
||||
send_update(file_id, false);
|
||||
}
|
||||
void on_download_ok(FileId file_id) final {
|
||||
send_update(file_id, true);
|
||||
send_update(file_id, false);
|
||||
}
|
||||
void on_download_error(FileId file_id, Status error) final {
|
||||
send_update(file_id, true);
|
||||
|
@ -26,6 +26,11 @@ class DownloadManagerCallback final : public DownloadManager::Callback {
|
||||
|
||||
void update_counters(DownloadManager::Counters counters) final;
|
||||
|
||||
void update_file_added(FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date,
|
||||
bool is_paused) final;
|
||||
|
||||
void update_file_changed(FileId file_id, int32 complete_date, bool is_paused) final;
|
||||
|
||||
void update_file_removed(FileId file_id) final;
|
||||
|
||||
void start_file(FileId file_id, int8 priority, ActorShared<DownloadManager> download_manager) final;
|
||||
|
@ -4064,6 +4064,9 @@ void Td::send_update(tl_object_ptr<td_api::Update> &&object) {
|
||||
case td_api::updateChatAction::ID / 2:
|
||||
case td_api::updateChatFilters::ID / 2:
|
||||
case td_api::updateChatPosition::ID / 2:
|
||||
case td_api::updateFileAddedToDownloads::ID:
|
||||
case td_api::updateFileDownload::ID:
|
||||
case td_api::updateFileRemovedFromDownloads::ID:
|
||||
LOG(ERROR) << "Sending update: " << oneline(to_string(object));
|
||||
break;
|
||||
default:
|
||||
|
@ -1120,7 +1120,7 @@ void FileManager::on_file_unlink(const FullLocalFileLocation &location) {
|
||||
auto file_id = it->second;
|
||||
auto file_node = get_sync_file_node(file_id);
|
||||
CHECK(file_node);
|
||||
send_closure(G()->download_manager(), &DownloadManager::remove_file, file_node->main_file_id_, FileSourceId{}, false);
|
||||
send_closure(G()->download_manager(), &DownloadManager::remove_file_if_finished, file_node->main_file_id_, FileSourceId{}, false);
|
||||
file_node->drop_local_location();
|
||||
try_flush_node_info(file_node, "on_file_unlink");
|
||||
}
|
||||
@ -2146,7 +2146,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, file_view.file_id(), FileSourceId{}, false);
|
||||
send_closure(G()->download_manager(), &DownloadManager::remove_file_if_finished, file_view.file_id(), FileSourceId{}, false);
|
||||
// TODO review delete condition
|
||||
if (file_view.has_local_location()) {
|
||||
if (begins_with(file_view.local_location().path_, get_files_dir(file_view.get_type()))) {
|
||||
|
Loading…
Reference in New Issue
Block a user