diff --git a/assets/javascripts/discourse/connectors/topic-above-suggested/related-topics.hbs b/assets/javascripts/discourse/connectors/topic-above-suggested/related-topics.hbs deleted file mode 100644 index d62a260c..00000000 --- a/assets/javascripts/discourse/connectors/topic-above-suggested/related-topics.hbs +++ /dev/null @@ -1,6 +0,0 @@ - \ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs new file mode 100644 index 00000000..fb055d6c --- /dev/null +++ b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/topic-above-suggested/related-topics.js b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js similarity index 55% rename from assets/javascripts/discourse/connectors/topic-above-suggested/related-topics.js rename to assets/javascripts/discourse/connectors/topic-more-content/related-topics.js index 890e679c..1109161c 100644 --- a/assets/javascripts/discourse/connectors/topic-above-suggested/related-topics.js +++ b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js @@ -1,5 +1,6 @@ import Component from "@glimmer/component"; import { inject as service } from "@ember/service"; +import { computed } from "@ember/object"; export default class extends Component { static shouldRender(args) { @@ -7,6 +8,18 @@ export default class extends Component { } @service store; + @service site; + @service moreTopicsPreferenceTracking; + + listId = "related-topics"; + + @computed("moreTopicsPreferenceTracking.preference") + get hidden() { + return ( + this.site.mobileView && + this.moreTopicsPreferenceTracking.preference !== this.listId + ); + } get relatedTopics() { return this.args.outletArgs.model.related_topics.map((topic) => diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index fb10dfec..a051eb62 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -5,7 +5,8 @@ en: select_option: "Select an option..." related_topics: - title: "Related Topics" + title: "Similar Topics" + pill: "Related" ai_helper: title: "Suggest changes using AI" description: "Choose one of the options below, and the AI will suggest you a new version of the text." diff --git a/lib/modules/embeddings/entry_point.rb b/lib/modules/embeddings/entry_point.rb index a7d37eed..e6423bfc 100644 --- a/lib/modules/embeddings/entry_point.rb +++ b/lib/modules/embeddings/entry_point.rb @@ -16,6 +16,16 @@ module DiscourseAi end def inject_into(plugin) + # Include random topics in the suggested list *only* if there are no related topics. + plugin.register_modifier( + :topic_view_suggested_topics_options, + ) do |suggested_options, topic_view| + related_topics = topic_view.related_topics + include_random = related_topics.nil? || related_topics.length == 0 + suggested_options.merge(include_random: include_random) + end + + # Query and serialize related topics. plugin.add_to_class(:topic_view, :related_topics) do if topic.private_message? || !SiteSetting.ai_embeddings_semantic_related_topics_enabled return nil @@ -23,20 +33,12 @@ module DiscourseAi @related_topics ||= TopicList.new( - :suggested, + :related, nil, DiscourseAi::Embeddings::SemanticRelated.candidates_for(topic), ).topics end - plugin.register_modifier( - :topic_view_suggested_topics_options, - ) do |suggested_options, topic_view| - related_topics = topic_view.related_topics - include_random = related_topics.nil? || related_topics.length == 0 - suggested_options.merge(include_random: include_random) - end - %i[topic_view TopicViewPosts].each do |serializer| plugin.add_to_serializer( serializer, @@ -51,6 +53,7 @@ module DiscourseAi end end + # embeddings generation. callback = Proc.new do |topic| if SiteSetting.ai_embeddings_enabled