@@ -3,17 +3,30 @@ import { htmlSafe } from "@ember/template";
33import { isEmpty } from "@ember/utils" ;
44import { hbs } from "ember-cli-htmlbars" ;
55import { h } from "virtual-dom" ;
6+ import {
7+ POST_MENU_ADMIN_BUTTON_KEY ,
8+ POST_MENU_COPY_LINK_BUTTON_KEY ,
9+ POST_MENU_DELETE_BUTTON_KEY ,
10+ POST_MENU_LIKE_BUTTON_KEY ,
11+ POST_MENU_SHARE_BUTTON_KEY ,
12+ POST_MENU_SHOW_MORE_BUTTON_KEY ,
13+ } from "discourse/components/post/menu" ;
614import SearchAdvancedOptions from "discourse/components/search-advanced-options" ;
715import { renderAvatar } from "discourse/helpers/user-avatar" ;
816import { withPluginApi } from "discourse/lib/plugin-api" ;
917import { registerTopicFooterDropdown } from "discourse/lib/register-topic-footer-dropdown" ;
1018import { escapeExpression } from "discourse/lib/utilities" ;
1119import RawHtml from "discourse/widgets/raw-html" ;
1220import RenderGlimmer from "discourse/widgets/render-glimmer" ;
21+ import { withSilencedDeprecations } from "discourse-common/lib/deprecated" ;
1322import getURL from "discourse-common/lib/get-url" ;
1423import { iconHTML , iconNode } from "discourse-common/lib/icon-library" ;
1524import discourseComputed from "discourse-common/utils/decorators" ;
1625import I18n from "I18n" ;
26+ import AssignButton , {
27+ assignPost ,
28+ unassignPost ,
29+ } from "../components/assign-button" ;
1730import BulkActionsAssignUser from "../components/bulk-actions/bulk-assign-user" ;
1831import EditTopicAssignments from "../components/modal/edit-topic-assignments" ;
1932import TopicLevelAssignMenu from "../components/topic-level-assign-menu" ;
@@ -314,47 +327,9 @@ function initialize(api) {
314327 } ,
315328 before : "top" ,
316329 } ) ;
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- } ) ;
343330
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- } ) ;
331+ if ( api . getCurrentUser ( ) ?. can_assign ) {
332+ customizePostMenu ( api ) ;
358333 }
359334 }
360335
@@ -755,6 +730,77 @@ function initialize(api) {
755730 api . addKeyboardShortcut ( "g a" , "" , { path : "/my/activity/assigned" } ) ;
756731}
757732
733+ function customizePostMenu ( api ) {
734+ const transformerRegistered = api . registerValueTransformer (
735+ "post-menu-buttons" ,
736+ ( { value : dag , context : { post, state } } ) => {
737+ dag . add (
738+ "assign" ,
739+ AssignButton ,
740+ post . assigned_to_user ?. id === state . currentUser . id
741+ ? {
742+ before : [
743+ POST_MENU_LIKE_BUTTON_KEY ,
744+ POST_MENU_COPY_LINK_BUTTON_KEY ,
745+ POST_MENU_SHARE_BUTTON_KEY ,
746+ POST_MENU_SHOW_MORE_BUTTON_KEY ,
747+ ] ,
748+ }
749+ : {
750+ before : [
751+ POST_MENU_ADMIN_BUTTON_KEY ,
752+ POST_MENU_SHOW_MORE_BUTTON_KEY ,
753+ ] ,
754+ after : POST_MENU_DELETE_BUTTON_KEY ,
755+ }
756+ ) ;
757+
758+ return dag ;
759+ }
760+ ) ;
761+
762+ const silencedKey =
763+ transformerRegistered && "discourse.post-menu-widget-overrides" ;
764+
765+ withSilencedDeprecations ( silencedKey , ( ) => customizeWidgetPostMenu ( api ) ) ;
766+ }
767+
768+ function customizeWidgetPostMenu ( api ) {
769+ api . addPostMenuButton ( "assign" , ( post ) => {
770+ if ( post . firstPost ) {
771+ return ;
772+ }
773+ if ( post . assigned_to_user || post . assigned_to_group ) {
774+ return {
775+ action : "unassignPost" ,
776+ icon : "user-times" ,
777+ className : "unassign-post" ,
778+ title : "discourse_assign.unassign_post.title" ,
779+ position :
780+ post . assigned_to_user ?. id === api . getCurrentUser ( ) . id
781+ ? "first"
782+ : "second-last-hidden" ,
783+ } ;
784+ } else {
785+ return {
786+ action : "assignPost" ,
787+ icon : "user-plus" ,
788+ className : "assign-post" ,
789+ title : "discourse_assign.assign_post.title" ,
790+ position : "second-last-hidden" ,
791+ } ;
792+ }
793+ } ) ;
794+
795+ api . attachWidgetAction ( "post" , "assignPost" , function ( ) {
796+ assignPost ( this . model , getOwner ( this ) . lookup ( "service:task-actions" ) ) ;
797+ } ) ;
798+
799+ api . attachWidgetAction ( "post" , "unassignPost" , function ( ) {
800+ unassignPost ( this . model , getOwner ( this ) . lookup ( "service:task-actions" ) ) ;
801+ } ) ;
802+ }
803+
758804const REGEXP_USERNAME_PREFIX = / ^ ( a s s i g n e d : ) / gi;
759805
760806export default {
0 commit comments