diff --git a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb index bc134eb7e36..600ee90664b 100644 --- a/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb +++ b/plugins/discourse-narrative-bot/lib/discourse_narrative_bot/new_user_narrative.rb @@ -302,7 +302,6 @@ module DiscourseNarrativeBot post_topic_id = @post.topic_id return unless valid_topic?(post_topic_id) - @post.post_analyzer.cook(@post.raw, {}) transition = true attempted_count = get_state_data(:attempted) || 0 @@ -313,7 +312,9 @@ module DiscourseNarrativeBot @data[:skip_attempted] = false end - if @post.post_analyzer.image_count > 0 + cooked = @post.post_analyzer.cook(@post.raw, {}) + + if Nokogiri::HTML.fragment(cooked).css("img").size > 0 set_state_data(:post_id, @post.id) if get_state_data(:liked) diff --git a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb index 0d0d144f5ec..3a7e5d8aa32 100644 --- a/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb +++ b/plugins/discourse-narrative-bot/spec/discourse_narrative_bot/new_user_narrative_spec.rb @@ -434,12 +434,19 @@ describe DiscourseNarrativeBot::NewUserNarrative do described_class.any_instance.expects(:enqueue_timeout_job).with(user) + url = "https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg" + + stub_request(:head, url).to_return( + status: 200, body: file_from_fixtures("smallest.png").read + ) + new_post = Fabricate(:post, user: user, topic: topic, - raw: "" + raw: url ) + CookedPostProcessor.new(new_post).post_process DiscourseNarrativeBot::TrackSelector.new(:reply, user, post_id: new_post.id).select expected_raw = <<~RAW