Better suggeste_name for thumbnails and profile photos.
GitOrigin-RevId: 4313c9677fcdc07131d19be36ba66fdb137558df
This commit is contained in:
parent
b314311c4d
commit
b9b35ebe0a
@ -35,7 +35,6 @@
|
|||||||
#include "td/utils/StringBuilder.h"
|
#include "td/utils/StringBuilder.h"
|
||||||
#include "td/utils/utf8.h"
|
#include "td/utils/utf8.h"
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -279,7 +278,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
|
|
||||||
auto suggested_file_name = file_name;
|
auto suggested_file_name = file_name;
|
||||||
if (suggested_file_name.empty()) {
|
if (suggested_file_name.empty()) {
|
||||||
suggested_file_name = to_string(std::abs(id));
|
suggested_file_name = to_string(static_cast<uint64>(id));
|
||||||
auto extension = MimeType::to_extension(mime_type, default_extension);
|
auto extension = MimeType::to_extension(mime_type, default_extension);
|
||||||
if (!extension.empty()) {
|
if (!extension.empty()) {
|
||||||
suggested_file_name += '.';
|
suggested_file_name += '.';
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include "td/utils/Random.h"
|
#include "td/utils/Random.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
@ -92,9 +91,15 @@ static FileId register_photo(FileManager *file_manager, FileType file_type, int6
|
|||||||
|
|
||||||
LOG(DEBUG) << "Receive photo of type " << static_cast<int8>(file_type) << " in [" << dc_id << "," << volume_id << ","
|
LOG(DEBUG) << "Receive photo of type " << static_cast<int8>(file_type) << " in [" << dc_id << "," << volume_id << ","
|
||||||
<< local_id << "]. Id: (" << id << ", " << access_hash << ")";
|
<< local_id << "]. Id: (" << id << ", " << access_hash << ")";
|
||||||
|
auto suggested_name = [&] {
|
||||||
|
if (id) {
|
||||||
|
return PSTRING() << static_cast<uint64>(id) << ".jpg";
|
||||||
|
}
|
||||||
|
return PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id) << ".jpg";
|
||||||
|
}();
|
||||||
return file_manager->register_remote(
|
return file_manager->register_remote(
|
||||||
FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret, dc_id),
|
FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret, dc_id),
|
||||||
FileLocationSource::FromServer, owner_dialog_id, file_size, 0, to_string(std::abs(id ? id : local_id)) + ".jpg");
|
FileLocationSource::FromServer, owner_dialog_id, file_size, 0, std::move(suggested_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfilePhoto get_profile_photo(FileManager *file_manager,
|
ProfilePhoto get_profile_photo(FileManager *file_manager,
|
||||||
@ -223,7 +228,8 @@ PhotoSize get_thumbnail_photo_size(FileManager *file_manager, BufferSlice bytes,
|
|||||||
auto secret = 0;
|
auto secret = 0;
|
||||||
res.file_id = file_manager->register_remote(
|
res.file_id = file_manager->register_remote(
|
||||||
FullRemoteFileLocation(FileType::EncryptedThumbnail, 0, 0, local_id, volume_id, secret, dc_id),
|
FullRemoteFileLocation(FileType::EncryptedThumbnail, 0, 0, local_id, volume_id, secret, dc_id),
|
||||||
FileLocationSource::FromServer, owner_dialog_id, res.size, 0, to_string(std::abs(local_id)) + ".jpg");
|
FileLocationSource::FromServer, owner_dialog_id, res.size, 0,
|
||||||
|
PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id) << ".jpg");
|
||||||
file_manager->set_content(res.file_id, std::move(bytes));
|
file_manager->set_content(res.file_id, std::move(bytes));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -402,7 +408,8 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr<telegram_api::encrypted
|
|||||||
CHECK(DcId::is_valid(file->dc_id_));
|
CHECK(DcId::is_valid(file->dc_id_));
|
||||||
FileId file_id = file_manager->register_remote(
|
FileId file_id = file_manager->register_remote(
|
||||||
FullRemoteFileLocation(FileType::Encrypted, file->id_, file->access_hash_, DcId::internal(file->dc_id_)),
|
FullRemoteFileLocation(FileType::Encrypted, file->id_, file->access_hash_, DcId::internal(file->dc_id_)),
|
||||||
FileLocationSource::FromServer, owner_dialog_id, photo->size_, 0, to_string(std::abs(file->id_)) + ".jpg");
|
FileLocationSource::FromServer, owner_dialog_id, photo->size_, 0,
|
||||||
|
PSTRING() << static_cast<uint64>(file->id_) << ".jpg");
|
||||||
file_manager->set_encryption_key(file_id, FileEncryptionKey{photo->key_.as_slice(), photo->iv_.as_slice()});
|
file_manager->set_encryption_key(file_id, FileEncryptionKey{photo->key_.as_slice(), photo->iv_.as_slice()});
|
||||||
|
|
||||||
Photo res;
|
Photo res;
|
||||||
|
Reference in New Issue
Block a user