DEV: Remove the legacy widget post menu code (#1225)
This commit is contained in:
parent
fccd072f44
commit
aa5c968b18
|
@ -5,8 +5,10 @@ import { ajax } from "discourse/lib/ajax";
|
|||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
||||
export default class AiCancelStreamingButton extends Component {
|
||||
// TODO (glimmer-post-menu): Remove this static function and move the code into the button action after the widget code is removed
|
||||
static async cancelStreaming(post) {
|
||||
@action
|
||||
async cancelStreaming() {
|
||||
const post = this.args.post;
|
||||
|
||||
try {
|
||||
await ajax(`/discourse-ai/ai-bot/post/${post.id}/stop-streaming`, {
|
||||
type: "POST",
|
||||
|
@ -20,11 +22,6 @@ export default class AiCancelStreamingButton extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
@action
|
||||
cancelStreaming() {
|
||||
this.constructor.cancelStreaming(this.args.post);
|
||||
}
|
||||
|
||||
<template>
|
||||
<DButton
|
||||
class="post-action-menu__ai-cancel-streaming cancel-streaming"
|
||||
|
|
|
@ -10,16 +10,11 @@ export default class AiDebugButton extends Component {
|
|||
return isPostFromAiBot(args.post, args.state.currentUser);
|
||||
}
|
||||
|
||||
// TODO (glimmer-post-menu): Remove this static function and move the code into the button action after the widget code is removed
|
||||
static debugAiResponse(post, modal) {
|
||||
modal.show(DebugAiModal, { model: post });
|
||||
}
|
||||
|
||||
@service modal;
|
||||
|
||||
@action
|
||||
debugAiResponse() {
|
||||
this.constructor.debugAiResponse(this.args.post, this.modal);
|
||||
this.modal.show(DebugAiModal, { model: this.args.post });
|
||||
}
|
||||
|
||||
<template>
|
||||
|
|
|
@ -13,25 +13,18 @@ export default class AiDebugButton extends Component {
|
|||
return isPostFromAiBot(args.post, args.state.currentUser);
|
||||
}
|
||||
|
||||
// TODO (glimmer-post-menu): Remove this static function and move the code into the button action after the widget code is removed
|
||||
static async shareAiResponse(post, modal, showFeedback) {
|
||||
if (post.post_number <= AUTO_COPY_THRESHOLD) {
|
||||
await copyConversation(post.topic, 1, post.post_number);
|
||||
showFeedback("discourse_ai.ai_bot.conversation_shared");
|
||||
} else {
|
||||
modal.show(ShareModal, { model: post });
|
||||
}
|
||||
}
|
||||
|
||||
@service modal;
|
||||
|
||||
@action
|
||||
shareAiResponse() {
|
||||
this.constructor.shareAiResponse(
|
||||
this.args.post,
|
||||
this.modal,
|
||||
this.args.showFeedback
|
||||
);
|
||||
async shareAiResponse() {
|
||||
const post = this.args.post;
|
||||
|
||||
if (post.post_number <= AUTO_COPY_THRESHOLD) {
|
||||
await copyConversation(post.topic, 1, post.post_number);
|
||||
this.args.showFeedback("discourse_ai.ai_bot.conversation_shared");
|
||||
} else {
|
||||
this.modal.show(ShareModal, { model: post });
|
||||
}
|
||||
}
|
||||
|
||||
<template>
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
import { hbs } from "ember-cli-htmlbars";
|
||||
import { withSilencedDeprecations } from "discourse/lib/deprecated";
|
||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
|
||||
import AiBotHeaderIcon from "../discourse/components/ai-bot-header-icon";
|
||||
import AiCancelStreamingButton from "../discourse/components/post-menu/ai-cancel-streaming-button";
|
||||
import AiDebugButton from "../discourse/components/post-menu/ai-debug-button";
|
||||
import AiShareButton from "../discourse/components/post-menu/ai-share-button";
|
||||
import {
|
||||
isPostFromAiBot,
|
||||
showShareConversationModal,
|
||||
} from "../discourse/lib/ai-bot-helper";
|
||||
import { showShareConversationModal } from "../discourse/lib/ai-bot-helper";
|
||||
import { streamPostText } from "../discourse/lib/ai-streamer/progress-handlers";
|
||||
|
||||
let enabledChatBotIds = [];
|
||||
|
@ -83,7 +79,7 @@ function initializePersonaDecorator(api) {
|
|||
}
|
||||
|
||||
function initializePauseButton(api) {
|
||||
const transformerRegistered = api.registerValueTransformer(
|
||||
api.registerValueTransformer(
|
||||
"post-menu-buttons",
|
||||
({ value: dag, context: { post, firstButtonKey } }) => {
|
||||
if (isGPTBot(post.user)) {
|
||||
|
@ -94,29 +90,6 @@ function initializePauseButton(api) {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
const silencedKey =
|
||||
transformerRegistered && "discourse.post-menu-widget-overrides";
|
||||
|
||||
withSilencedDeprecations(silencedKey, () => initializePauseWidgetButton(api));
|
||||
}
|
||||
|
||||
function initializePauseWidgetButton(api) {
|
||||
api.addPostMenuButton("cancel-gpt", (post) => {
|
||||
if (isGPTBot(post.user)) {
|
||||
return {
|
||||
icon: "pause",
|
||||
action: "cancelStreaming",
|
||||
title: "discourse_ai.ai_bot.cancel_streaming",
|
||||
className: "btn btn-default cancel-streaming",
|
||||
position: "first",
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
api.attachWidgetAction("post", "cancelStreaming", function () {
|
||||
AiCancelStreamingButton.cancelStreaming(this.model);
|
||||
});
|
||||
}
|
||||
|
||||
function initializeDebugButton(api) {
|
||||
|
@ -125,7 +98,7 @@ function initializeDebugButton(api) {
|
|||
return;
|
||||
}
|
||||
|
||||
const transformerRegistered = api.registerValueTransformer(
|
||||
api.registerValueTransformer(
|
||||
"post-menu-buttons",
|
||||
({ value: dag, context: { post, firstButtonKey } }) => {
|
||||
if (post.topic?.archetype === "private_message") {
|
||||
|
@ -136,38 +109,6 @@ function initializeDebugButton(api) {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
const silencedKey =
|
||||
transformerRegistered && "discourse.post-menu-widget-overrides";
|
||||
|
||||
withSilencedDeprecations(silencedKey, () => initializeDebugWidgetButton(api));
|
||||
}
|
||||
|
||||
function initializeDebugWidgetButton(api) {
|
||||
const currentUser = api.getCurrentUser();
|
||||
|
||||
let debugAiResponse = async function ({ post }) {
|
||||
const modal = api.container.lookup("service:modal");
|
||||
AiDebugButton.debugAiResponse(post, modal);
|
||||
};
|
||||
|
||||
api.addPostMenuButton("debugAi", (post) => {
|
||||
if (post.topic?.archetype !== "private_message") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isPostFromAiBot(post, currentUser)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
action: debugAiResponse,
|
||||
icon: "info",
|
||||
className: "post-action-menu__debug-ai",
|
||||
title: "discourse_ai.ai_bot.debug_ai",
|
||||
position: "first",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function initializeShareButton(api) {
|
||||
|
@ -176,7 +117,7 @@ function initializeShareButton(api) {
|
|||
return;
|
||||
}
|
||||
|
||||
const transformerRegistered = api.registerValueTransformer(
|
||||
api.registerValueTransformer(
|
||||
"post-menu-buttons",
|
||||
({ value: dag, context: { post, firstButtonKey } }) => {
|
||||
if (post.topic?.archetype === "private_message") {
|
||||
|
@ -186,39 +127,6 @@ function initializeShareButton(api) {
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
const silencedKey =
|
||||
transformerRegistered && "discourse.post-menu-widget-overrides";
|
||||
|
||||
withSilencedDeprecations(silencedKey, () => initializeShareWidgetButton(api));
|
||||
}
|
||||
|
||||
function initializeShareWidgetButton(api) {
|
||||
const currentUser = api.getCurrentUser();
|
||||
|
||||
let shareAiResponse = async function ({ post, showFeedback }) {
|
||||
const modal = api.container.lookup("service:modal");
|
||||
AiShareButton.shareAiResponse(post, modal, showFeedback);
|
||||
};
|
||||
|
||||
api.addPostMenuButton("share", (post) => {
|
||||
// for backwards compat so we don't break if topic is undefined
|
||||
if (post.topic?.archetype !== "private_message") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isPostFromAiBot(post, currentUser)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
action: shareAiResponse,
|
||||
icon: "far-copy",
|
||||
className: "post-action-menu__share-ai",
|
||||
title: "discourse_ai.ai_bot.share",
|
||||
position: "first",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function initializeShareTopicButton(api) {
|
||||
|
|
Loading…
Reference in New Issue