From fb80d776d860fa3c0f8ef0bdfb70171a9ce3c436 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Tue, 19 Nov 2024 11:04:34 -0300 Subject: [PATCH] FEATURE: Enable gists on all topic lists (#922) --- .../discourse/components/ai-topic-gist.gjs | 2 -- lib/summarization/entry_point.rb | 8 ++++---- spec/lib/modules/summarization/entry_point_spec.rb | 14 -------------- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/assets/javascripts/discourse/components/ai-topic-gist.gjs b/assets/javascripts/discourse/components/ai-topic-gist.gjs index 3ec25657..008336af 100644 --- a/assets/javascripts/discourse/components/ai-topic-gist.gjs +++ b/assets/javascripts/discourse/components/ai-topic-gist.gjs @@ -12,9 +12,7 @@ export default class AiTopicGist extends Component { get showGist() { return ( - this.router.currentRoute.attributes?.filterType === "hot" && this.args.topic?.ai_topic_gist && - !this.args.topic?.excerpt && this.prefersGist && !this.args.topic?.excerpt ); diff --git a/lib/summarization/entry_point.rb b/lib/summarization/entry_point.rb index a9be9f6e..07640612 100644 --- a/lib/summarization/entry_point.rb +++ b/lib/summarization/entry_point.rb @@ -18,7 +18,9 @@ module DiscourseAi end plugin.register_modifier(:topic_query_create_list_topics) do |topics, options| - if options[:filter] == :hot && SiteSetting.ai_summarization_enabled && + skipped_filters = %i[suggested semantic_related] + + if !skipped_filters.include?(options[:filter]) && SiteSetting.ai_summarization_enabled && SiteSetting.ai_summarize_max_hot_topics_gists_per_batch > 0 topics.includes(:ai_summaries).where( "ai_summaries.id IS NULL OR ai_summaries.summary_type = ?", @@ -34,9 +36,7 @@ module DiscourseAi :ai_topic_gist, include_condition: -> { scope.can_see_gists? }, ) do - # Options is defined at the instance level so we cannot run this check inside "include_condition". - return if options[:filter] != :hot - + return if %i[suggested semantic_related].include?(options[:filter]) summaries = object.ai_summaries.to_a # Summaries should always have one or zero elements here. diff --git a/spec/lib/modules/summarization/entry_point_spec.rb b/spec/lib/modules/summarization/entry_point_spec.rb index f7e1f56f..0ba22770 100644 --- a/spec/lib/modules/summarization/entry_point_spec.rb +++ b/spec/lib/modules/summarization/entry_point_spec.rb @@ -71,20 +71,6 @@ RSpec.describe DiscourseAi::Summarization::EntryPoint do expect(serialized[:ai_topic_gist]).to be_present end - it "doesn't include the summary when looking at other topic lists" do - gist_topic = topic_query.list_hot.topics.find { |t| t.id == topic_ai_gist.target_id } - - serialized = - TopicListItemSerializer.new( - gist_topic, - scope: Guardian.new(user), - root: false, - filter: :latest, - ).as_json - - expect(serialized[:ai_topic_gist]).to be_nil - end - it "doesn't include the summary when the user is not a member of the opt-in group" do SiteSetting.ai_hot_topic_gists_allowed_groups = ""