From 2156adb9ebdc63d96e53f823aed401b296f02c21 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 31 Oct 2024 20:39:07 +0100 Subject: [PATCH 1/3] DEV: Use the new more-topics API See: https://github.com/discourse/discourse/pull/29143 --- .../topic-more-content/related-topics.hbs | 15 ---- .../topic-more-content/related-topics.js | 41 ----------- .../initializers/related-topics.gjs | 71 +++++++++++++++++++ .../initializers/related-topics.js | 32 --------- 4 files changed, 71 insertions(+), 88 deletions(-) delete mode 100644 assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs delete mode 100644 assets/javascripts/discourse/connectors/topic-more-content/related-topics.js create mode 100644 assets/javascripts/initializers/related-topics.gjs delete mode 100644 assets/javascripts/initializers/related-topics.js diff --git a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs deleted file mode 100644 index 2471ab376..000000000 --- a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.hbs +++ /dev/null @@ -1,15 +0,0 @@ - \ No newline at end of file diff --git a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js b/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js deleted file mode 100644 index a1996dad7..000000000 --- a/assets/javascripts/discourse/connectors/topic-more-content/related-topics.js +++ /dev/null @@ -1,41 +0,0 @@ -import Component from "@glimmer/component"; -import { action, computed } from "@ember/object"; -import { inject as service } from "@ember/service"; -import I18n from "I18n"; - -export default class extends Component { - static shouldRender(args) { - return (args.model.related_topics?.length || 0) > 0; - } - - @service store; - @service site; - @service moreTopicsPreferenceTracking; - - listId = "related-topics"; - - @computed("moreTopicsPreferenceTracking.selectedTab") - get hidden() { - return this.moreTopicsPreferenceTracking.selectedTab !== this.listId; - } - - get relatedTopics() { - return this.args.outletArgs.model.related_topics.map((topic) => - this.store.createRecord("topic", topic) - ); - } - - @action - registerList() { - this.moreTopicsPreferenceTracking.registerTopicList({ - name: I18n.t("discourse_ai.related_topics.pill"), - id: this.listId, - icon: "discourse-sparkles", - }); - } - - @action - removeList() { - this.moreTopicsPreferenceTracking.removeTopicList(this.listId); - } -} diff --git a/assets/javascripts/initializers/related-topics.gjs b/assets/javascripts/initializers/related-topics.gjs new file mode 100644 index 000000000..b4d95ecb8 --- /dev/null +++ b/assets/javascripts/initializers/related-topics.gjs @@ -0,0 +1,71 @@ +import { cached, tracked } from "@glimmer/tracking"; +import BasicTopicList from "discourse/components/basic-topic-list"; +import { withPluginApi } from "discourse/lib/plugin-api"; +import i18n from "discourse-common/helpers/i18n"; + +const RelatedTopics = ; + +export default { + name: "discourse-ai-related-topics", + + initialize(container) { + const settings = container.lookup("service:site-settings"); + + if ( + !settings.ai_embeddings_enabled || + !settings.ai_embeddings_semantic_related_topics_enabled + ) { + return; + } + + withPluginApi("1.37.2", (api) => { + api.registerMoreTopicsTab({ + id: "related-topics", + name: i18n("discourse_ai.related_topics.pill"), + icon: "discourse-sparkles", + component: RelatedTopics, + condition: ({ topic }) => topic.relatedTopics?.length, + }); + + api.modifyClass( + "model:topic", + (Superclass) => + class extends Superclass { + @tracked related_topics; + + @cached + get relatedTopics() { + return this.related_topics?.map((topic) => + this.store.createRecord("topic", topic) + ); + } + } + ); + + api.modifyClass( + "model:post-stream", + (Superclass) => + class extends Superclass { + _setSuggestedTopics(result) { + super._setSuggestedTopics(...arguments); + this.topic.related_topics = result.related_topics; + } + } + ); + }); + }, +}; diff --git a/assets/javascripts/initializers/related-topics.js b/assets/javascripts/initializers/related-topics.js deleted file mode 100644 index 6eae8c37a..000000000 --- a/assets/javascripts/initializers/related-topics.js +++ /dev/null @@ -1,32 +0,0 @@ -import { withPluginApi } from "discourse/lib/plugin-api"; - -export default { - name: "discourse-ai-related-topics", - - initialize(container) { - const settings = container.lookup("service:site-settings"); - - if ( - settings.ai_embeddings_enabled && - settings.ai_embeddings_semantic_related_topics_enabled - ) { - withPluginApi("1.1.0", (api) => { - api.modifyClass("model:post-stream", { - pluginId: "discourse-ai", - - _setSuggestedTopics(result) { - this._super(...arguments); - - if (!result.related_topics) { - return; - } - - this.topic.setProperties({ - related_topics: result.related_topics, - }); - }, - }); - }); - } - }, -}; From d61aa2dd4872f704c6d275ff169141fdbbb2f95c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 31 Oct 2024 20:40:26 +0100 Subject: [PATCH 2/3] use PR --- .github/workflows/discourse-plugin.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/discourse-plugin.yml b/.github/workflows/discourse-plugin.yml index f5cf62e53..6940ab8da 100644 --- a/.github/workflows/discourse-plugin.yml +++ b/.github/workflows/discourse-plugin.yml @@ -9,3 +9,5 @@ on: jobs: ci: uses: discourse/.github/.github/workflows/discourse-plugin.yml@v1 + with: + core_ref: 0-a-more-topics-api From 69dfdfe3d65acf0fe3b66a80140b6cc9c07fbe5b Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 4 Nov 2024 17:34:08 +0100 Subject: [PATCH 3/3] remove core_ref --- .github/workflows/discourse-plugin.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/discourse-plugin.yml b/.github/workflows/discourse-plugin.yml index 6940ab8da..f5cf62e53 100644 --- a/.github/workflows/discourse-plugin.yml +++ b/.github/workflows/discourse-plugin.yml @@ -9,5 +9,3 @@ on: jobs: ci: uses: discourse/.github/.github/workflows/discourse-plugin.yml@v1 - with: - core_ref: 0-a-more-topics-api