A platform for community discussion. Free, open, simple.
FIX: add lightbox class to chat quoted images (#35442)
David Battersby2e5eb80b942a
diff --git a/plugins/chat/assets/javascripts/discourse/lib/lightbox.js b/plugins/chat/assets/javascripts/discourse/lib/lightbox.jsindex a2f26d4154b..995aab910bf 100644--- a/plugins/chat/assets/javascripts/discourse/lib/lightbox.js+++ b/plugins/chat/assets/javascripts/discourse/lib/lightbox.js@@ -13,7 +13,8 @@ export default function loadLightbox(element, siteSettings) {return;}- const images = element?.querySelectorAll("img.chat-img-upload");+ // catches chat message uploads and quoted images+ const images = element?.querySelectorAll("img:not(.emoji, .avatar)");if (!images.length) {return;diff --git a/plugins/chat/lib/chat/message_processor.rb b/plugins/chat/lib/chat/message_processor.rbindex 423820dcc50..cfa5a449adb 100644--- a/plugins/chat/lib/chat/message_processor.rb+++ b/plugins/chat/lib/chat/message_processor.rb@@ -19,6 +19,7 @@ module Chatdef run!post_process_oneboxesprocess_thumbnails+ add_lightbox_to_imagesDiscourseEvent.trigger(:chat_message_processed, @doc, @model)end@@ -55,6 +56,15 @@ module Chatendend+ def add_lightbox_to_images+ @doc+ .css("img")+ .each do |img|+ next if img["class"]&.include?("emoji") || img["class"]&.include?("avatar")+ img["class"] = "#{img["class"]} lightbox".strip+ end+ end+def large_images[]enddiff --git a/plugins/chat/spec/lib/chat/message_processor_spec.rb b/plugins/chat/spec/lib/chat/message_processor_spec.rbindex 333647ca9cd..418b9c61183 100644--- a/plugins/chat/spec/lib/chat/message_processor_spec.rb+++ b/plugins/chat/spec/lib/chat/message_processor_spec.rb@@ -24,4 +24,24 @@ RSpec.describe Chat::MessageProcessor doexpect { processor.run! }.not_to raise_errorendend++ describe "#add_lightbox_to_images" do+ it "adds lightbox class to quoted images" do+ cooked_html = <<~HTML+ <blockquote>+ <img src="https://example.com/image.jpg" width="500" height="300">+ </blockquote>+ HTML++ Chat::Message.stubs(:cook).returns(cooked_html)+ processor = described_class.new(message)++ processor.run!++ doc = processor.instance_variable_get(:@doc)+ img = doc.at_css("img")++ expect(img["class"]).to include("lightbox")+ end+ endend