@@ -12,7 +12,10 @@ import AiBotHeaderIcon from "../discourse/components/ai-bot-header-icon";
1212import AiCancelStreamingButton from "../discourse/components/post-menu/ai-cancel-streaming-button" ;
1313import AiDebugButton from "../discourse/components/post-menu/ai-debug-button" ;
1414import AiShareButton from "../discourse/components/post-menu/ai-share-button" ;
15- import { showShareConversationModal } from "../discourse/lib/ai-bot-helper" ;
15+ import {
16+ isPostFromAiBot ,
17+ showShareConversationModal ,
18+ } from "../discourse/lib/ai-bot-helper" ;
1619import { streamPostText } from "../discourse/lib/ai-streamer/progress-handlers" ;
1720
1821let enabledChatBotIds = [ ] ;
@@ -85,20 +88,20 @@ function initializePersonaDecorator(api) {
8588 ) ;
8689}
8790
88- const MAX_PERSONA_USER_ID = - 1200 ;
91+ const POST_MENU_BUTTONS_POSITION_BEFORE = [
92+ POST_MENU_LIKE_BUTTON_KEY ,
93+ POST_MENU_COPY_LINK_BUTTON_KEY ,
94+ POST_MENU_SHARE_BUTTON_KEY ,
95+ POST_MENU_SHOW_MORE_BUTTON_KEY ,
96+ ] ;
8997
9098function initializePauseButton ( api ) {
9199 const transformerRegistered = api . registerValueTransformer (
92100 "post-menu-buttons" ,
93101 ( { value : dag , context : { post } } ) => {
94102 if ( isGPTBot ( post . user ) ) {
95103 dag . add ( "ai-cancel-gpt" , AiCancelStreamingButton , {
96- before : [
97- POST_MENU_LIKE_BUTTON_KEY ,
98- POST_MENU_COPY_LINK_BUTTON_KEY ,
99- POST_MENU_SHARE_BUTTON_KEY ,
100- POST_MENU_SHOW_MORE_BUTTON_KEY ,
101- ] ,
104+ before : POST_MENU_BUTTONS_POSITION_BEFORE ,
102105 after : [ "ai-share" , "ai-debug" ] ,
103106 } ) ;
104107 }
@@ -142,12 +145,7 @@ function initializeDebugButton(api) {
142145 ( { value : dag , context : { post } } ) => {
143146 if ( post . topic ?. archetype === "private_message" ) {
144147 dag . add ( "ai-debug" , AiDebugButton , {
145- before : [
146- POST_MENU_LIKE_BUTTON_KEY ,
147- POST_MENU_COPY_LINK_BUTTON_KEY ,
148- POST_MENU_SHARE_BUTTON_KEY ,
149- POST_MENU_SHOW_MORE_BUTTON_KEY ,
150- ] ,
148+ before : POST_MENU_BUTTONS_POSITION_BEFORE ,
151149 after : "ai-share" ,
152150 } ) ;
153151 }
@@ -175,15 +173,8 @@ function initializeDebugWidgetButton(api) {
175173 return ;
176174 }
177175
178- if (
179- ! currentUser . ai_enabled_chat_bots . any (
180- ( bot ) => post . username === bot . username
181- )
182- ) {
183- // special handling for personas (persona bot users start at ID -1200 and go down)
184- if ( post . user_id > MAX_PERSONA_USER_ID ) {
185- return ;
186- }
176+ if ( ! isPostFromAiBot ( post , currentUser ) ) {
177+ return ;
187178 }
188179
189180 return {
@@ -207,12 +198,7 @@ function initializeShareButton(api) {
207198 ( { value : dag , context : { post } } ) => {
208199 if ( post . topic ?. archetype === "private_message" ) {
209200 dag . add ( "ai-share" , AiShareButton , {
210- before : [
211- POST_MENU_LIKE_BUTTON_KEY ,
212- POST_MENU_COPY_LINK_BUTTON_KEY ,
213- POST_MENU_SHARE_BUTTON_KEY ,
214- POST_MENU_SHOW_MORE_BUTTON_KEY ,
215- ] ,
201+ before : POST_MENU_BUTTONS_POSITION_BEFORE ,
216202 } ) ;
217203 }
218204
@@ -240,15 +226,8 @@ function initializeShareWidgetButton(api) {
240226 return ;
241227 }
242228
243- if (
244- ! currentUser . ai_enabled_chat_bots . any (
245- ( bot ) => post . username === bot . username
246- )
247- ) {
248- // special handling for personas (persona bot users start at ID -1200 and go down)
249- if ( post . user_id > MAX_PERSONA_USER_ID ) {
250- return ;
251- }
229+ if ( ! isPostFromAiBot ( post , currentUser ) ) {
230+ return ;
252231 }
253232
254233 return {
0 commit comments