Disable leftover minithumbnails if the option is set

This commit is contained in:
Andrea Cavalli 2021-08-03 19:55:27 +02:00
parent d79f12d21f
commit fe8f46bfe3
6 changed files with 44 additions and 20 deletions

View File

@ -212,9 +212,11 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
a->duration = new_animation->duration;
a->is_changed = true;
}
if (a->minithumbnail != new_animation->minithumbnail) {
a->minithumbnail = std::move(new_animation->minithumbnail);
a->is_changed = true;
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
if (a->minithumbnail != new_animation->minithumbnail) {
a->minithumbnail = std::move(new_animation->minithumbnail);
a->is_changed = true;
}
}
if (a->thumbnail != new_animation->thumbnail) {
if (!a->thumbnail.file_id.is_valid()) {
@ -353,8 +355,10 @@ void AnimationsManager::create_animation(FileId file_id, string minithumbnail, P
a->mime_type = std::move(mime_type);
a->duration = max(duration, 0);
a->dimensions = dimensions;
if (!td_->auth_manager_->is_bot()) {
a->minithumbnail = std::move(minithumbnail);
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
if (!td_->auth_manager_->is_bot()) {
a->minithumbnail = std::move(minithumbnail);
}
}
a->thumbnail = std::move(thumbnail);
a->animated_thumbnail = std::move(animated_thumbnail);

View File

@ -3039,8 +3039,10 @@ void merge_message_contents(Td *td, const MessageContent *old_content, MessageCo
if (old_photo->id.get() != new_photo->id.get() || old_->caption != new_->caption) {
need_update = true;
}
if (old_photo->minithumbnail != new_photo->minithumbnail) {
need_update = true;
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
if (old_photo->minithumbnail != new_photo->minithumbnail) {
need_update = true;
}
}
if (old_photo->photos != new_photo->photos) {
LOG(DEBUG) << "Merge photos " << old_photo->photos << " and " << new_photo->photos

View File

@ -67,6 +67,9 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimen
}
td_api::object_ptr<td_api::minithumbnail> get_minithumbnail_object(const string &packed) {
if (G()->shared_config().get_option_boolean("disable_minithumbnails")) {
return nullptr;
}
if (packed.size() < 3) {
return nullptr;
}
@ -165,7 +168,9 @@ ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64
auto dc_id = DcId::create(profile_photo->dc_id_);
result.has_animation = (profile_photo->flags_ & telegram_api::userProfilePhoto::HAS_VIDEO_MASK) != 0;
result.id = profile_photo->photo_id_;
result.minithumbnail = profile_photo->stripped_thumb_.as_slice().str();
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
result.minithumbnail = profile_photo->stripped_thumb_.as_slice().str();
}
result.small_file_id =
register_photo(file_manager, {DialogId(user_id), user_access_hash, false}, result.id, 0 /*access_hash*/,
"" /*file_reference*/, DialogId(), 0 /*file_size*/, dc_id, PhotoFormat::Jpeg);

View File

@ -9,6 +9,7 @@
#include "td/telegram/files/FileId.hpp"
#include "td/telegram/Photo.h"
#include "td/telegram/Version.h"
#include "td/telegram/ConfigShared.h"
#include "td/utils/logging.h"
#include "td/utils/tl_helpers.h"
@ -35,13 +36,13 @@ void store(const DialogPhoto &dialog_photo, StorerT &storer) {
BEGIN_STORE_FLAGS();
STORE_FLAG(has_file_ids);
STORE_FLAG(dialog_photo.has_animation);
STORE_FLAG(has_minithumbnail);
STORE_FLAG(!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail);
END_STORE_FLAGS();
if (has_file_ids) {
store(dialog_photo.small_file_id, storer);
store(dialog_photo.big_file_id, storer);
}
if (has_minithumbnail) {
if (!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail) {
store(dialog_photo.minithumbnail, storer);
}
}
@ -62,7 +63,11 @@ void parse(DialogPhoto &dialog_photo, ParserT &parser) {
parse(dialog_photo.big_file_id, parser);
}
if (has_minithumbnail) {
parse(dialog_photo.minithumbnail, parser);
std::basic_string<char> minithumbnail;
parse(minithumbnail, parser);
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
dialog_photo.minithumbnail = minithumbnail;
}
}
}
@ -128,7 +133,7 @@ void store(const Photo &photo, StorerT &storer) {
bool has_animations = !photo.animations.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(photo.has_stickers);
STORE_FLAG(has_minithumbnail);
STORE_FLAG(!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail);
STORE_FLAG(has_animations);
END_STORE_FLAGS();
store(photo.id.get(), storer);
@ -137,7 +142,7 @@ void store(const Photo &photo, StorerT &storer) {
if (photo.has_stickers) {
store(photo.sticker_file_ids, storer);
}
if (has_minithumbnail) {
if (!G()->shared_config().get_option_boolean("disable_minithumbnails") && has_minithumbnail) {
store(photo.minithumbnail, storer);
}
if (has_animations) {
@ -163,7 +168,11 @@ void parse(Photo &photo, ParserT &parser) {
parse(photo.sticker_file_ids, parser);
}
if (has_minithumbnail) {
parse(photo.minithumbnail, parser);
std::basic_string<char> minithumbnail;
parse(minithumbnail, parser);
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
photo.minithumbnail = minithumbnail;
}
}
if (has_animations) {
parse(photo.animations, parser);

View File

@ -64,9 +64,11 @@ FileId VideoNotesManager::on_get_video_note(unique_ptr<VideoNote> new_video_note
v->dimensions = new_video_note->dimensions;
v->is_changed = true;
}
if (v->minithumbnail != new_video_note->minithumbnail) {
v->minithumbnail = std::move(new_video_note->minithumbnail);
v->is_changed = true;
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
if (v->minithumbnail != new_video_note->minithumbnail) {
v->minithumbnail = std::move(new_video_note->minithumbnail);
v->is_changed = true;
}
}
if (v->thumbnail != new_video_note->thumbnail) {
if (!v->thumbnail.file_id.is_valid()) {

View File

@ -78,9 +78,11 @@ FileId VideosManager::on_get_video(unique_ptr<Video> new_video, bool replace) {
v->file_name = std::move(new_video->file_name);
v->is_changed = true;
}
if (v->minithumbnail != new_video->minithumbnail) {
v->minithumbnail = std::move(new_video->minithumbnail);
v->is_changed = true;
if (!G()->shared_config().get_option_boolean("disable_minithumbnails")) {
if (v->minithumbnail != new_video->minithumbnail) {
v->minithumbnail = std::move(new_video->minithumbnail);
v->is_changed = true;
}
}
if (v->thumbnail != new_video->thumbnail) {
if (!v->thumbnail.file_id.is_valid()) {