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";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
|
|
||||||
export default class AiCancelStreamingButton extends Component {
|
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
|
@action
|
||||||
static async cancelStreaming(post) {
|
async cancelStreaming() {
|
||||||
|
const post = this.args.post;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ajax(`/discourse-ai/ai-bot/post/${post.id}/stop-streaming`, {
|
await ajax(`/discourse-ai/ai-bot/post/${post.id}/stop-streaming`, {
|
||||||
type: "POST",
|
type: "POST",
|
||||||
|
@ -20,11 +22,6 @@ export default class AiCancelStreamingButton extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
cancelStreaming() {
|
|
||||||
this.constructor.cancelStreaming(this.args.post);
|
|
||||||
}
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<DButton
|
<DButton
|
||||||
class="post-action-menu__ai-cancel-streaming cancel-streaming"
|
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);
|
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;
|
@service modal;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
debugAiResponse() {
|
debugAiResponse() {
|
||||||
this.constructor.debugAiResponse(this.args.post, this.modal);
|
this.modal.show(DebugAiModal, { model: this.args.post });
|
||||||
}
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -13,25 +13,18 @@ export default class AiDebugButton extends Component {
|
||||||
return isPostFromAiBot(args.post, args.state.currentUser);
|
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;
|
@service modal;
|
||||||
|
|
||||||
@action
|
@action
|
||||||
shareAiResponse() {
|
async shareAiResponse() {
|
||||||
this.constructor.shareAiResponse(
|
const post = this.args.post;
|
||||||
this.args.post,
|
|
||||||
this.modal,
|
if (post.post_number <= AUTO_COPY_THRESHOLD) {
|
||||||
this.args.showFeedback
|
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>
|
<template>
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
import { hbs } from "ember-cli-htmlbars";
|
import { hbs } from "ember-cli-htmlbars";
|
||||||
import { withSilencedDeprecations } from "discourse/lib/deprecated";
|
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
|
import { registerWidgetShim } from "discourse/widgets/render-glimmer";
|
||||||
import AiBotHeaderIcon from "../discourse/components/ai-bot-header-icon";
|
import AiBotHeaderIcon from "../discourse/components/ai-bot-header-icon";
|
||||||
import AiCancelStreamingButton from "../discourse/components/post-menu/ai-cancel-streaming-button";
|
import AiCancelStreamingButton from "../discourse/components/post-menu/ai-cancel-streaming-button";
|
||||||
import AiDebugButton from "../discourse/components/post-menu/ai-debug-button";
|
import AiDebugButton from "../discourse/components/post-menu/ai-debug-button";
|
||||||
import AiShareButton from "../discourse/components/post-menu/ai-share-button";
|
import AiShareButton from "../discourse/components/post-menu/ai-share-button";
|
||||||
import {
|
import { showShareConversationModal } from "../discourse/lib/ai-bot-helper";
|
||||||
isPostFromAiBot,
|
|
||||||
showShareConversationModal,
|
|
||||||
} from "../discourse/lib/ai-bot-helper";
|
|
||||||
import { streamPostText } from "../discourse/lib/ai-streamer/progress-handlers";
|
import { streamPostText } from "../discourse/lib/ai-streamer/progress-handlers";
|
||||||
|
|
||||||
let enabledChatBotIds = [];
|
let enabledChatBotIds = [];
|
||||||
|
@ -83,7 +79,7 @@ function initializePersonaDecorator(api) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializePauseButton(api) {
|
function initializePauseButton(api) {
|
||||||
const transformerRegistered = api.registerValueTransformer(
|
api.registerValueTransformer(
|
||||||
"post-menu-buttons",
|
"post-menu-buttons",
|
||||||
({ value: dag, context: { post, firstButtonKey } }) => {
|
({ value: dag, context: { post, firstButtonKey } }) => {
|
||||||
if (isGPTBot(post.user)) {
|
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) {
|
function initializeDebugButton(api) {
|
||||||
|
@ -125,7 +98,7 @@ function initializeDebugButton(api) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformerRegistered = api.registerValueTransformer(
|
api.registerValueTransformer(
|
||||||
"post-menu-buttons",
|
"post-menu-buttons",
|
||||||
({ value: dag, context: { post, firstButtonKey } }) => {
|
({ value: dag, context: { post, firstButtonKey } }) => {
|
||||||
if (post.topic?.archetype === "private_message") {
|
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) {
|
function initializeShareButton(api) {
|
||||||
|
@ -176,7 +117,7 @@ function initializeShareButton(api) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const transformerRegistered = api.registerValueTransformer(
|
api.registerValueTransformer(
|
||||||
"post-menu-buttons",
|
"post-menu-buttons",
|
||||||
({ value: dag, context: { post, firstButtonKey } }) => {
|
({ value: dag, context: { post, firstButtonKey } }) => {
|
||||||
if (post.topic?.archetype === "private_message") {
|
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) {
|
function initializeShareTopicButton(api) {
|
||||||
|
|
Loading…
Reference in New Issue