Skip to content

Commit 593e8dc

Browse files
committed
DEV: Update modifyClass calls
- Update `controller:topic` modification to native class syntax - Remove search-result-entry modification in favour of plugin-outlet-based solution
1 parent 0abd4b1 commit 593e8dc

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

assets/javascripts/discourse/connectors/after-search-result-entry/search-result-decoration.gjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
12
import icon from "discourse-common/helpers/d-icon";
23
import i18n from "discourse-common/helpers/i18n";
34

5+
function addResultClass(element) {
6+
element.closest(".fps-result")?.classList.add("ai-result");
7+
}
8+
49
const SearchResultDecoration = <template>
510
<div
611
class="ai-result__icon"
712
title={{i18n "discourse_ai.embeddings.ai_generated_result"}}
13+
{{didInsert addResultClass}}
814
>
915
{{icon "discourse-sparkles"}}
1016
</div>

assets/javascripts/initializers/ai-bot-replies.js

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,38 @@ function attachHeaderIcon(api) {
2626
function initializeAIBotReplies(api) {
2727
initializePauseButton(api);
2828

29-
api.modifyClass("controller:topic", {
30-
pluginId: "discourse-ai",
31-
32-
onAIBotStreamedReply: function (data) {
33-
streamPostText(this.model.postStream, data);
34-
},
35-
subscribe: function () {
36-
this._super();
37-
38-
if (
39-
this.model.isPrivateMessage &&
40-
this.model.details.allowed_users &&
41-
this.model.details.allowed_users.filter(isGPTBot).length >= 1
42-
) {
43-
// we attempt to recover the last message in the bus
44-
// so we subscribe at -2
45-
this.messageBus.subscribe(
46-
`discourse-ai/ai-bot/topic/${this.model.id}`,
47-
this.onAIBotStreamedReply.bind(this),
48-
-2
49-
);
29+
api.modifyClass(
30+
"controller:topic",
31+
(Superclass) =>
32+
class extends Superclass {
33+
onAIBotStreamedReply(data) {
34+
streamPostText(this.model.postStream, data);
35+
}
36+
37+
subscribe() {
38+
super.subscribe();
39+
40+
if (
41+
this.model.isPrivateMessage &&
42+
this.model.details.allowed_users &&
43+
this.model.details.allowed_users.filter(isGPTBot).length >= 1
44+
) {
45+
// we attempt to recover the last message in the bus
46+
// so we subscribe at -2
47+
this.messageBus.subscribe(
48+
`discourse-ai/ai-bot/topic/${this.model.id}`,
49+
this.onAIBotStreamedReply.bind(this),
50+
-2
51+
);
52+
}
53+
}
54+
55+
unsubscribe() {
56+
this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*");
57+
super.unsubscribe();
58+
}
5059
}
51-
},
52-
unsubscribe: function () {
53-
this.messageBus.unsubscribe("discourse-ai/ai-bot/topic/*");
54-
this._super();
55-
},
56-
});
60+
);
5761
}
5862

5963
function initializePersonaDecorator(api) {

assets/javascripts/initializers/ai-semantic-search.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)