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:
parent
0abd4b1244
commit
593e8dc2a5
|
@ -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>
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"],
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue