DEV: Update modifyClass calls

- Update `controller:topic` modification to native class syntax
- Remove search-result-entry modification in favour of plugin-outlet-based solution
This commit is contained in:
David Taylor 2024-12-02 11:28:41 +00:00
parent 0abd4b1244
commit 593e8dc2a5
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
3 changed files with 35 additions and 34 deletions

View File

@ -1,10 +1,16 @@
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import icon from "discourse-common/helpers/d-icon";
import i18n from "discourse-common/helpers/i18n";
function addResultClass(element) {
element.closest(".fps-result")?.classList.add("ai-result");
}
const SearchResultDecoration = <template>
<div
class="ai-result__icon"
title={{i18n "discourse_ai.embeddings.ai_generated_result"}}
{{didInsert addResultClass}}
>
{{icon "discourse-sparkles"}}
</div>

View File

@ -26,34 +26,38 @@ function attachHeaderIcon(api) {
function initializeAIBotReplies(api) {
initializePauseButton(api);
api.modifyClass("controller:topic", {
pluginId: "discourse-ai",
api.modifyClass(
"controller:topic",
(Superclass) =>
class extends Superclass {
onAIBotStreamedReply(data) {
streamPostText(this.model.postStream, data);
}
onAIBotStreamedReply: function (data) {
streamPostText(this.model.postStream, data);
},
subscribe: function () {
this._super();
subscribe() {
super.subscribe();
if (
this.model.isPrivateMessage &&
this.model.details.allowed_users &&
this.model.details.allowed_users.filter(isGPTBot).length >= 1
) {
// we attempt to recover the last message in the bus
// so we subscribe at -2
this.messageBus.subscribe(
`discourse-ai/ai-bot/topic/${this.model.id}`,
this.onAIBotStreamedReply.bind(this),
-2
);
if (
this.model.isPrivateMessage &&
this.model.details.allowed_users &&
this.model.details.allowed_users.filter(isGPTBot).length >= 1
) {
// we attempt to recover the last message in the bus
// so we subscribe at -2
this.messageBus.subscribe(
`discourse-ai/ai-bot/topic/${this.model.id}`,
this.onAIBotStreamedReply.bind(this),
-2
);
}
}
unsubscribe() {
this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*");
super.unsubscribe();
}
}
},
unsubscribe: function () {
this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*");
this._super();
},
});
);
}
function initializePersonaDecorator(api) {

View File

@ -1,9 +0,0 @@
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer("1.15.0", (api) => {
api.modifyClass("component:search-result-entry", {
pluginId: "discourse-ai",
classNameBindings: ["bulkSelectEnabled", "post.generatedByAi:ai-result"],
});
});