Support thumbnail_document_id.

This commit is contained in:
levlam 2022-07-16 17:22:30 +03:00
parent 577d48cba5
commit 32c7bd8bcd
3 changed files with 40 additions and 0 deletions

View File

@ -2031,6 +2031,22 @@ double StickersManager::get_sticker_set_minithumbnail_zoom(const StickerSet *sti
td_api::object_ptr<td_api::thumbnail> StickersManager::get_sticker_set_thumbnail_object(
const StickerSet *sticker_set) const {
CHECK(sticker_set != nullptr);
if (sticker_set->thumbnail_document_id != 0 && sticker_set->sticker_type == StickerType::Emoji) {
for (auto sticker_id : sticker_set->sticker_ids) {
auto file_view = td_->file_manager_->get_file_view(sticker_id);
if (file_view.has_remote_location() && !file_view.remote_location().is_web() &&
file_view.remote_location().get_id() == sticker_set->thumbnail_document_id) {
const Sticker *s = get_sticker(sticker_id);
auto thumbnail_format = get_sticker_set_thumbnail_format(s->format);
PhotoSize thumbnail;
thumbnail.type = 't';
thumbnail.size = static_cast<int32>(file_view.size());
thumbnail.dimensions = s->dimensions;
thumbnail.file_id = s->file_id;
return get_thumbnail_object(td_->file_manager_.get(), thumbnail, thumbnail_format);
}
}
}
auto thumbnail_format = get_sticker_set_thumbnail_format(sticker_set->sticker_format);
return get_thumbnail_object(td_->file_manager_.get(), sticker_set->thumbnail, thumbnail_format);
}
@ -3006,6 +3022,7 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
PhotoSize thumbnail;
string minithumbnail;
int64 thumbnail_document_id = 0;
for (auto &thumb : set->thumbs_) {
auto photo_size =
get_photo_size(td_->file_manager_.get(),
@ -3020,6 +3037,9 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
minithumbnail = std::move(photo_size.get<1>());
}
}
if ((set->flags_ & telegram_api::stickerSet::THUMB_DOCUMENT_ID_MASK) != 0) {
thumbnail_document_id = set->thumb_document_id_;
}
if (!s->is_inited) {
LOG(INFO) << "Init " << set_id;
s->is_inited = true;
@ -3029,6 +3049,7 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
s->minithumbnail = std::move(minithumbnail);
}
s->thumbnail = std::move(thumbnail);
s->thumbnail_document_id = thumbnail_document_id;
s->is_thumbnail_reloaded = true;
s->are_legacy_sticker_thumbnails_reloaded = true;
s->sticker_count = set->count_;
@ -3076,6 +3097,12 @@ StickerSetId StickersManager::on_get_sticker_set(tl_object_ptr<telegram_api::sti
s->thumbnail = std::move(thumbnail);
s->is_changed = true;
}
if (s->thumbnail_document_id != thumbnail_document_id) {
LOG(INFO) << "Thumbnail of " << set_id << " has changed from " << s->thumbnail_document_id << " to "
<< thumbnail_document_id;
s->thumbnail_document_id = thumbnail_document_id;
s->is_changed = true;
}
if (!s->is_thumbnail_reloaded || !s->are_legacy_sticker_thumbnails_reloaded) {
LOG(INFO) << "Sticker thumbnails and thumbnail of " << set_id << " was reloaded";
s->is_thumbnail_reloaded = true;

View File

@ -395,6 +395,7 @@ class StickersManager final : public Actor {
string minithumbnail;
PhotoSize thumbnail;
int64 thumbnail_document_id = 0;
vector<FileId> sticker_ids;
FlatHashMap<string, vector<FileId>> emoji_stickers_map_; // emoji -> stickers

View File

@ -179,6 +179,7 @@ void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with
bool is_webm = sticker_set->sticker_format == StickerFormat::Webm;
bool is_masks = sticker_set->sticker_type == StickerType::Mask;
bool is_emojis = sticker_set->sticker_type == StickerType::Emoji;
bool has_thumbnail_document_id = sticker_set->thumbnail_document_id != 0;
BEGIN_STORE_FLAGS();
STORE_FLAG(sticker_set->is_inited);
STORE_FLAG(was_loaded);
@ -196,6 +197,7 @@ void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with
STORE_FLAG(has_minithumbnail);
STORE_FLAG(is_webm);
STORE_FLAG(is_emojis);
STORE_FLAG(has_thumbnail_document_id);
END_STORE_FLAGS();
store(sticker_set->id.get(), storer);
store(sticker_set->access_hash, storer);
@ -213,6 +215,9 @@ void StickersManager::store_sticker_set(const StickerSet *sticker_set, bool with
if (has_minithumbnail) {
store(sticker_set->minithumbnail, storer);
}
if (has_thumbnail_document_id) {
store(sticker_set->thumbnail_document_id, storer);
}
auto stored_sticker_count = narrow_cast<uint32>(is_full ? sticker_set->sticker_ids.size() : stickers_limit);
store(stored_sticker_count, storer);
@ -247,6 +252,7 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
bool has_minithumbnail;
bool is_webm;
bool is_emojis;
bool has_thumbnail_document_id;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(sticker_set->is_inited);
PARSE_FLAG(sticker_set->was_loaded);
@ -264,6 +270,7 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
PARSE_FLAG(has_minithumbnail);
PARSE_FLAG(is_webm);
PARSE_FLAG(is_emojis);
PARSE_FLAG(has_thumbnail_document_id);
END_PARSE_FLAGS();
int64 sticker_set_id;
int64 access_hash;
@ -295,6 +302,7 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
string short_name;
string minithumbnail;
PhotoSize thumbnail;
int64 thumbnail_document_id = 0;
int32 sticker_count;
int32 hash;
int32 expires_at = 0;
@ -311,12 +319,16 @@ void StickersManager::parse_sticker_set(StickerSet *sticker_set, ParserT &parser
if (has_minithumbnail) {
parse(minithumbnail, parser);
}
if (has_thumbnail_document_id) {
parse(thumbnail_document_id, parser);
}
if (!was_inited) {
sticker_set->title = std::move(title);
sticker_set->short_name = std::move(short_name);
sticker_set->minithumbnail = std::move(minithumbnail);
sticker_set->thumbnail = std::move(thumbnail);
sticker_set->thumbnail_document_id = thumbnail_document_id;
sticker_set->sticker_count = sticker_count;
sticker_set->hash = hash;
sticker_set->expires_at = expires_at;