@@ -10,10 +10,15 @@ import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer
1010import { escapeExpression } from "discourse/lib/utilities" ;
1111import RawHtml from "discourse/widgets/raw-html" ;
1212import RenderGlimmer from "discourse/widgets/render-glimmer" ;
13+ import { withSilencedDeprecations } from "discourse-common/lib/deprecated" ;
1314import getURL from "discourse-common/lib/get-url" ;
1415import { iconHTML , iconNode } from "discourse-common/lib/icon-library" ;
1516import discourseComputed from "discourse-common/utils/decorators" ;
1617import I18n from "I18n" ;
18+ import AssignButton , {
19+ assignPost ,
20+ unassignPost ,
21+ } from "../components/assign-button" ;
1722import BulkActionsAssignUser from "../components/bulk-actions/bulk-assign-user" ;
1823import EditTopicAssignments from "../components/modal/edit-topic-assignments" ;
1924import TopicLevelAssignMenu from "../components/topic-level-assign-menu" ;
@@ -314,47 +319,9 @@ function initialize(api) {
314319 } ,
315320 before : "top" ,
316321 } ) ;
317- if ( api . getCurrentUser ( ) ?. can_assign ) {
318- api . addPostMenuButton ( "assign" , ( post ) => {
319- if ( post . firstPost ) {
320- return ;
321- }
322- if ( post . assigned_to_user || post . assigned_to_group ) {
323- return {
324- action : "unassignPost" ,
325- icon : "user-times" ,
326- className : "unassign-post" ,
327- title : "discourse_assign.unassign_post.title" ,
328- position :
329- post . assigned_to_user ?. id === api . getCurrentUser ( ) . id
330- ? "first"
331- : "second-last-hidden" ,
332- } ;
333- } else {
334- return {
335- action : "assignPost" ,
336- icon : "user-plus" ,
337- className : "assign-post" ,
338- title : "discourse_assign.assign_post.title" ,
339- position : "second-last-hidden" ,
340- } ;
341- }
342- } ) ;
343322
344- api . attachWidgetAction ( "post" , "assignPost" , function ( ) {
345- const taskActions = getOwner ( this ) . lookup ( "service:task-actions" ) ;
346- taskActions . showAssignModal ( this . model , {
347- isAssigned : false ,
348- targetType : "Post" ,
349- } ) ;
350- } ) ;
351-
352- api . attachWidgetAction ( "post" , "unassignPost" , function ( ) {
353- const taskActions = getOwner ( this ) . lookup ( "service:task-actions" ) ;
354- taskActions . unassign ( this . model . id , "Post" ) . then ( ( ) => {
355- delete this . model . topic . indirectly_assigned_to [ this . model . id ] ;
356- } ) ;
357- } ) ;
323+ if ( api . getCurrentUser ( ) ?. can_assign ) {
324+ customizePostMenu ( api ) ;
358325 }
359326 }
360327
@@ -528,7 +495,9 @@ function initialize(api) {
528495 return new RenderGlimmer (
529496 this ,
530497 "p.assigned-to" ,
531- hbs `<AssignedToPost @assignedToUser={{@data.assignedToUser}} @assignedToGroup={{@data.assignedToGroup}} @href={{@data.href}} @post={{@data.post}} />` ,
498+ hbs `
499+ <AssignedToPost @assignedToUser={{@data.assignedToUser}} @assignedToGroup={{@data.assignedToGroup}}
500+ @href={{@data.href}} @post={{@data.post}} />` ,
532501 {
533502 assignedToUser : attrs . post . assigned_to_user ,
534503 assignedToGroup : attrs . post . assigned_to_group ,
@@ -755,6 +724,76 @@ function initialize(api) {
755724 api . addKeyboardShortcut ( "g a" , "" , { path : "/my/activity/assigned" } ) ;
756725}
757726
727+ function customizePostMenu ( api ) {
728+ const transformerRegistered = api . registerValueTransformer (
729+ "post-menu-buttons" ,
730+ ( {
731+ value : dag ,
732+ context : {
733+ post,
734+ state,
735+ firstButtonKey,
736+ lastHiddenButtonKey,
737+ secondLastHiddenButtonKey,
738+ } ,
739+ } ) => {
740+ dag . add (
741+ "assign" ,
742+ AssignButton ,
743+ post . assigned_to_user ?. id === state . currentUser . id
744+ ? {
745+ before : firstButtonKey ,
746+ }
747+ : {
748+ before : lastHiddenButtonKey ,
749+ after : secondLastHiddenButtonKey ,
750+ }
751+ ) ;
752+ }
753+ ) ;
754+
755+ const silencedKey =
756+ transformerRegistered && "discourse.post-menu-widget-overrides" ;
757+
758+ withSilencedDeprecations ( silencedKey , ( ) => customizeWidgetPostMenu ( api ) ) ;
759+ }
760+
761+ function customizeWidgetPostMenu ( api ) {
762+ api . addPostMenuButton ( "assign" , ( post ) => {
763+ if ( post . firstPost ) {
764+ return ;
765+ }
766+ if ( post . assigned_to_user || post . assigned_to_group ) {
767+ return {
768+ action : "unassignPost" ,
769+ icon : "user-times" ,
770+ className : "unassign-post" ,
771+ title : "discourse_assign.unassign_post.title" ,
772+ position :
773+ post . assigned_to_user ?. id === api . getCurrentUser ( ) . id
774+ ? "first"
775+ : "second-last-hidden" ,
776+ } ;
777+ } else {
778+ return {
779+ action : "assignPost" ,
780+ icon : "user-plus" ,
781+ className : "assign-post" ,
782+ title : "discourse_assign.assign_post.title" ,
783+ position : "second-last-hidden" ,
784+ } ;
785+ }
786+ } ) ;
787+
788+ api . attachWidgetAction ( "post" , "assignPost" , function ( ) {
789+ assignPost ( this . model , getOwner ( this ) . lookup ( "service:task-actions" ) ) ;
790+ } ) ;
791+
792+ api . attachWidgetAction ( "post" , "unassignPost" , function ( ) {
793+ unassignPost ( this . model , getOwner ( this ) . lookup ( "service:task-actions" ) ) ;
794+ } ) ;
795+ }
796+
758797const REGEXP_USERNAME_PREFIX = / ^ ( a s s i g n e d : ) / gi;
759798
760799export default {
@@ -794,7 +833,7 @@ export default {
794833 } ) ;
795834 }
796835
797- withPluginApi ( "0.13 .0" , ( api ) => {
836+ withPluginApi ( "1.34 .0" , ( api ) => {
798837 extendTopicModel ( api , PLUGIN_ID ) ;
799838 initialize ( api ) ;
800839 registerTopicFooterButtons ( api ) ;
0 commit comments