A platform for community discussion. Free, open, simple.
FEATURE: Add animated_topic_thumbnails site setting (#39165)
Gerhard Schlagercca6cd0a3096
diff --git a/app/models/topic_thumbnail.rb b/app/models/topic_thumbnail.rbindex 7800e4ed0b6..fc34f62185d 100644--- a/app/models/topic_thumbnail.rb+++ b/app/models/topic_thumbnail.rb@@ -23,7 +23,10 @@ class TopicThumbnail < ActiveRecord::Base{ max_width: max_width, max_height: max_height },)- if target_width < original.width && target_height < original.height+ needs_optimization = target_width < original.width && target_height < original.height+ skip_animated = SiteSetting.animated_topic_thumbnails && original.animated?++ if needs_optimization && !skip_animatedoptimized = OptimizedImage.create_for(original, target_width, target_height)enddiff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 46ee7432cb4..0a4b55e85f5 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2254,6 +2254,7 @@ en:here_mention_allowed_groups: "Groups that are allowed to mention @here. Admins and moderators can always mention @here."create_thumbnails: "Create thumbnails and lightbox images that are too large to fit in a post."+ animated_topic_thumbnails: "Use the original animated image as the topic thumbnail instead of generating a static thumbnail."email_time_window_mins: "Wait (n) minutes before sending any notification emails, to give users a chance to edit and finalize their posts."personal_email_time_window_seconds: "Wait (n) seconds before sending any personal message notification emails, to give users a chance to edit and finalize their messages."diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 8a1a899ceec..776c0d83110 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -2193,6 +2193,8 @@ files:type: listregex: '\A((https?:\/\/.+)(\|https?:\/\/.+[|$])*)?\z'create_thumbnails: true+ animated_topic_thumbnails:+ default: falseclean_up_uploads: trueclean_orphan_uploads_grace_period_hours:default: 48diff --git a/spec/models/topic_thumbnail_spec.rb b/spec/models/topic_thumbnail_spec.rbindex d529d26f26d..4bf94d363cc 100644--- a/spec/models/topic_thumbnail_spec.rb+++ b/spec/models/topic_thumbnail_spec.rb@@ -61,6 +61,26 @@ RSpec.describe "TopicThumbnail" doexpect(topic.topic_thumbnails.length).to eq(0)end+ it "skips optimized image creation for animated uploads when setting is enabled" do+ SiteSetting.animated_topic_thumbnails = true+ animated_upload = Fabricate(:image_upload, width: 50, height: 50, animated: true)++ thumbnail = TopicThumbnail.find_or_create_for!(animated_upload, max_width: 49, max_height: 49)++ expect(thumbnail).to be_present+ expect(thumbnail.optimized_image_id).to be_nil+ end++ it "creates optimized image for animated uploads when setting is disabled" do+ SiteSetting.animated_topic_thumbnails = false+ animated_upload = Fabricate(:image_upload, width: 50, height: 50, animated: true)++ thumbnail = TopicThumbnail.find_or_create_for!(animated_upload, max_width: 49, max_height: 49)++ expect(thumbnail).to be_present+ expect(thumbnail.optimized_image_id).to be_present+ end+it "cleans up unneeded sizes" doexpect(topic.topic_thumbnails.length).to eq(1)topic.topic_thumbnails[0].update_column(:max_width, 999_999)