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 2471ab37..00000000 --- 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 a1996dad..00000000 --- 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 00000000..b4d95ecb --- /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 6eae8c37..00000000 --- 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, - }); - }, - }); - }); - } - }, -};