Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit aa5c968

Browse files
authored
DEV: Remove the legacy widget post menu code (#1225)
1 parent fccd072 commit aa5c968

File tree

4 files changed

+17
-124
lines changed

4 files changed

+17
-124
lines changed

assets/javascripts/discourse/components/post-menu/ai-cancel-streaming-button.gjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { ajax } from "discourse/lib/ajax";
55
import { popupAjaxError } from "discourse/lib/ajax-error";
66

77
export default class AiCancelStreamingButton extends Component {
8-
// TODO (glimmer-post-menu): Remove this static function and move the code into the button action after the widget code is removed
9-
static async cancelStreaming(post) {
8+
@action
9+
async cancelStreaming() {
10+
const post = this.args.post;
11+
1012
try {
1113
await ajax(`/discourse-ai/ai-bot/post/${post.id}/stop-streaming`, {
1214
type: "POST",
@@ -20,11 +22,6 @@ export default class AiCancelStreamingButton extends Component {
2022
}
2123
}
2224

23-
@action
24-
cancelStreaming() {
25-
this.constructor.cancelStreaming(this.args.post);
26-
}
27-
2825
<template>
2926
<DButton
3027
class="post-action-menu__ai-cancel-streaming cancel-streaming"

assets/javascripts/discourse/components/post-menu/ai-debug-button.gjs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ export default class AiDebugButton extends Component {
1010
return isPostFromAiBot(args.post, args.state.currentUser);
1111
}
1212

13-
// TODO (glimmer-post-menu): Remove this static function and move the code into the button action after the widget code is removed
14-
static debugAiResponse(post, modal) {
15-
modal.show(DebugAiModal, { model: post });
16-
}
17-
1813
@service modal;
1914

2015
@action
2116
debugAiResponse() {
22-
this.constructor.debugAiResponse(this.args.post, this.modal);
17+
this.modal.show(DebugAiModal, { model: this.args.post });
2318
}
2419

2520
<template>

assets/javascripts/discourse/components/post-menu/ai-share-button.gjs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,20 @@ export default class AiDebugButton extends Component {
1313
return isPostFromAiBot(args.post, args.state.currentUser);
1414
}
1515

16-
// TODO (glimmer-post-menu): Remove this static function and move the code into the button action after the widget code is removed
17-
static async shareAiResponse(post, modal, showFeedback) {
16+
@service modal;
17+
18+
@action
19+
async shareAiResponse() {
20+
const post = this.args.post;
21+
1822
if (post.post_number <= AUTO_COPY_THRESHOLD) {
1923
await copyConversation(post.topic, 1, post.post_number);
20-
showFeedback("discourse_ai.ai_bot.conversation_shared");
24+
this.args.showFeedback("discourse_ai.ai_bot.conversation_shared");
2125
} else {
22-
modal.show(ShareModal, { model: post });
26+
this.modal.show(ShareModal, { model: post });
2327
}
2428
}
2529

26-
@service modal;
27-
28-
@action
29-
shareAiResponse() {
30-
this.constructor.shareAiResponse(
31-
this.args.post,
32-
this.modal,
33-
this.args.showFeedback
34-
);
35-
}
36-
3730
<template>
3831
<DButton
3932
class="post-action-menu__share-ai"

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

Lines changed: 4 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { hbs } from "ember-cli-htmlbars";
2-
import { withSilencedDeprecations } from "discourse/lib/deprecated";
32
import { withPluginApi } from "discourse/lib/plugin-api";
43
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
54
import AiBotHeaderIcon from "../discourse/components/ai-bot-header-icon";
65
import AiCancelStreamingButton from "../discourse/components/post-menu/ai-cancel-streaming-button";
76
import AiDebugButton from "../discourse/components/post-menu/ai-debug-button";
87
import AiShareButton from "../discourse/components/post-menu/ai-share-button";
9-
import {
10-
isPostFromAiBot,
11-
showShareConversationModal,
12-
} from "../discourse/lib/ai-bot-helper";
8+
import { showShareConversationModal } from "../discourse/lib/ai-bot-helper";
139
import { streamPostText } from "../discourse/lib/ai-streamer/progress-handlers";
1410

1511
let enabledChatBotIds = [];
@@ -83,7 +79,7 @@ function initializePersonaDecorator(api) {
8379
}
8480

8581
function initializePauseButton(api) {
86-
const transformerRegistered = api.registerValueTransformer(
82+
api.registerValueTransformer(
8783
"post-menu-buttons",
8884
({ value: dag, context: { post, firstButtonKey } }) => {
8985
if (isGPTBot(post.user)) {
@@ -94,29 +90,6 @@ function initializePauseButton(api) {
9490
}
9591
}
9692
);
97-
98-
const silencedKey =
99-
transformerRegistered && "discourse.post-menu-widget-overrides";
100-
101-
withSilencedDeprecations(silencedKey, () => initializePauseWidgetButton(api));
102-
}
103-
104-
function initializePauseWidgetButton(api) {
105-
api.addPostMenuButton("cancel-gpt", (post) => {
106-
if (isGPTBot(post.user)) {
107-
return {
108-
icon: "pause",
109-
action: "cancelStreaming",
110-
title: "discourse_ai.ai_bot.cancel_streaming",
111-
className: "btn btn-default cancel-streaming",
112-
position: "first",
113-
};
114-
}
115-
});
116-
117-
api.attachWidgetAction("post", "cancelStreaming", function () {
118-
AiCancelStreamingButton.cancelStreaming(this.model);
119-
});
12093
}
12194

12295
function initializeDebugButton(api) {
@@ -125,7 +98,7 @@ function initializeDebugButton(api) {
12598
return;
12699
}
127100

128-
const transformerRegistered = api.registerValueTransformer(
101+
api.registerValueTransformer(
129102
"post-menu-buttons",
130103
({ value: dag, context: { post, firstButtonKey } }) => {
131104
if (post.topic?.archetype === "private_message") {
@@ -136,38 +109,6 @@ function initializeDebugButton(api) {
136109
}
137110
}
138111
);
139-
140-
const silencedKey =
141-
transformerRegistered && "discourse.post-menu-widget-overrides";
142-
143-
withSilencedDeprecations(silencedKey, () => initializeDebugWidgetButton(api));
144-
}
145-
146-
function initializeDebugWidgetButton(api) {
147-
const currentUser = api.getCurrentUser();
148-
149-
let debugAiResponse = async function ({ post }) {
150-
const modal = api.container.lookup("service:modal");
151-
AiDebugButton.debugAiResponse(post, modal);
152-
};
153-
154-
api.addPostMenuButton("debugAi", (post) => {
155-
if (post.topic?.archetype !== "private_message") {
156-
return;
157-
}
158-
159-
if (!isPostFromAiBot(post, currentUser)) {
160-
return;
161-
}
162-
163-
return {
164-
action: debugAiResponse,
165-
icon: "info",
166-
className: "post-action-menu__debug-ai",
167-
title: "discourse_ai.ai_bot.debug_ai",
168-
position: "first",
169-
};
170-
});
171112
}
172113

173114
function initializeShareButton(api) {
@@ -176,7 +117,7 @@ function initializeShareButton(api) {
176117
return;
177118
}
178119

179-
const transformerRegistered = api.registerValueTransformer(
120+
api.registerValueTransformer(
180121
"post-menu-buttons",
181122
({ value: dag, context: { post, firstButtonKey } }) => {
182123
if (post.topic?.archetype === "private_message") {
@@ -186,39 +127,6 @@ function initializeShareButton(api) {
186127
}
187128
}
188129
);
189-
190-
const silencedKey =
191-
transformerRegistered && "discourse.post-menu-widget-overrides";
192-
193-
withSilencedDeprecations(silencedKey, () => initializeShareWidgetButton(api));
194-
}
195-
196-
function initializeShareWidgetButton(api) {
197-
const currentUser = api.getCurrentUser();
198-
199-
let shareAiResponse = async function ({ post, showFeedback }) {
200-
const modal = api.container.lookup("service:modal");
201-
AiShareButton.shareAiResponse(post, modal, showFeedback);
202-
};
203-
204-
api.addPostMenuButton("share", (post) => {
205-
// for backwards compat so we don't break if topic is undefined
206-
if (post.topic?.archetype !== "private_message") {
207-
return;
208-
}
209-
210-
if (!isPostFromAiBot(post, currentUser)) {
211-
return;
212-
}
213-
214-
return {
215-
action: shareAiResponse,
216-
icon: "far-copy",
217-
className: "post-action-menu__share-ai",
218-
title: "discourse_ai.ai_bot.share",
219-
position: "first",
220-
};
221-
});
222130
}
223131

224132
function initializeShareTopicButton(api) {

0 commit comments

Comments
 (0)