From 8413d27cf2a91a9363acf085a856f4cfa6b616bc Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 8 Sep 2020 16:35:59 +0200 Subject: [PATCH] FIX: handles different cases of canInvite/canRemove states in PM (#10607) --- .../app/widgets/private-message-map.js | 24 +++++++++++++------ config/locales/client.en.yml | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/app/widgets/private-message-map.js b/app/assets/javascripts/discourse/app/widgets/private-message-map.js index 6f397d1b363..13784716e0f 100644 --- a/app/assets/javascripts/discourse/app/widgets/private-message-map.js +++ b/app/assets/javascripts/discourse/app/widgets/private-message-map.js @@ -158,15 +158,25 @@ export default createWidget("private-message-map", { const result = [h(`div.participants${hideNamesClass}`, participants)]; const controls = []; - if ( - attrs.canInvite || - attrs.canRemoveAllowedUsers || - attrs.canRemoveSelfId - ) { + const canRemove = attrs.canRemoveAllowedUsers || attrs.canRemoveSelfId; + + if (attrs.canInvite || canRemove) { + let key; + let action = "toggleEditing"; + + if (attrs.canInvite && canRemove) { + key = "edit"; + } else if (!attrs.canInvite && canRemove) { + key = "remove"; + } else { + key = "add"; + action = "showInvite"; + } + controls.push( this.attach("button", { - action: "toggleEditing", - label: "private_message_info.edit", + action, + label: `private_message_info.${key}`, className: "btn btn-default add-remove-participant-btn", }) ); diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f0cec47959d..9c8d2bfb9ce 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1586,6 +1586,8 @@ en: title: "Message" invite: "Invite Others ..." edit: "Add or Remove ..." + remove: "Remove ..." + add: "Add ..." leave_message: "Do you really want to leave this message?" remove_allowed_user: "Do you really want to remove %{name} from this message?" remove_allowed_group: "Do you really want to remove %{name} from this message?"