FileManager: reload photo on FILE_ID_INVALID

GitOrigin-RevId: defb6736befa35189253f8ac70342be81a607918
This commit is contained in:
Arseny Smirnov 2019-07-30 17:42:36 +03:00
parent f78018be61
commit 089d73953c
7 changed files with 79 additions and 1 deletions

View File

@ -8907,6 +8907,19 @@ ContactsManager::User *ContactsManager::get_user(UserId user_id) {
}
}
void ContactsManager::reload_dialog(DialogId dialog_id, Promise<Unit> &&promise) {
switch (dialog_id.get_type()) {
case DialogType::User:
return reload_user(dialog_id.get_user_id(), std::move(promise));
case DialogType::Chat:
return reload_chat(dialog_id.get_chat_id(), std::move(promise));
case DialogType::Channel:
return reload_channel(dialog_id.get_channel_id(), std::move(promise));
default:
promise.set_error(Status::Error("Invalid dialog id to reload"));
}
}
void ContactsManager::send_get_me_query(Td *td, Promise<Unit> &&promise) {
vector<tl_object_ptr<telegram_api::InputUser>> users;
users.push_back(make_tl_object<telegram_api::inputUserSelf>());

View File

@ -351,6 +351,8 @@ class ContactsManager : public Actor {
bool have_min_user(UserId user_id) const;
bool have_user_force(UserId user_id);
void reload_dialog(DialogId dialog_id, Promise<Unit> &&promise);
static void send_get_me_query(Td *td, Promise<Unit> &&promise);
UserId get_me(Promise<Unit> &&promise);
bool get_user(UserId user_id, int left_tries, Promise<Unit> &&promise);

View File

@ -336,4 +336,18 @@ void FileReferenceManager::repair_file_reference(NodeId node_id, Promise<> promi
run_node(node_id);
}
void FileReferenceManager::reload_photo(PhotoSizeSource source, Promise<Unit> promise) {
switch (source.get_type()) {
case PhotoSizeSource::Type::DialogPhotoBig:
case PhotoSizeSource::Type::DialogPhotoSmall:
send_closure(G()->contacts_manager(), &ContactsManager::reload_dialog, source.dialog_photo().dialog_id,
std::move(promise));
break;
case PhotoSizeSource::Type::StickerSetThumbnail:
//TODO
default:
promise.set_error(Status::Error("Unexpected PotoSizeSource type"));
}
}
} // namespace td

View File

@ -15,6 +15,7 @@
#include "td/telegram/files/FileId.h"
#include "td/telegram/files/FileSourceId.h"
#include "td/telegram/MessageId.h"
#include "td/telegram/PhotoSizeSource.h"
#include "td/telegram/SetWithPosition.h"
#include "td/telegram/UserId.h"
@ -49,6 +50,7 @@ class FileReferenceManager : public Actor {
using NodeId = FileId;
void repair_file_reference(NodeId node_id, Promise<> promise);
void reload_photo(PhotoSizeSource source, Promise<Unit> promise);
bool add_file_source(NodeId node_id, FileSourceId file_source_id);

View File

@ -4502,6 +4502,10 @@ void Td::init_file_manager() {
std::move(promise));
}
void reload_photo(PhotoSizeSource source, Promise<Unit> promise) final {
send_closure(G()->file_reference_manager(), &FileReferenceManager::reload_photo, source, std::move(promise));
}
ActorShared<> create_reference() final {
return td_->create_reference();
}

View File

@ -2068,6 +2068,25 @@ void FileManager::run_download(FileNodePtr node) {
CHECK(!node->file_ids_.empty());
auto file_id = node->main_file_id_;
if (node->need_reload_photo_ && file_view.may_reload_photo()) {
QueryId id = queries_container_.create(Query{file_id, Query::DownloadReloadDialog});
node->download_id_ = id;
context_->reload_photo(file_view.remote_location().get_source(),
PromiseCreator::lambda([id, actor_id = actor_id(this), file_id](Result<Unit> res) {
Status error;
if (res.is_ok()) {
error = Status::Error("FILE_DOWNLOAD_ID_INVALID");
} else {
error = res.move_as_error();
}
VLOG(file_references)
<< "Got result from reload photo for file " << file_id << ": " << error;
send_closure(actor_id, &FileManager::on_error, id, std::move(error));
}));
node->need_reload_photo_ = false;
return;
}
// If file reference is needed
if (!file_view.has_active_download_remote_location()) {
VLOG(file_references) << "Do not have valid file_reference for file " << file_id;
@ -3358,6 +3377,13 @@ void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type,
if (begins_with(status.message(), "FILE_GENERATE_LOCATION_INVALID")) {
node->set_generate_location(nullptr);
}
if (status.message() == "FILE_ID_INVALID" && FileView(node).may_reload_photo()) {
node->need_reload_photo_ = true;
run_download(node);
return;
}
if (FileReferenceManager::is_file_reference_error(status)) {
string file_reference;
Slice prefix = "#BASE64";

View File

@ -159,8 +159,9 @@ class FileNode {
bool is_download_offset_dirty_ = false;
bool is_download_limit_dirty_ = false;
bool get_by_hash_ = false;
bool get_by_hash_{false};
bool can_search_locally_{true};
bool need_reload_photo_{false};
bool is_download_started_ = false;
bool generate_was_update_ = false;
@ -300,6 +301,19 @@ class FileView {
return node_->encryption_key_;
}
bool may_reload_photo() {
if (!has_remote_location()) {
return false;
}
if (!remote_location().is_photo()) {
return false;
}
auto type = remote_location().get_source().get_type();
return type == PhotoSizeSource::Type::DialogPhotoBig || type == PhotoSizeSource::Type::DialogPhotoSmall ||
type == PhotoSizeSource::Type::StickerSetThumbnail;
return false;
}
private:
ConstFileNodePtr node_{};
};
@ -354,6 +368,8 @@ class FileManager : public FileLoadManager::Callback {
virtual void repair_file_reference(FileId file_id, Promise<Unit> promise) = 0;
virtual void reload_photo(PhotoSizeSource source, Promise<Unit> promise) = 0;
virtual ActorShared<> create_reference() = 0;
Context() = default;
@ -475,6 +491,7 @@ class FileManager : public FileLoadManager::Callback {
UploadWaitFileReference,
Upload,
DownloadWaitFileReferece,
DownloadReloadDialog,
Download,
SetContent,
Generate