Add FileReferenceManager::get_file_info.

This commit is contained in:
levlam 2022-02-26 21:52:14 +03:00
parent 29f8f79b16
commit 4524ba0380
7 changed files with 47 additions and 5 deletions

View File

@ -508,6 +508,7 @@ set(TDLIB_SOURCE
td/telegram/Document.h
td/telegram/DocumentsManager.h
td/telegram/DownloadManager.h
td/telegram/DownloadsDb.h
td/telegram/DraftMessage.h
td/telegram/EncryptedFile.h
td/telegram/FileReferenceManager.h

View File

@ -6,12 +6,12 @@
//
#include "td/telegram/DownloadManager.h"
#include "td/utils/FlatHashMap.h"
#include "td/telegram/DownloadsDb.h"
#include "td/telegram/Global.h"
#include "td/telegram/TdDb.h"
#include "td/utils/FlatHashMap.h"
namespace td {
class DownloadManagerImpl final : public DownloadManager {
@ -50,7 +50,7 @@ class DownloadManagerImpl final : public DownloadManager {
return Status::Error("TODO: code and message`");
}
for (auto &it : active_files_) {
toggle_is_paused(it.key(), is_paused);
toggle_is_paused(it.first, is_paused);
}
// TODO: update db
@ -132,7 +132,7 @@ class DownloadManagerImpl final : public DownloadManager {
TRY_RESULT_PROMISE(promise, offset_int64, to_integer_safe<int64>(offset));
// TODO: only active, only completed
G()->td_db()->get_downloads_db_async()->get_downloads_fts(DownloadsDbFtsQuery{query, offset_int64, limit},
[](Result<Unit>) {});
[](Result<DownloadsDbFtsResult>) {});
return promise.set_value({});
}

View File

@ -247,7 +247,7 @@ class DownloadsDbAsync final : public DownloadsDbAsyncInterface {
promise.set_result(sync_db_->get_downloads_fts(std::move(query)));
}
void get_active_downloads(Promise<> promise) {
void get_active_downloads(Promise<GetActiveDownloadsResult> promise) {
add_read_query();
promise.set_result(sync_db_->get_active_downloads());
}

View File

@ -394,4 +394,16 @@ void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> pr
}
}
void FileReferenceManager::get_file_info(FileSourceId file_source_id, string unique_file_id,
Promise<FileSearchInfo> promise) {
auto index = static_cast<size_t>(file_source_id.get()) - 1;
CHECK(index < file_sources_.size());
file_sources_[index].visit(overloaded(
[&](const FileSourceMessage &source) {
send_closure_later(G()->messages_manager(), &MessagesManager::get_message_file_info, source.full_message_id,
std::move(unique_file_id), std::move(promise));
},
[&](const auto &source) { promise.set_error(Status::Error(500, "Unsupported file source")); }));
}
} // namespace td

View File

@ -32,6 +32,11 @@ class Td;
extern int VERBOSITY_NAME(file_references);
struct FileSearchInfo {
FileId file_id;
string search_text;
};
class FileReferenceManager final : public Actor {
public:
static bool is_file_reference_error(const Status &error);
@ -55,6 +60,8 @@ class FileReferenceManager final : public Actor {
using NodeId = FileId;
void repair_file_reference(NodeId node_id, Promise<> promise);
void get_file_info(FileSourceId file_source_id, string unique_file_id, Promise<FileSearchInfo> promise);
static void reload_photo(PhotoSizeSource source, Promise<Unit> promise);
bool add_file_source(NodeId node_id, FileSourceId file_source_id);

View File

@ -39816,4 +39816,23 @@ void MessagesManager::add_message_file_to_downloads(FullMessageId full_message_i
promise.set_value(td_->file_manager_->get_file_object(file_id));
}
void MessagesManager::get_message_file_info(FullMessageId full_message_id, string unique_file_id,
Promise<FileSearchInfo> promise) {
auto m = get_message_force(full_message_id, "add_message_file_to_downloads");
if (m == nullptr) {
return promise.set_error(Status::Error(200, "Message not found"));
}
for (auto file_id : get_message_file_ids(m)) {
auto file_view = td_->file_manager_->get_file_view(file_id);
CHECK(!file_view.empty());
if (file_view.get_unique_file_id() == unique_file_id) {
FileSearchInfo info;
info.file_id = file_id;
info.search_text = get_message_search_text(m);
return promise.set_value(std::move(info));
}
}
return promise.set_error(Status::Error(200, "File not found"));
}
} // namespace td

View File

@ -90,6 +90,7 @@ struct Dependencies;
class DialogActionBar;
class DialogFilter;
class DraftMessage;
struct FileSearchInfo;
struct InputMessageContent;
class MessageContent;
struct MessageReactions;
@ -983,6 +984,8 @@ class MessagesManager final : public Actor {
void add_message_file_to_downloads(FullMessageId full_message_id, FileId file_id, int32 priority,
Promise<td_api::object_ptr<td_api::file>> promise);
void get_message_file_info(FullMessageId full_message_id, string unique_file_id, Promise<FileSearchInfo> promise);
private:
class PendingPtsUpdate {
public: