Better suggested name for sticker thumbnails.

GitOrigin-RevId: 5372a13825f558e47ee84bfaa705af6a9b587298
This commit is contained in:
levlam 2018-06-01 01:23:07 +03:00
parent 804827cfda
commit 8750c7a41a
6 changed files with 47 additions and 14 deletions

View File

@ -128,6 +128,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
FileType file_type = FileType::Document;
Slice default_extension;
bool supports_streaming = false;
bool has_webp_thumbnail = false;
if (type_attributes == 1 || default_document_type != DocumentType::General) { // not a general document
if (animated != nullptr || default_document_type == DocumentType::Animation) {
document_type = DocumentType::Animation;
@ -155,6 +156,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
default_extension = "webp";
owner_dialog_id = DialogId();
file_name.clear();
has_webp_thumbnail = td_->stickers_manager_->has_webp_thumbnail(sticker);
} else if (video != nullptr || default_document_type == DocumentType::Video ||
default_document_type == DocumentType::VideoNote) {
bool is_video_note = default_document_type == DocumentType::VideoNote;
@ -202,7 +204,7 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
if (document_type != DocumentType::VoiceNote) {
thumbnail = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, owner_dialog_id,
std::move(document->thumb_));
std::move(document->thumb_), has_webp_thumbnail);
}
} else if (remote_document.secret_file != nullptr) {
CHECK(remote_document.secret_document != nullptr);

View File

@ -61,7 +61,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimen
static FileId register_photo(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
tl_object_ptr<telegram_api::FileLocation> &&location_ptr, DialogId owner_dialog_id,
int32 file_size) {
int32 file_size, bool is_webp = false) {
int32 location_id = location_ptr->get_id();
DcId dc_id;
int32 local_id;
@ -93,9 +93,11 @@ static FileId register_photo(FileManager *file_manager, FileType file_type, int6
break;
}
LOG(DEBUG) << "Receive photo of type " << static_cast<int8>(file_type) << " in [" << dc_id << "," << volume_id << ","
<< local_id << "]. Id: (" << id << ", " << access_hash << ")";
auto suggested_name = PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id) << ".jpg";
LOG(DEBUG) << "Receive " << (is_webp ? "webp" : "jpeg") << " photo of type " << static_cast<int8>(file_type)
<< " in [" << dc_id << "," << volume_id << "," << local_id << "]. Id: (" << id << ", " << access_hash
<< ")";
auto suggested_name = PSTRING() << static_cast<uint64>(volume_id) << "_" << static_cast<uint64>(local_id)
<< (is_webp ? ".webp" : ".jpg");
return file_manager->register_remote(
FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret, dc_id),
FileLocationSource::FromServer, owner_dialog_id, file_size, 0, std::move(suggested_name));
@ -235,7 +237,7 @@ PhotoSize get_thumbnail_photo_size(FileManager *file_manager, BufferSlice bytes,
}
PhotoSize get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
DialogId owner_dialog_id, tl_object_ptr<telegram_api::PhotoSize> &&size_ptr) {
DialogId owner_dialog_id, tl_object_ptr<telegram_api::PhotoSize> &&size_ptr, bool is_webp) {
tl_object_ptr<telegram_api::FileLocation> location_ptr;
string type;
@ -275,8 +277,8 @@ PhotoSize get_photo_size(FileManager *file_manager, FileType file_type, int64 id
break;
}
res.file_id =
register_photo(file_manager, file_type, id, access_hash, std::move(location_ptr), owner_dialog_id, res.size);
res.file_id = register_photo(file_manager, file_type, id, access_hash, std::move(location_ptr), owner_dialog_id,
res.size, is_webp);
if (!content.empty()) {
file_manager->set_content(res.file_id, std::move(content));
@ -468,7 +470,7 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr<telegram_api::photo> &&
for (auto &size_ptr : photo->sizes_) {
res.photos.push_back(get_photo_size(file_manager, FileType::Photo, photo->id_, photo->access_hash_, owner_dialog_id,
std::move(size_ptr)));
std::move(size_ptr), false));
}
return res;

View File

@ -81,7 +81,7 @@ StringBuilder &operator<<(StringBuilder &string_builder, const DialogPhoto &dial
PhotoSize get_thumbnail_photo_size(FileManager *file_manager, BufferSlice bytes, DialogId owner_dialog_id, int32 width,
int32 height);
PhotoSize get_photo_size(FileManager *file_manager, FileType file_type, int64 id, int64 access_hash,
DialogId owner_dialog_id, tl_object_ptr<telegram_api::PhotoSize> &&size_ptr);
DialogId owner_dialog_id, tl_object_ptr<telegram_api::PhotoSize> &&size_ptr, bool is_webp);
PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_type, DialogId owner_dialog_id,
tl_object_ptr<telegram_api::WebDocument> web_document_ptr);
tl_object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size);

View File

@ -973,6 +973,14 @@ FileId StickersManager::on_get_sticker(std::unique_ptr<Sticker> new_sticker, boo
return file_id;
}
bool StickersManager::has_webp_thumbnail(const tl_object_ptr<telegram_api::documentAttributeSticker> &sticker) {
if (sticker == nullptr) {
return false;
}
return get_sticker_set_id(sticker->stickerset_) != 0;
}
std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<telegram_api::Document> &&document_ptr,
bool from_message) {
int32 document_constructor_id = document_ptr->get_id();
@ -1014,8 +1022,8 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
FullRemoteFileLocation(FileType::Sticker, document_id, document->access_hash_, DcId::internal(document->dc_id_)),
FileLocationSource::FromServer, DialogId(), document->size_, 0, to_string(document_id) + ".webp");
PhotoSize thumbnail =
get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, DialogId(), std::move(document->thumb_));
PhotoSize thumbnail = get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, DialogId(),
std::move(document->thumb_), has_webp_thumbnail(sticker));
create_sticker(sticker_id, std::move(thumbnail), dimensions, from_message, std::move(sticker), nullptr);
return {document_id, sticker_id};
@ -1059,6 +1067,23 @@ const StickersManager::StickerSet *StickersManager::get_sticker_set(int64 sticke
return sticker_set->second.get();
}
int64 StickersManager::get_sticker_set_id(const tl_object_ptr<telegram_api::InputStickerSet> &set_ptr) {
CHECK(set_ptr != nullptr);
switch (set_ptr->get_id()) {
case telegram_api::inputStickerSetEmpty::ID:
return 0;
case telegram_api::inputStickerSetID::ID:
return static_cast<const telegram_api::inputStickerSetID *>(set_ptr.get())->id_;
case telegram_api::inputStickerSetShortName::ID:
LOG(ERROR) << "Receive sticker set by its short name";
return search_sticker_set(static_cast<const telegram_api::inputStickerSetShortName *>(set_ptr.get())->short_name_,
Auto());
default:
UNREACHABLE();
return 0;
}
}
int64 StickersManager::add_sticker_set(tl_object_ptr<telegram_api::InputStickerSet> &&set_ptr) {
CHECK(set_ptr != nullptr);
switch (set_ptr->get_id()) {

View File

@ -71,6 +71,10 @@ class StickersManager : public Actor {
vector<int64> get_installed_sticker_sets(bool is_masks, Promise<Unit> &&promise);
bool has_webp_thumbnail(const tl_object_ptr<telegram_api::documentAttributeSticker> &sticker);
int64 get_sticker_set_id(const tl_object_ptr<telegram_api::InputStickerSet> &set_ptr);
int64 add_sticker_set(tl_object_ptr<telegram_api::InputStickerSet> &&set_ptr);
int64 get_sticker_set(int64 set_id, Promise<Unit> &&promise);

View File

@ -178,8 +178,8 @@ class GetWallpapersQuery : public Td::ResultHandler {
vector<tl_object_ptr<td_api::photoSize>> sizes;
sizes.reserve(wallpaper->sizes_.size());
for (auto &size_ptr : wallpaper->sizes_) {
auto photo_size =
get_photo_size(td->file_manager_.get(), FileType::Wallpaper, 0, 0, DialogId(), std::move(size_ptr));
auto photo_size = get_photo_size(td->file_manager_.get(), FileType::Wallpaper, 0, 0, DialogId(),
std::move(size_ptr), false);
sizes.push_back(get_photo_size_object(td->file_manager_.get(), &photo_size));
}
sort_photo_sizes(sizes);