A platform for community discussion. Free, open, simple.
WIP: New "Post Type" dropdown in composer header (#38068)
Jordan Vidrine938980ecb742
diff --git a/app/assets/stylesheets/common/base/compose.scss b/app/assets/stylesheets/common/base/compose.scssindex ea71c7713f5..bd760dcc04d 100644--- a/app/assets/stylesheets/common/base/compose.scss+++ b/app/assets/stylesheets/common/base/compose.scss@@ -37,6 +37,11 @@ html.composer-open:not(.has-full-page-chat) {}}+.composer-toggles-menu-content,+.composer-actions-dropdown {+ z-index: z("composer", "dropdown") + 1;+}+#reply-control {position: fixed;display: flex;@@ -218,48 +223,83 @@ html.composer-open:not(.has-full-page-chat) {}}- .composer-action-title {- display: flex;- align-items: center;- width: auto;- max-width: 100%;- min-width: 0; // allows shrinking when needed+ .composer-actions-trigger {+ border-color: var(--input-border-color);+ }- .action-title {- display: flex;- align-items: center;- line-height: normal;- min-width: 0;+ .composer-actions-trigger .d-button-label {+ max-width: 10ch;++ @include ellipsis;+ }- .topic-link,- .user-link,- .post-link {- margin-right: 8px;+ .composer-whisper-indicator {+ margin-left: auto;- @include ellipsis;+ @include viewport.until(sm) {+ .d-button-label {+ display: none;+ }++ .d-icon {+ margin-right: 0;}}+ font-size: var(--font-down-1);+ border-radius: var(--d-border-radius);- .username {- margin-right: 5px;- max-width: 100px;+ &.--public {+ --d-button-default-text-color: var(--primary-high);+ --d-button-flat-icon-color: var(--primary-high);+ }- @include ellipsis;+ &.--whispering {+ --d-button-default-text-color: var(--tertiary);+ --d-button-flat-icon-color: var(--tertiary);- @media screen and (width <= 500px) {- display: none;+ &:hover {+ background-color: var(--tertiary-200);}}+ }++ .composer-actions-reply-target-link {+ --d-button-default-text-color: var(--primary-high);+ --d-button-flat-icon-color: var(--primary-high);+ max-width: 30ch;++ @include viewport.until(sm) {+ max-width: 18ch;+ }++ &__label {+ @include ellipsis;+ }+ }++ .composer-action-title {+ display: flex;+ gap: var(--space-1);+ align-items: center;+ width: 100%;+ max-width: 100%;+ min-width: 0; // allows shrinking when neededimg.avatar {margin-right: 3px;}}+ .action-title {+ display: flex;+ gap: var(--space-1);+ align-items: center;+ width: 100%;+ max-width: 100%;+ }+.composer-controls {display: flex;- gap: 8px;- margin-left: 8px;}// Protection for languages with long strings on very small screens. This@@ -270,6 +310,12 @@ html.composer-open:not(.has-full-page-chat) {flex-wrap: wrap;}+ .composer-actions-reply-target-link {+ .d-icon {+ margin-right: none;+ }+ }+.display-edit-reason.--active {width: 100%;}@@ -279,10 +325,6 @@ html.composer-open:not(.has-full-page-chat) {margin-left: 0;margin-top: var(--space-2);}-- .composer-controls {- align-self: flex-start;- }}}@@ -548,11 +590,11 @@ html.composer-open:not(.has-full-page-chat) {flex: 1 1 auto;}- .btn-primary {- flex: 0 0 auto;+ .d-combo-button-button .d-icon {+ margin-right: 0.45em;}- .cancel {+ .d-c .cancel {align-items: center;display: flex;margin-left: 1em;@@ -635,10 +677,6 @@ html.composer-open:not(.has-full-page-chat) {font-size: 20px;vertical-align: -5.5px;}-- + .btn-mini-toggle {- margin-left: 0;- }}.composer-select-form-template {@@ -1197,3 +1235,18 @@ body.has-sidebar-page {}}}++.composer-toggle-item {+ cursor: pointer;++ @include menu-item;++ &__icons .d-toggle-switch {+ --toggle-switch-width: var(--d-sidebar-section-link-prefix-width);+ --toggle-switch-height: 16px;+ }++ &__icons .d-toggle-switch__checkbox-slider .d-icon {+ display: none;+ }+}diff --git a/app/assets/stylesheets/common/components/buttons.scss b/app/assets/stylesheets/common/components/buttons.scssindex c6503c66170..f62055c6a79 100644--- a/app/assets/stylesheets/common/components/buttons.scss+++ b/app/assets/stylesheets/common/components/buttons.scss@@ -544,18 +544,3 @@padding-left: 0;}}--.btn-mini-toggle {- border-radius: var(--d-border-radius);- padding: 0.4em 0.467em;-- .d-icon {- color: var(--primary-medium);- }-- @include hover {- .d-icon {- color: var(--primary);- }- }-}diff --git a/app/assets/stylesheets/common/components/d-toggle-switch.scss b/app/assets/stylesheets/common/components/d-toggle-switch.scssindex c1147e3e969..d0552a77ad9 100644--- a/app/assets/stylesheets/common/components/d-toggle-switch.scss+++ b/app/assets/stylesheets/common/components/d-toggle-switch.scss@@ -82,9 +82,9 @@transition: background 0.25s;.d-icon {- width: calc(var(--toggle-switch-height) * 0.54);- height: calc(var(--toggle-switch-height) * 0.54);- color: var(--secondary);+ width: calc(var(--toggle-switch-height) * 0.54) !important;+ height: calc(var(--toggle-switch-height) * 0.54) !important;+ color: var(--secondary) !important;position: absolute;top: 50%;left: calc(var(--toggle-switch-height) * 0.291);diff --git a/app/assets/stylesheets/common/components/notifications-tracking.scss b/app/assets/stylesheets/common/components/notifications-tracking.scssindex 5f2ddfb9e0a..c597c1c22e5 100644--- a/app/assets/stylesheets/common/components/notifications-tracking.scss+++ b/app/assets/stylesheets/common/components/notifications-tracking.scss@@ -1,5 +1,7 @@.pinned-options-btn,-.notifications-tracking-btn {+.notifications-tracking-btn,+.composer-actions-btn,+.composer-toggle-item {display: flex;flex: 1 0 auto;box-sizing: border-box;diff --git a/app/assets/stylesheets/common/float-kit/d-menu.scss b/app/assets/stylesheets/common/float-kit/d-menu.scssindex b0f3d88943f..64d240d12d1 100644--- a/app/assets/stylesheets/common/float-kit/d-menu.scss+++ b/app/assets/stylesheets/common/float-kit/d-menu.scss@@ -101,60 +101,7 @@&__item {.btn {- display: inline-flex;- gap: var(--d-sidebar-section-link-prefix-margin-right);- padding-inline: var(--d-sidebar-row-horizontal-padding);- width: 100%;- justify-content: flex-start;- background: rgb(0, 0, 0, 0);- border-radius: var(--d-border-radius);-- &:not(- .notifications-tracking-btn,- .--with-description,- .pinned-options-btn- ) {- height: var(--d-sidebar-row-height);- padding-block: 0;- }-- &.-selected {- background: var(--d-hover);- }-- &.btn-danger {- color: var(--danger);-- .d-icon {- color: inherit;- }- }-- .svg-icon {- width: var(--d-sidebar-section-link-prefix-width);- margin-right: 0;- }-- &:hover,- &:focus-visible {- .discourse-no-touch & {- background: var(--d-hover);- color: var(--primary);-- .d-icon {- color: inherit;- }-- &.btn-danger {- background: var(--danger-low);- color: var(--danger);-- .d-icon {- color: var(--danger-hover);- }- }- }- }+ @include menu-item;}}diff --git a/app/assets/stylesheets/common/foundation/mixins.scss b/app/assets/stylesheets/common/foundation/mixins.scssindex 88a1ffea5c5..50f1426b93e 100644--- a/app/assets/stylesheets/common/foundation/mixins.scss+++ b/app/assets/stylesheets/common/foundation/mixins.scss@@ -362,3 +362,56 @@ $hpad: 0.65em;background: var(--primary-low-mid);flex-shrink: 0;}++@mixin menu-item {+ display: inline-flex;+ gap: var(--d-sidebar-section-link-prefix-margin-right);+ padding: var(--space-2) var(--d-sidebar-row-horizontal-padding);+ width: 100%;+ justify-content: flex-start;+ background: rgb(0, 0, 0, 0);+ border-radius: var(--d-border-radius);++ &:not(.notifications-tracking-btn, .--with-description, .pinned-options-btn) {+ height: var(--d-sidebar-row-height);+ padding-block: 0;+ }++ &.-selected {+ background: var(--d-hover);+ }++ &.btn-danger {+ color: var(--danger);++ .d-icon {+ color: inherit;+ }+ }++ .svg-icon {+ width: var(--d-sidebar-section-link-prefix-width);+ margin-right: 0;+ }++ &:hover,+ &:focus-visible {+ .discourse-no-touch & {+ background: var(--d-hover);+ color: var(--primary);++ .d-icon {+ color: inherit;+ }++ &.btn-danger {+ background: var(--danger-low);+ color: var(--danger);++ .d-icon {+ color: var(--danger-hover);+ }+ }+ }+ }+}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 190b88e24ec..bee40c5b82d 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -3252,7 +3252,7 @@ en:users_placeholder: "Add users or groups"title_placeholder: "What is this discussion about in one brief sentence?"title_or_link_placeholder: "Type title, or paste a link here"- edit_reason_placeholder: "why are you editing?"+ edit_reason_placeholder: "Why are you editing?"topic_featured_link_placeholder: "Enter link shown with title."remove_featured_link: "Remove link from topic."reply_placeholder: "Type here. Use Markdown, BBCode, or HTML to format. Drag or paste images."@@ -3323,7 +3323,10 @@ en:collapse: "Minimize the composer panel"open: "Open the composer panel"abandon: "Close composer and discard draft"- edit_reason: "Add your reason for editing"+ edit_reason: "Why are you editing?"+ whisper_indicator:+ public: "Visible"+ whispering: "Whispering"enter_fullscreen: "Enter fullscreen composer"exit_fullscreen: "Exit fullscreen composer"exit_fullscreen_prompt: "Press <kbd>ESC</kbd> to exit full screen"@@ -3360,25 +3363,30 @@ en:desc: Create new message starting with same recipientsreply_to_topic:label: Reply to topic+ trigger: Topicdesc: Reply to the topic, not any specific posttoggle_whisper:label: Toggle whisper- desc: Whispers are only visible to staff members+ desc: Whispers are only visible to allowed groupscreate_topic:- label: "New topic"+ label: Create topicdesc: Create a new topiccreate_personal_message:- label: "New message"+ label: Create messagedesc: "Create a new personal message"shared_draft:label: "Shared Draft"desc: "Draft a topic that will only be visible to allowed users"toggle_topic_bump:- label: "Toggle topic bump"+ label: "Do not bump"desc: "Reply without changing latest reply date"+ create_unlisted_topic: "Unlisted topic"toggle_unlisted:label: Toggle unlisteddesc: "Unlisted topics are only accessible by direct link"+ edit_post: "Editing post"+ no_actions_available: "No actions available"+ unknown_user: "User"reload: "Reload"ignore: "Ignore"@@ -6136,7 +6144,7 @@ en:title: "Edit Table"cancel: "cancel"create: "Save"- reason: "why are you editing?"+ reason: "Why are you editing?"trigger_reason: "Add reason for edit"default_edit_reason: "Update Table with Table Editor"default_header:diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 730569ae857..13d8eadeded 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -2846,6 +2846,7 @@ en:enable_auto_grid_images: "Automatically wraps images in [grid] tags when 3 or more images are uploaded in the composer."enable_new_checkbox_style: "Enable the redesigned checkbox style for FormKit checkboxes."enable_new_post_reactions_menu: "Enable the redesigned post likes and reactions menu, with infinite scroll and a native mobile experience."+ enable_new_composer_actions: "Enable the redesigned composer actions menu and combo save button, with whisper, no-bump, and unlist toggles surfaced next to the save action."experimental_impersonation_time_limit_minutes: "How long before an impersonation session is automatically ended."page_loading_indicator: "Configure the loading indicator which appears during page navigations within Discourse. 'Spinner' is a full page indicator. 'Slider' shows a narrow bar at the top of the screen."show_user_menu_avatars: "Show user avatars in the user menu"diff --git a/config/site_settings.yml b/config/site_settings.ymlindex 77e05beb7b4..71105daa019 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -4431,6 +4431,15 @@ experimental:status: "stable"impact: "feature,all_members"learn_more_url: "https://meta.discourse.org/t/-/389820"+ enable_new_composer_actions:+ default: false+ client: true+ hidden: true+ area: "experimental"+ upcoming_change:+ status: "alpha"+ impact: "feature,all_members"+ learn_more_url: "https://meta.discourse.org/t/-/403635"rename_faq_to_guidelines:default: falsehidden: truediff --git a/frontend/discourse/app/components/composer-action-title.gjs b/frontend/discourse/app/components/composer-action-title.gjsindex a6db2a07b24..df6881f5bb6 100644--- a/frontend/discourse/app/components/composer-action-title.gjs+++ b/frontend/discourse/app/components/composer-action-title.gjs@@ -6,6 +6,7 @@ import { action, computed, set } from "@ember/object";import { service } from "@ember/service";import { trustHTML } from "@ember/template";import { tagName } from "@ember-decorators/component";+import ComposerActionsNew from "discourse/components/composer-actions-new";import escape from "discourse/lib/escape";import { iconHTML } from "discourse/lib/icon-library";import {@@ -17,7 +18,8 @@ import {PRIVATE_MESSAGE,REPLY,} from "discourse/models/composer";-import ComposerActions from "discourse/select-kit/components/composer-actions";+import ComposerActionsOld from "discourse/select-kit/components/composer-actions";+import DButton from "discourse/ui-kit/d-button";import { i18n } from "discourse-i18n";const TITLES = {@@ -34,6 +36,7 @@ export default class ComposerActionTitle extends Component {// text customizations to use those.@service composer;+ @service siteSettings;@computed("model.replyOptions")get options() {@@ -142,35 +145,62 @@ export default class ComposerActionTitle extends Component {<template><div class="composer-action-title" ...attributes>- <ComposerActions- @composerModel={{this.model}}- @replyOptions={{this.model.replyOptions}}- @canWhisper={{this.canWhisper}}- @canUnlistTopic={{this.canUnlistTopic}}- @action={{this.model.action}}- @tabindex={{this.tabindex}}- @topic={{this.model.topic}}- @post={{this.model.post}}- @whisper={{this.model.whisper}}- @noBump={{this.model.noBump}}- @options={{hash mobilePlacementStrategy="fixed"}}- />-- <span class="action-title" role="heading" aria-level="1">- {{this.actionTitle}}- {{#if this.replyTargetSegment}}- {{#if this.canEditReplyTo}}- <button- type="button"- class="composer-edit-reply-to"- title={{i18n "composer.change_reply_to.open"}}- {{on "click" this.openChangeReplyToModal}}- >{{this.replyTargetSegment}}</button>- {{else}}- {{this.replyTargetSegment}}+ {{#if this.siteSettings.enable_new_composer_actions}}+ <span class="action-title" role="heading" aria-level="1">+ <ComposerActionsNew+ @composerModel={{this.model}}+ @replyOptions={{this.model.replyOptions}}+ @action={{this.model.action}}+ @tabindex={{this.tabindex}}+ @topic={{this.model.topic}}+ @post={{this.model.post}}+ @options={{hash mobilePlacementStrategy="fixed"}}+ />++ {{#if this.replyTargetSegment}}+ {{#if this.canEditReplyTo}}+ <DButton+ @action={{this.openChangeReplyToModal}}+ @title="composer.change_reply_to.open"+ @translatedLabel={{this.replyTargetSegment}}+ class="composer-edit-reply-to btn-default"+ />+ {{else}}+ {{this.replyTargetSegment}}+ {{/if}}{{/if}}- {{/if}}- </span>+ </span>+ {{else}}+ <ComposerActionsOld+ @composerModel={{this.model}}+ @replyOptions={{this.model.replyOptions}}+ @canWhisper={{this.canWhisper}}+ @canUnlistTopic={{this.canUnlistTopic}}+ @action={{this.model.action}}+ @tabindex={{this.tabindex}}+ @topic={{this.model.topic}}+ @post={{this.model.post}}+ @whisper={{this.model.whisper}}+ @noBump={{this.model.noBump}}+ @options={{hash mobilePlacementStrategy="fixed"}}+ />++ <span class="action-title" role="heading" aria-level="1">+ {{this.actionTitle}}+ {{#if this.replyTargetSegment}}+ {{#if this.canEditReplyTo}}+ <button+ type="button"+ class="composer-edit-reply-to"+ title={{i18n "composer.change_reply_to.open"}}+ {{on "click" this.openChangeReplyToModal}}+ >{{this.replyTargetSegment}}</button>+ {{else}}+ {{this.replyTargetSegment}}+ {{/if}}+ {{/if}}+ </span>+ {{/if}}</div></template>}diff --git a/frontend/discourse/app/components/composer-actions-new.gjs b/frontend/discourse/app/components/composer-actions-new.gjsnew file mode 100644index 00000000000..9349263d723--- /dev/null+++ b/frontend/discourse/app/components/composer-actions-new.gjs@@ -0,0 +1,528 @@+import Component from "@glimmer/component";+import { cached, tracked } from "@glimmer/tracking";+import { registerDestructor } from "@ember/destroyable";+import { fn } from "@ember/helper";+import { on } from "@ember/modifier";+import { action, get } from "@ember/object";+import { service } from "@ember/service";+import DMenu from "discourse/float-kit/components/d-menu";+import { ComposerActionItemBuilder } from "discourse/lib/composer/action-items";+import { prioritizeNameFallback } from "discourse/lib/settings";+import {+ applyBehaviorTransformer,+ applyValueTransformer,+} from "discourse/lib/transformer";+import {+ ADD_TRANSLATION,+ CREATE_SHARED_DRAFT,+ CREATE_TOPIC,+ EDIT,+ EDIT_SHARED_DRAFT,+ PRIVATE_MESSAGE,+ REPLY,+} from "discourse/models/composer";+import { or } from "discourse/truth-helpers";+import DButton from "discourse/ui-kit/d-button";+import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";+import DTextField from "discourse/ui-kit/d-text-field";+import DToggleSwitch from "discourse/ui-kit/d-toggle-switch";+import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";+import dIcon from "discourse/ui-kit/helpers/d-icon";+import dAutoFocus from "discourse/ui-kit/modifiers/d-auto-focus";+import { i18n } from "discourse-i18n";++export default class ComposerActions extends Component {+ @service composer;+ @service composerActionState;+ @service router;+ @service site;++ @tracked replyTargetInViewport = false;+ #observer = null;++ constructor() {+ super(...arguments);+ this.composerActionState.remember({ topic: this.topic, post: this.post });++ this.router.on("routeDidChange", this.refreshReplyTargetObserver);+ this.refreshReplyTargetObserver();++ registerDestructor(this, () => {+ this.router.off("routeDidChange", this.refreshReplyTargetObserver);+ this.#disconnectReplyTargetObserver();+ });+ }++ @action+ refreshReplyTargetObserver() {+ this.#disconnectReplyTargetObserver();++ const postId = this.post?.id;+ if (!postId || !this.isOnComposerTopic) {+ this.replyTargetInViewport = false;+ return;+ }++ requestAnimationFrame(() => {+ if (this.isDestroying || this.isDestroyed) {+ return;+ }++ const element = document.querySelector(+ `article[data-post-id="${postId}"]`+ );++ if (!element) {+ this.replyTargetInViewport = false;+ return;+ }++ this.#observer = new IntersectionObserver((entries) => {+ for (const entry of entries) {+ this.replyTargetInViewport = entry.isIntersecting;+ }+ });+ this.#observer.observe(element);+ });+ }++ #disconnectReplyTargetObserver() {+ this.#observer?.disconnect();+ this.#observer = null;+ }++ get action() {+ return this.args.action;+ }++ get topic() {+ return this.args.topic;+ }++ get post() {+ return this.args.post;+ }++ get composerModel() {+ return this.args.composerModel;+ }++ get replyOptions() {+ return this.args.replyOptions;+ }++ get isEditing() {+ return this.action === EDIT;+ }++ get isInSlowMode() {+ return this.topic?.slow_mode_seconds > 0;+ }++ @cached+ get templateData() {+ const { action: currentAction, isInSlowMode, isEditing } = this;+ if (this.composerModel) {+ get(this.composerModel, "tags");+ get(this.composerModel, "category");+ get(this.composerModel, "whisper");+ get(this.composerModel, "noBump");+ get(this.composerModel, "unlistTopic");+ }++ let iconName;+ if (currentAction === CREATE_TOPIC) {+ iconName = "far-pen-to-square";+ } else if (currentAction === PRIVATE_MESSAGE) {+ iconName = "envelope";+ } else if (currentAction === CREATE_SHARED_DRAFT) {+ iconName = "far-clipboard";+ } else if (isInSlowMode) {+ iconName = "hourglass-start";+ } else if (isEditing) {+ iconName = "pencil";+ } else if (currentAction === REPLY && this.composerModel?.whisper) {+ iconName = "far-eye-slash";+ } else {+ iconName = "share";+ }++ const availableActions = this._computeAvailableActions();++ return {+ icon: iconName,+ label: this._labelText(),+ actions: availableActions,+ hasActions: availableActions.length > 0,+ };+ }++ _labelText() {+ const pluginLabel = this.composerModel?.customizationFor("actionTitle");+ if (pluginLabel) {+ return pluginLabel;+ }++ const currentAction = this.action;+ if (currentAction === CREATE_TOPIC) {+ return i18n("composer.composer_actions.create_topic.label");+ }+ if (currentAction === PRIVATE_MESSAGE) {+ return i18n("composer.composer_actions.create_personal_message.label");+ }+ if (currentAction === CREATE_SHARED_DRAFT) {+ return i18n("composer.composer_actions.shared_draft.label");+ }+ if (currentAction === EDIT_SHARED_DRAFT) {+ return i18n("composer.edit_shared_draft");+ }+ if (currentAction === ADD_TRANSLATION) {+ return i18n("composer.translations.title");+ }+ if (currentAction === EDIT) {+ return i18n("composer.composer_actions.edit_post");+ }+ if (currentAction === REPLY) {+ const isReplyingToPost =+ this.post &&+ this.replyOptions?.userAvatar &&+ this.replyOptions?.userLink;++ if (isReplyingToPost) {+ return this._postDisplayName(this.post);+ }+ return i18n("composer.composer_actions.reply_to_topic.trigger");+ }++ return i18n("composer.composer_actions.create_topic.label");+ }++ _postDisplayName(post) {+ const fallback = i18n("composer.composer_actions.unknown_user");+ if (!post) {+ return fallback;+ }+ if (post === this.post && this.replyOptions?.userLink?.anchor) {+ return this.replyOptions.userLink.anchor;+ }+ return prioritizeNameFallback(post.name, post.username) || fallback;+ }++ _computeAvailableActions() {+ this.composerActionState.remember({ topic: this.topic, post: this.post });++ const currentAction = this.action;+ const currentTopic = this.topic;+ const currentPost = this.post;++ const composerActionItemBuilder = new ComposerActionItemBuilder(+ this,+ currentAction,+ currentTopic,+ currentPost,+ this.replyOptions,+ this.composerModel+ );++ const composerActionItems = composerActionItemBuilder.build();++ return applyValueTransformer(+ "composer-actions-content",+ composerActionItems,+ {+ action: currentAction,+ topic: currentTopic,+ post: currentPost,+ composerModel: this.composerModel,+ }+ );+ }++ get hasToggles() {+ return (+ this.composer.canToggleWhisper ||+ this.composer.canToggleNoBump ||+ this.composer.canUnlistTopic+ );+ }++ get hasMenuContent() {+ return this.templateData.hasActions || this.hasToggles;+ }++ get replyTargetHref() {+ if (this.action !== REPLY) {+ return null;+ }++ const options = this.replyOptions;+ if (this.post && options?.postLink) {+ return options.postLink.href;+ }+ if (options?.topicLink) {+ return options.topicLink.href;+ }+ return null;+ }++ get isOnComposerTopic() {+ const composerTopicId = this.composerModel?.topic?.id;+ if (!composerTopicId) {+ return false;+ }++ let route = this.router.currentRoute;+ while (route) {+ if (route.name === "topic") {+ return parseInt(route.params?.id, 10) === composerTopicId;+ }+ route = route.parent;+ }+ return false;+ }++ get isReplyTargetOnScreen() {+ return this.replyTargetInViewport;+ }++ get replyTargetLabel() {+ if (this.post) {+ return this.replyOptions?.postLink?.anchor;+ }+ if (this.isOnComposerTopic && !this.site.mobileView) {+ return null;+ }+ return this.replyOptions?.topicLink?.anchor;+ }++ get showReplyTargetLink() {+ if (!this.replyTargetHref) {+ return false;+ }++ if (this.site.mobileView) {+ return true;+ }++ if (this.post) {+ return !this.isReplyTargetOnScreen;+ }++ return !this.isOnComposerTopic;+ }++ get replyTargetTitle() {+ if (this.post) {+ return i18n("composer.composer_actions.reply_to_post.label", {+ postUsername: this._postDisplayName(this.post),+ postNumber: this.post.post_number,+ });+ }+ return i18n("composer.composer_actions.reply_to_topic.label");+ }++ @action+ toggleWhisper() {+ this.composerModel.toggleProperty("whisper");+ }++ @action+ runToggleAction(actionFn, event) {+ event.preventDefault();+ actionFn();+ }++ @action+ registerDmenuApi(api) {+ this.dmenuApi = api;+ }++ @action+ async onSelectAction(actionId) {+ await this.dmenuApi?.close({ focusTrigger: true });++ const options = this.composerModel.getProperties(+ "draftKey",+ "draftSequence",+ "title",+ "reply",+ "disableScopedCategory",+ "whisper",+ "noBump",+ "unlistTopic"+ );++ this.composerActionState.remember({ topic: this.topic, post: this.post });++ const handled = await this.composerActionState.selectAction(actionId, {+ options,+ composerModel: this.composerModel,+ topic: this.topic,+ post: this.post,+ });++ if (!handled) {+ applyBehaviorTransformer("composer-actions-on-select", () => {}, {+ actionId,+ options,+ model: this.composerModel,+ });+ }+ }++ <template>+ {{#let this.templateData as |data|}}+ {{#if this.hasMenuContent}}+ <DMenu+ @label={{data.label}}+ @icon={{data.icon}}+ @modalForMobile={{true}}+ @closeOnClickOutside={{true}}+ @closeOnEscape={{true}}+ @onRegisterApi={{this.registerDmenuApi}}+ @triggerClass="composer-actions-trigger btn-flat btn-icon-text"+ @contentClass="composer-actions-dropdown"+ class="composer-actions-new"+ >+ <:trigger>+ {{dIcon "angle-down" class="composer-actions-caret"}}+ </:trigger>++ <:content>+ <DDropdownMenu as |dropdown|>+ {{#each data.actions key="id" as |availAction|}}+ {{#unless availAction.isToggle}}+ <dropdown.item>+ <DButton+ class="composer-actions-btn+ {{if availAction.description '--with-description'}}"+ @action={{fn this.onSelectAction availAction.id}}+ data-action-id={{availAction.id}}+ >+ <div class="composer-actions-btn__icons">+ {{dIcon availAction.icon}}+ </div>+ <div class="composer-actions-btn__texts">+ <span class="composer-actions-btn__label">+ {{availAction.name}}+ </span>+ <span class="composer-actions-btn__description">+ {{availAction.description}}+ </span>+ </div>+ </DButton>+ </dropdown.item>+ {{/unless}}+ {{/each}}+ {{#unless (or data.actions.length this.hasToggles)}}+ <div class="composer-actions-btn">+ {{i18n "composer.composer_actions.no_actions_available"}}+ </div>+ {{/unless}}++ {{#if this.hasToggles}}+ <dropdown.divider />+ <div class="composer-actions-toggles">+ {{#each data.actions key="id" as |availAction|}}+ {{#if availAction.isToggle}}+ <dropdown.item>+ {{! eslint-disable-next-line ember/template-no-invalid-interactive }}+ <div+ class={{dConcatClass+ availAction.class+ "composer-toggle-item --with-description btn"+ }}+ {{on+ "click"+ (fn this.runToggleAction availAction.action)+ }}+ >+ <div class="composer-toggle-item__icons">+ <DToggleSwitch+ @state={{availAction.state}}+ aria-label={{availAction.ariaLabel}}+ />+ </div>+ <div class="composer-toggle-item__texts">+ <span+ class="composer-toggle-item__label"+ >{{availAction.label}}</span>+ <span+ class="composer-toggle-item__description"+ >{{availAction.description}}</span>+ </div>++ </div>+ </dropdown.item>+ {{/if}}+ {{/each}}+ </div>+ {{/if}}+ </DDropdownMenu>+ </:content>+ </DMenu>++ {{#if this.showReplyTargetLink}}+ <a+ class={{dConcatClass+ "composer-actions-reply-target-link btn btn-transparent"+ (if this.replyTargetLabel "btn-icon-text" "btn-icon no-text")+ (if this.site.mobileView "btn-small")+ }}+ href={{this.replyTargetHref}}+ title={{this.replyTargetTitle}}+ aria-label={{this.replyTargetTitle}}+ >+ {{dIcon "link"}}+ {{#if this.replyTargetLabel}}+ <span+ class="d-button-label composer-actions-reply-target-link__label"+ >{{this.replyTargetLabel}}</span>+ {{/if}}+ </a>+ {{/if}}+ {{else if this.composer.showEditReason}}+ <span+ class="composer-actions-trigger composer-actions-trigger--static composer-actions-trigger--editing"+ >+ <DTextField+ @value={{this.composer.editReason}}+ @id="edit-reason"+ @maxlength="255"+ @placeholderKey="composer.edit_reason_placeholder"+ {{dAutoFocus}}+ />+ </span>+ {{else if this.composer.canEdit}}+ <DButton+ @action={{this.composer.displayEditReason}}+ @icon={{data.icon}}+ @label="composer.edit_reason"+ class="composer-actions-trigger composer-actions-trigger--static btn-transparent btn-icon-text"+ />+ {{else}}+ <span class="composer-actions-trigger composer-actions-trigger--static">+ {{dIcon data.icon}}+ <span class="d-button-label">{{data.label}}</span>+ </span>+ {{/if}}++ {{#if this.composer.canToggleWhisper}}+ <DButton+ @action={{this.toggleWhisper}}+ @icon={{if this.composerModel.whisper "far-eye-slash" "far-eye"}}+ @label={{if+ this.composerModel.whisper+ "composer.whisper_indicator.whispering"+ "composer.whisper_indicator.public"+ }}+ class={{dConcatClass+ "composer-whisper-indicator btn-transparent"+ (if this.composerModel.whisper "--whispering" "--public")+ (if this.site.mobileView "btn-small")+ }}+ />+ {{/if}}+ {{/let}}+ </template>+}diff --git a/frontend/discourse/app/components/composer-container.gjs b/frontend/discourse/app/components/composer-container.gjsindex 17671202458..f277cd97afc 100644--- a/frontend/discourse/app/components/composer-container.gjs+++ b/frontend/discourse/app/components/composer-container.gjs@@ -207,7 +207,7 @@ export default class ComposerContainer extends Component {<div class="reply-to">{{#unless this.composer.model.viewFullscreen}}- <div class="reply-details">+ {{#if this.siteSettings.enable_new_composer_actions}}<ComposerActionTitle@model={{this.composer.model}}@canWhisper={{this.composer.canWhisper}}@@ -237,36 +237,68 @@ export default class ComposerContainer extends Component {@name="composer-action-after"@outletArgs={{lazyHash model=this.composer.model}}/>+ {{else}}+ <div class="reply-details">+ <ComposerActionTitle+ @model={{this.composer.model}}+ @canWhisper={{this.composer.canWhisper}}+ @canUnlistTopic={{this.composer.canUnlistTopic}}+ />- {{#if this.site.desktopView}}- {{#if this.composer.model.unlistTopic}}- <span class="unlist">({{i18n "composer.unlist"}})</span>+ {{#if this.composer.showTranslationSelector}}+ <DropdownSelectBox+ @nameProperty="name"+ @valueProperty="value"+ @value={{this.composer.selectedTranslationLocale}}+ @content={{this.availableContentLocalizationLocales}}+ @onChange={{this.updateSelectedTranslationLocale}}+ @options={{hash+ icon="language"+ showCaret=true+ filterable=true+ disabled=this.composer.loading+ placement="bottom-start"+ translatedNone=(i18n "composer.translations.select")+ }}+ class="translation-selector-dropdown btn-small"+ />{{/if}}- {{#if this.composer.isWhispering}}- {{#if this.composer.model.noBump}}- <span class="no-bump">{{dIcon "anchor"}}</span>++ <PluginOutlet+ @name="composer-action-after"+ @outletArgs={{lazyHash model=this.composer.model}}+ />++ {{#if this.site.desktopView}}+ {{#if this.composer.model.unlistTopic}}+ <span class="unlist">({{i18n "composer.unlist"}})</span>+ {{/if}}+ {{#if this.composer.isWhispering}}+ {{#if this.composer.model.noBump}}+ <span class="no-bump">{{dIcon "anchor"}}</span>+ {{/if}}{{/if}}{{/if}}- {{/if}}- {{#if this.composer.canEdit}}- <LinkToInput- @onClick={{this.composer.displayEditReason}}- @showInput={{this.composer.showEditReason}}- @icon="pen-to-square"- class="display-edit-reason- {{if this.composer.showEditReason '--active'}}"- title={{i18n "composer.edit_reason"}}- >- <DTextField- @value={{this.composer.editReason}}- @id="edit-reason"- @maxlength="255"- @placeholderKey="composer.edit_reason_placeholder"- />- </LinkToInput>- {{/if}}- </div>+ {{#if this.composer.canEdit}}+ <LinkToInput+ @onClick={{this.composer.displayEditReason}}+ @showInput={{this.composer.showEditReason}}+ @icon="pen-to-square"+ class="display-edit-reason+ {{if this.composer.showEditReason '--active'}}"+ title={{i18n "composer.edit_reason"}}+ >+ <DTextField+ @value={{this.composer.editReason}}+ @id="edit-reason"+ @maxlength="255"+ @placeholderKey="composer.edit_reason_placeholder"+ />+ </LinkToInput>+ {{/if}}+ </div>+ {{/if}}{{/unless}}<PluginOutlet@@ -441,10 +473,6 @@ export default class ComposerContainer extends Component {class="discard-button btn-transparent"@title={{this.composer.cancelLabel}}/>-- {{#if this.composer.model.noBump}}- <span class="no-bump">{{dIcon "anchor"}}</span>- {{/if}}{{/if}}<span>@@ -553,7 +581,7 @@ export default class ComposerContainer extends Component {@translatedTitle={{this.composer.toggleText}}@icon="angles-left"class={{dConcatClass- "btn-transparent btn-mini-toggle toggle-preview"+ "btn-transparent btn-small toggle-preview"(unless this.composer.isPreviewVisible "active")}}/>diff --git a/frontend/discourse/app/components/composer-toggles.gjs b/frontend/discourse/app/components/composer-toggles.gjsindex 59f2cd121c0..1eee0b52597 100644--- a/frontend/discourse/app/components/composer-toggles.gjs+++ b/frontend/discourse/app/components/composer-toggles.gjs@@ -49,9 +49,7 @@ export default class ComposerToggles extends Component {<template><div class={{dConcatClass "composer-controls" this.additionalClasses}}>- <span>- <PluginOutlet @name="before-composer-toggles" @connectorTagName="div" />- </span>+ <PluginOutlet @name="before-composer-toggles" @connectorTagName="div" />{{#if this.site.mobileView}}<DButton@@ -59,7 +57,7 @@ export default class ComposerToggles extends Component {@action={{@toggleToolbar}}@title={{this.toggleToolbarTitle}}@preventFocus={{true}}- class="btn-transparent toggle-toolbar btn-mini-toggle"+ class="btn-transparent toggle-toolbar btn-small"/>{{/if}}@@ -68,7 +66,7 @@ export default class ComposerToggles extends Component {@icon={{this.fullscreenIcon}}@action={{@toggleFullscreen}}@title={{this.fullscreenTitle}}- class="btn-transparent toggle-fullscreen btn-mini-toggle"+ class="btn-transparent toggle-fullscreen btn-small"/>{{/if}}@@ -77,7 +75,7 @@ export default class ComposerToggles extends Component {@icon="angles-down"@action={{@toggleComposer}}@title="composer.collapse"- class="btn-transparent toggler toggle-minimize btn-mini-toggle"+ class="btn-transparent toggler toggle-minimize btn-small"/>{{/if}}@@ -86,7 +84,7 @@ export default class ComposerToggles extends Component {@icon="xmark"@action={{@saveAndClose}}@title="composer.save_and_close"- class="btn-transparent toggler toggle-save-and-close btn-mini-toggle"+ class="btn-transparent toggler toggle-save-and-close btn-small"/>{{/if}}</div>diff --git a/frontend/discourse/app/lib/composer/action-items.js b/frontend/discourse/app/lib/composer/action-items.jsnew file mode 100644index 00000000000..a9c7046fc46--- /dev/null+++ b/frontend/discourse/app/lib/composer/action-items.js@@ -0,0 +1,293 @@+import { getOwner, setOwner } from "@ember/owner";+import { service } from "@ember/service";+import { isNone } from "@ember/utils";+import { prioritizeNameFallback } from "discourse/lib/settings";+import {+ CREATE_SHARED_DRAFT,+ CREATE_TOPIC,+ EDIT,+ PRIVATE_MESSAGE,+ REPLY,+} from "discourse/models/composer";+import { i18n } from "discourse-i18n";++export class ComposerActionItemBuilder {+ @service currentUser;+ @service site;+ @service composerActionState;+ @service composer;++ constructor(context, action, topic, post, replyOptions, composerModel) {+ setOwner(this, getOwner(context));++ this.action = action;+ this.topic = topic;+ this.post = post;+ this.replyOptions = replyOptions;+ this.composerModel = composerModel;+ }++ get isEditing() {+ return this.action === EDIT;+ }++ get snapshotPost() {+ return this.composerActionState.snapshot.post;+ }++ get snapshotTopic() {+ return this.composerActionState.snapshot.topic;+ }++ get isExistingTopic() {+ return !isNone(this.topic?.id);+ }++ get isCreatingTopic() {+ return this.action === CREATE_TOPIC || this.action === CREATE_SHARED_DRAFT;+ }++ build() {+ const items = [];++ if (this.isEditing) {+ return items;+ }++ // All of these items can be counted as a "maybe"+ // and will either return the item or null. Look at+ // the function itself for logic on whether the item+ // will be added to the list.+ items.push(this.#createSharedDraft());+ items.push(this.#createTopic());+ items.push(this.#replyToTopic());++ if (this.isExistingTopic) {+ items.push(this.#replyToPost());+ items.push(this.#replyAsNewTopic());+ items.push(this.#replyAsNewGroupMessage());+ }++ if (this.isCreatingTopic) {+ items.push(this.#replyToSnapshottedPost());+ items.push(this.#replyToSnapshottedTopic());+ items.push(this.#createPersonalMessage());+ }++ if (this.composer.canToggleWhisper) {+ items.push(this.#toggleWhisper());+ }++ if (this.composer.canToggleNoBump) {+ items.push(this.#toggleNoBump());+ }++ if (this.composer.canUnlistTopic) {+ items.push(this.#toggleUnlisted());+ }++ return items.filter(Boolean).flat();+ }++ // NOTE: Some duplication with ComposerActionsNew here...probably+ // fine but at some point we may want to consolidate.+ #postDisplayName(post) {+ const fallback = i18n("composer.composer_actions.unknown_user");+ if (!post) {+ return fallback;+ }+ if (post === this.post && this.replyOptions?.userLink?.anchor) {+ return this.replyOptions.userLink.anchor;+ }+ return prioritizeNameFallback(post.name, post.username) || fallback;+ }++ #replyAsNewTopic() {+ if (+ this.action === REPLY &&+ !this.topic.isPrivateMessage &&+ this.currentUser.can_create_topic+ ) {+ return {+ name: i18n("composer.composer_actions.reply_as_new_topic.label"),+ description: i18n("composer.composer_actions.reply_as_new_topic.desc"),+ icon: "far-pen-to-square",+ id: "reply_as_new_topic",+ };+ }+ }++ #replyAsNewGroupMessage() {+ if (+ this.action === REPLY &&+ this.topic.isPrivateMessage &&+ this.topic.details &&+ (this.topic.details.allowed_users?.length > 1 ||+ this.topic.details.allowed_groups?.length > 0)+ ) {+ return {+ name: i18n(+ "composer.composer_actions.reply_as_new_group_message.label"+ ),+ description: i18n(+ "composer.composer_actions.reply_as_new_group_message.desc"+ ),+ icon: "plus",+ id: "reply_as_new_group_message",+ };+ }+ }++ #replyToPost() {+ const canRestoreReplyToPost =+ this.action === REPLY &&+ !this.post &&+ this.snapshotPost &&+ this.snapshotTopic &&+ this.topic?.id === this.snapshotTopic.id;++ if (+ (this.action !== REPLY && this.post) ||+ (this.action === REPLY &&+ this.post &&+ !(this.replyOptions?.userAvatar && this.replyOptions?.userLink)) ||+ canRestoreReplyToPost+ ) {+ const postForLabel = this.post || this.snapshotPost;++ return {+ name: i18n("composer.composer_actions.reply_to_post.label", {+ postUsername: this.#postDisplayName(postForLabel),+ }),+ description: i18n("composer.composer_actions.reply_to_post.desc"),+ icon: "share",+ id: "reply_to_post",+ };+ }+ }++ #replyToTopic() {+ if (+ (this.action !== CREATE_TOPIC &&+ this.action !== PRIVATE_MESSAGE &&+ ((this.action !== REPLY && this.topic) ||+ (this.action === REPLY &&+ this.replyOptions?.userAvatar &&+ this.replyOptions?.userLink &&+ this.replyOptions?.topicLink))) ||+ (this.action === PRIVATE_MESSAGE && this.snapshotTopic)+ ) {+ return {+ name: i18n("composer.composer_actions.reply_to_topic.label"),+ description: i18n("composer.composer_actions.reply_to_topic.desc"),+ icon: "share",+ id: "reply_to_topic",+ };+ }+ }++ #replyToSnapshottedPost() {+ if (this.snapshotPost && this.snapshotTopic) {+ return {+ name: i18n("composer.composer_actions.reply_to_post.label", {+ postUsername: this.#postDisplayName(this.snapshotPost),+ }),+ description: i18n("composer.composer_actions.reply_to_post.desc"),+ icon: "share",+ id: "reply_to_post",+ };+ }+ }++ #replyToSnapshottedTopic() {+ if (this.snapshotTopic) {+ return {+ name: i18n("composer.composer_actions.reply_to_topic.label"),+ description: i18n("composer.composer_actions.reply_to_topic.desc"),+ icon: "share",+ id: "reply_to_topic",+ };+ }+ }++ #createPersonalMessage() {+ if (this.currentUser?.can_send_private_messages) {+ return {+ name: i18n("composer.composer_actions.create_personal_message.label"),+ description: i18n(+ "composer.composer_actions.create_personal_message.desc"+ ),+ icon: "envelope",+ id: "create_private_message",+ };+ }+ }++ #createSharedDraft() {+ if (this.action === CREATE_TOPIC && this.site.shared_drafts_category_id) {+ return {+ name: i18n("composer.composer_actions.shared_draft.label"),+ description: i18n("composer.composer_actions.shared_draft.desc"),+ icon: "far-clipboard",+ id: "shared_draft",+ };+ }+ }++ #createTopic() {+ if (+ (this.action === CREATE_SHARED_DRAFT ||+ this.action === PRIVATE_MESSAGE) &&+ this.currentUser?.can_create_topic+ ) {+ return {+ name: i18n("composer.composer_actions.create_topic.label"),+ description: i18n("composer.composer_actions.create_topic.desc"),+ icon: "far-pen-to-square",+ id: "create_topic",+ };+ }+ }++ #toggleWhisper() {+ return {+ isToggle: true,+ action: () => this.composerModel.toggleProperty("whisper"),+ class: "composer-toggle-whisper",+ icon: "far-eye-slash",+ label: i18n("composer.composer_actions.toggle_whisper.label"),+ description: i18n("composer.composer_actions.toggle_whisper.desc"),+ state: this.composerModel.whisper,+ ariaLabel: i18n("composer.composer_actions.toggle_whisper.label"),+ id: "toggle_whisper",+ };+ }++ #toggleNoBump() {+ return {+ isToggle: true,+ action: () => this.composerModel.toggleProperty("noBump"),+ class: "composer-toggle-no-bump",+ icon: "anchor",+ label: i18n("composer.composer_actions.toggle_topic_bump.label"),+ description: i18n("composer.composer_actions.toggle_topic_bump.desc"),+ state: this.composerModel.noBump,+ ariaLabel: i18n("composer.composer_actions.toggle_topic_bump.label"),+ id: "toggle_topic_bump",+ };+ }++ #toggleUnlisted() {+ return {+ isToggle: true,+ action: () => this.composerModel.toggleProperty("unlistTopic"),+ class: "composer-toggle-unlisted",+ icon: "far-eye-slash",+ label: i18n("composer.composer_actions.toggle_unlisted.label"),+ description: i18n("composer.composer_actions.toggle_unlisted.desc"),+ state: this.composerModel.unlistTopic,+ ariaLabel: i18n("composer.composer_actions.toggle_unlisted.label"),+ id: "toggle_unlisted",+ };+ }+}diff --git a/frontend/discourse/app/lib/registry/transformers.js b/frontend/discourse/app/lib/registry/transformers.jsindex d84faa13a9d..0b02e60e007 100644--- a/frontend/discourse/app/lib/registry/transformers.js+++ b/frontend/discourse/app/lib/registry/transformers.js@@ -9,6 +9,7 @@*/// eslint-discourse keep-array-sortedexport const BEHAVIOR_TRANSFORMERS = Object.freeze([+ "composer-actions-on-select","composer-position:correct-scroll-position","composer-position:editor-touch-move","custom-homepage-model",@@ -43,6 +44,7 @@ export const VALUE_TRANSFORMERS = Object.freeze(["category-display-name","category-sort-orders","category-text-color",+ "composer-actions-content","composer-editor-quoted-post-avatar-template","composer-editor-reply-placeholder","composer-force-editor-mode",diff --git a/frontend/discourse/app/models/composer.js b/frontend/discourse/app/models/composer.jsindex 7ad9c9ebcf3..99a531eadc6 100644--- a/frontend/discourse/app/models/composer.js+++ b/frontend/discourse/app/models/composer.js@@ -128,7 +128,7 @@ export const SAVE_ICONS = {[EDIT]: "pencil",[EDIT_SHARED_DRAFT]: "far-clipboard",[REPLY]: "reply",- [CREATE_TOPIC]: "plus",+ [CREATE_TOPIC]: "far-pen-to-square",[PRIVATE_MESSAGE]: "envelope",[CREATE_SHARED_DRAFT]: "far-clipboard",};@@ -219,7 +219,7 @@ export default class Composer extends RestModel {? this.post?.locale: null;- unlistTopic = false;+ @tracked unlistTopic = false;noBump = false;draftSaving = false;draftForceSave = false;diff --git a/frontend/discourse/app/services/composer-action-state.js b/frontend/discourse/app/services/composer-action-state.jsnew file mode 100644index 00000000000..92dd93ef387--- /dev/null+++ b/frontend/discourse/app/services/composer-action-state.js@@ -0,0 +1,219 @@+import Service, { service } from "@ember/service";+import { escapeExpression } from "discourse/lib/utilities";+import {+ CREATE_SHARED_DRAFT,+ CREATE_TOPIC,+ PRIVATE_MESSAGE,+ REPLY,+} from "discourse/models/composer";+import Draft from "discourse/models/draft";+import { i18n } from "discourse-i18n";++export default class ComposerActionStateService extends Service {+ @service composer;+ @service dialog;++ topicSnapshot = null;+ postSnapshot = null;++ remember({ topic, post }) {+ if (topic && (!this.topicSnapshot || topic.id !== this.topicSnapshot.id)) {+ this.topicSnapshot = topic;+ this.postSnapshot = post;+ }++ if (post && (!this.postSnapshot || post.id !== this.postSnapshot.id)) {+ this.postSnapshot = post;+ }+ }++ clear() {+ this.topicSnapshot = null;+ this.postSnapshot = null;+ }++ get snapshot() {+ return { topic: this.topicSnapshot, post: this.postSnapshot };+ }++ async selectAction(actionId, { options, composerModel, topic, post }) {+ this.remember({ topic, post });++ switch (actionId) {+ case "reply_as_new_group_message":+ await this.replyAsNewGroupMessageSelected(options, topic);+ return true;+ case "reply_as_new_topic":+ await this.replyAsNewTopicSelected(options, composerModel);+ return true;+ case "reply_to_post":+ await this.replyToPostSelected(options);+ return true;+ case "reply_to_topic":+ await this.replyToTopicSelected(options);+ return true;+ case "shared_draft":+ await this.sharedDraftSelected(options, composerModel);+ return true;+ case "create_topic":+ await this.createTopicSelected(options, composerModel);+ return true;+ case "create_private_message":+ await this.createPrivateMessageSelected(options, composerModel);+ return true;+ default:+ return false;+ }+ }++ async replyAsNewGroupMessageSelected(options, topic) {+ const recipients = [];+ const details = topic.details;+ details.allowed_users.forEach((u) => recipients.push(u.username));+ details.allowed_groups.forEach((g) => recipients.push(g.name));++ options.action = PRIVATE_MESSAGE;+ options.recipients = recipients.join(",");+ options.archetypeId = "private_message";++ await this.#replyFromExisting(+ options,+ this.postSnapshot,+ this.topicSnapshot+ );+ }++ async replyAsNewTopicSelected(options, composerModel) {+ const response = await Draft.get("new_topic");++ if (response.draft) {+ this.dialog.confirm({+ message: i18n("composer.composer_actions.reply_as_new_topic.confirm"),+ confirmButtonLabel: "composer.ok_proceed",+ didConfirm: () => this.#replyAsNewTopicSelect(options, composerModel),+ });+ } else {+ await this.#replyAsNewTopicSelect(options, composerModel);+ }+ }++ async replyToPostSelected(options) {+ options.action = REPLY;+ options.post = this.postSnapshot;+ await this.#openComposer(options);+ }++ async replyToTopicSelected(options) {+ options.action = REPLY;+ options.topic = this.topicSnapshot;+ await this.#openComposer(options);+ }++ async sharedDraftSelected(options, composerModel) {+ await this.#switchCreate(options, CREATE_SHARED_DRAFT, composerModel);+ }++ async createTopicSelected(options, composerModel) {+ await this.#switchCreate(options, CREATE_TOPIC, composerModel);+ }++ async createPrivateMessageSelected(options, composerModel) {+ options.archetypeId = "private_message";+ await this.#switchCreate(options, PRIVATE_MESSAGE, composerModel);+ }++ async #replyAsNewTopicSelect(options, composerModel) {+ options.action = CREATE_TOPIC;+ options.draftKey = this.composer.topicDraftKey;+ options.categoryId = composerModel.topic?.category?.id;+ options.disableScopedCategory = true;++ await this.#replyFromExisting(+ options,+ this.postSnapshot,+ this.topicSnapshot+ );+ }++ async #switchCreate(options, composerAction, composerModel) {+ options.action = composerAction;+ options.categoryId = composerModel.categoryId;+ options.topicTitle = composerModel.title;+ options.tags = composerModel.tags;+ await this.#openComposer(options);+ }++ #continuedFromText(post, topic) {+ let url = post?.url || topic?.url;+ const topicTitle = topic?.title;++ if (!url || !topicTitle) {+ return;+ }++ url = `${location.protocol}//${location.host}${url}`;+ const link = `[${escapeExpression(topicTitle)}](${url})`;+ return i18n("post.continue_discussion", {+ postLink: link,+ });+ }++ async #replyFromExisting(options, post, topic) {+ const snapshot = this.snapshot;++ this.#clearUnsupportedToggles(options);+ await this.composer.destroyDraft();+ this.composer.close();+ this.#restoreSnapshot(snapshot);+ await this.composer.open({+ ...options,+ prependText: this.#continuedFromText(post, topic),+ });+ this.#reapplyToggles(options);+ }++ async #openComposer(options) {+ const snapshot = this.snapshot;++ this.#clearUnsupportedToggles(options);+ this.composer.closeComposer();+ this.#restoreSnapshot(snapshot);+ await this.composer.open(options);+ this.#reapplyToggles(options);+ }++ #restoreSnapshot({ topic, post }) {+ this.topicSnapshot = topic;+ this.postSnapshot = post;+ }++ #clearUnsupportedToggles(options) {+ if (options.action !== REPLY) {+ options.whisper = false;+ options.noBump = false;+ }++ if (options.action !== CREATE_TOPIC) {+ options.unlistTopic = false;+ }+ }++ #reapplyToggles(options) {+ const model = this.composer.model;+ if (!model) {+ return;+ }++ if (model.creatingTopic && options.unlistTopic) {+ model.set("unlistTopic", true);+ }++ if (model.replyingToTopic && options.whisper) {+ model.set("whisper", true);+ }++ if (model.replyingToTopic && options.noBump) {+ model.set("noBump", true);+ }+ }+}diff --git a/frontend/discourse/app/services/composer.js b/frontend/discourse/app/services/composer.jsindex 14a67185f25..335cec6f3c2 100644--- a/frontend/discourse/app/services/composer.js+++ b/frontend/discourse/app/services/composer.js@@ -107,6 +107,7 @@ export function addComposerSaveErrorCallback(callback) {export default class ComposerService extends Service {@service appEvents;@service capabilities;+ @service composerActionState;@service currentUser;@service dialog;@service keyValueStore;@@ -226,6 +227,14 @@ export default class ComposerService extends Service {return this.model?.creatingTopic && this.isStaffUser;}+ @computed("model.action", "isStaffUser", "currentUser.trust_level")+ get canToggleNoBump() {+ return (+ this.model?.action === Composer.REPLY &&+ (this.isStaffUser || this.currentUser?.trust_level === 4)+ );+ }+@computed("replyingToWhisper", "model.whisper")get isWhispering() {return this.replyingToWhisper || this.model?.whisper;@@ -427,11 +436,6 @@ export default class ComposerService extends Service {return this.model?.editingPost && !this.model?.topic?.canEditTags;}- @computed("canWhisper", "replyingToWhisper")- get showWhisperToggle() {- return this.canWhisper && !this.replyingToWhisper;- }-@computed("model.post")get replyingToWhisper() {return (@@ -509,6 +513,14 @@ export default class ComposerService extends Service {return this.whisperer && this.model?.action === Composer.REPLY;}+ @computed("canWhisper", "model.post.post_type", "site.post_types.whisper")+ get canToggleWhisper() {+ return (+ this.canWhisper &&+ this.model?.post?.post_type !== this.site.post_types?.whisper+ );+ }+_setupPopupMenuOption(option) {// Backwards compatibility support for when we used to accept a function.// This can be dropped when `addToolbarPopupMenuOptionsCallback` is removed from `plugin-api.js`.@@ -1422,6 +1434,7 @@ export default class ComposerService extends Service {if (result.responseJson.route_to) {// TODO: await this:this.destroyDraft();+ this.composerActionState.clear();if (result.responseJson.message) {return this.dialog.alert({message: result.responseJson.message,@@ -1681,6 +1694,8 @@ export default class ComposerService extends Service {tags = await this.filterTags(tags);+ this.composerActionState.clear();+return this.open({prioritizedCategoryId: categoryId,topicCategoryId: categoryId,@@ -1699,6 +1714,9 @@ export default class ComposerService extends Service {@actionasync openNewMessage({ title, body, recipients, hasGroups, tags }) {tags = await this.filterTags(tags);++ this.composerActionState.clear();+return this.open({action: Composer.PRIVATE_MESSAGE,recipients,@@ -2069,6 +2087,8 @@ export default class ComposerService extends Service {// This is a temporary solution to reset the saved form template state while we don't store draftsthis.set("formTemplateInitialValues", undefined);++ this.composerActionState.clear();}@computed("model.action")diff --git a/frontend/discourse/tests/acceptance/composer-actions-new-test.js b/frontend/discourse/tests/acceptance/composer-actions-new-test.jsnew file mode 100644index 00000000000..5487cf391d8--- /dev/null+++ b/frontend/discourse/tests/acceptance/composer-actions-new-test.js@@ -0,0 +1,644 @@+import { click, fillIn, visit, waitFor } from "@ember/test-helpers";+import { test } from "qunit";+import sinon from "sinon";+import { cloneJSON } from "discourse/lib/object";+import Draft from "discourse/models/draft";+import discoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";+import topicFixtures from "discourse/tests/fixtures/topic";+import userFixtures from "discourse/tests/fixtures/user-fixtures";+import {+ acceptance,+ selectText,+ updateCurrentUser,+} from "discourse/tests/helpers/qunit-helpers";+import selectKit from "discourse/tests/helpers/select-kit-helper";+import { i18n } from "discourse-i18n";++function composerActionsDropdown() {+ return {+ async expand() {+ await click(".composer-actions-trigger");+ },+ async selectRowByValue(value) {+ await click(`[data-action-id='${value}']`);+ },+ rows() {+ return document.querySelectorAll(+ ".composer-actions-dropdown [data-action-id]"+ );+ },+ actionIds() {+ return [...this.rows()].map((row) => row.dataset.actionId);+ },+ };+}++acceptance(`Composer Actions (new composer actions)`, function (needs) {+ needs.user({+ id: 5,+ username: "kris",+ whisperer: true,+ });+ needs.settings({+ prioritize_username_in_ux: true,+ display_name_on_posts: false,+ enable_new_composer_actions: true,+ });+ needs.site({ can_tag_topics: true });+ needs.pretender((server, helper) => {+ server.put("/u/kris.json", () => helper.response({ user: {} }));+ const cardResponse = cloneJSON(userFixtures["/u/shade/card.json"]);+ server.get("/u/shade/card.json", () => helper.response(cardResponse));+ server.get("/c/shared-drafts/24/l/latest.json", () => {+ const response = cloneJSON(discoveryFixtures["/c/bug/1/l/latest.json"]);+ response.topic_list.can_create_topic = true;+ response.topic_list.filter = "c/shared-drafts/24/l/latest";++ return helper.response(response);+ });+ });++ test("replying to post", async function (assert) {+ const composerActions = composerActionsDropdown();++ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");+ await composerActions.expand();++ assert.deepEqual(composerActions.actionIds().sort(), [+ "reply_as_new_topic",+ "reply_to_topic",+ ]);+ });++ test("replying to post - reply_to_topic", async function (assert) {+ const composerActions = composerActionsDropdown();++ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");+ await fillIn(+ ".d-editor-input",+ "test replying to topic when initially replied to post"+ );++ await composerActions.expand();+ await composerActions.selectRowByValue("reply_to_topic");++ assert+ .dom(".composer-actions-trigger")+ .includesText(i18n("composer.composer_actions.reply_to_topic.trigger"));+ assert+ .dom(".d-editor-input")+ .hasValue("test replying to topic when initially replied to post");+ });++ test("toggle whisper via actions dropdown for whisperers", async function (assert) {+ updateCurrentUser({ admin: false, moderator: false });++ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ await click(".composer-actions-trigger");++ assert+ .dom(".composer-toggle-whisper")+ .exists("whisper toggle item is visible in dropdown");++ await click(".composer-toggle-whisper .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-whisper .d-toggle-switch__checkbox[aria-checked='true']"+ )+ .exists("whisper toggle is on after click");++ await click(".composer-toggle-whisper .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-whisper .d-toggle-switch__checkbox[aria-checked='false']"+ )+ .exists("whisper toggle is off after second click");+ });++ test("replying to post - reply_as_new_topic", async function (assert) {+ sinon.stub(Draft, "get").resolves({ draft: "", draft_sequence: 0 });++ const composerActions = composerActionsDropdown();+ const categoryChooser = selectKit(".title-wrapper .category-chooser");+ const categoryChooserReplyArea = selectKit(".reply-area .category-chooser");+ const quote = "test replying as new topic when initially replied to post";++ await visit("/t/internationalization-localization/280");++ await click("#topic-title .d-icon-pencil");+ await categoryChooser.expand();+ await categoryChooser.selectRowByValue(4);+ await click("#topic-title .submit-edit");++ await click("article#post_3 button.reply");+ await fillIn(".d-editor-input", quote);++ await composerActions.expand();+ await composerActions.selectRowByValue("reply_as_new_topic");++ assert.strictEqual(categoryChooserReplyArea.header().name(), "faq");+ assert.dom(".d-editor-input").includesValue(quote);+ });++ test("reply_as_new_topic without a new_topic draft", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click(".create.reply");+ const composerActions = composerActionsDropdown();+ await composerActions.expand();+ await composerActions.selectRowByValue("reply_as_new_topic");+ assert.dom(".dialog-body").doesNotExist();+ });++ test("reply_as_new_group_message", async function (assert) {+ await visit("/t/lorem-ipsum-dolor-sit-amet/130");+ await click(".create.reply");+ const composerActions = composerActionsDropdown();+ await composerActions.expand();+ await composerActions.selectRowByValue("reply_as_new_group_message");++ const privateMessageUsers = selectKit("#private-message-users");+ assert.deepEqual(privateMessageUsers.header().value(), "foo,foo_group");+ });++ test("reply_as_new_topic without a permission to create topic", async function (assert) {+ updateCurrentUser({ can_create_topic: false });+ await visit("/t/internationalization-localization/280");+ await click(".create.reply");+ const composerActions = composerActionsDropdown();+ await composerActions.expand();+ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_as_new_topic']")+ .doesNotExist("reply as new topic option is not visible");+ });++ test("interactions", async function (assert) {+ const composerActions = composerActionsDropdown();+ const quote = "Life is like riding a bicycle.";++ await visit("/t/short-topic-with-two-posts/54077");+ await click("article#post_2 button.reply");+ await fillIn(".d-editor-input", quote);+ await composerActions.expand();+ await composerActions.selectRowByValue("reply_to_topic");++ assert+ .dom(".composer-actions-trigger")+ .includesText(i18n("composer.composer_actions.reply_to_topic.trigger"));+ assert.dom(".d-editor-input").hasValue(quote);++ await composerActions.expand();++ assert.deepEqual(composerActions.actionIds().sort(), [+ "reply_as_new_topic",+ "reply_to_post",+ ]);++ await composerActions.selectRowByValue("reply_to_post");+ await composerActions.expand();++ assert.dom(".composer-actions-trigger").includesText("tms");+ assert.dom(".d-editor-input").hasValue(quote);+ assert.deepEqual(composerActions.actionIds().sort(), [+ "reply_as_new_topic",+ "reply_to_topic",+ ]);++ await composerActions.selectRowByValue("reply_as_new_topic");+ await composerActions.expand();++ assert.dom(".d-editor-input").includesValue(quote);+ assert.deepEqual(composerActions.actionIds().sort(), [+ "create_private_message",+ "reply_to_post",+ "reply_to_topic",+ "shared_draft",+ ]);+ });++ test("interactions - private message", async function (assert) {+ const composerActions = composerActionsDropdown();++ await visit("/t/internationalization-localization/280");+ await click('#post_4 a[data-user-card="shade"]');+ await click(".usercard-controls .compose-pm .btn-primary");+ await composerActions.expand();++ assert.deepEqual(composerActions.actionIds().sort(), ["create_topic"]);+ });++ test("toggle no-bump via actions dropdown", async function (assert) {+ await visit("/t/short-topic-with-two-posts/54077");+ await click("article#post_2 button.reply");++ await click(".composer-actions-trigger");++ assert+ .dom(".composer-toggle-no-bump")+ .exists("no-bump toggle item is visible in dropdown");++ await click(".composer-toggle-no-bump .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-no-bump .d-toggle-switch__checkbox[aria-checked='true']"+ )+ .exists("no-bump toggle is on after click");++ await click(".composer-toggle-no-bump .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-no-bump .d-toggle-switch__checkbox[aria-checked='false']"+ )+ .exists("no-bump toggle is off after second click");+ });++ test("replying to post as staff shows whisper + no-bump toggles in dropdown", async function (assert) {+ updateCurrentUser({ admin: true });+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ await click(".composer-actions-trigger");++ assert+ .dom(".composer-toggle-whisper")+ .exists("whisper toggle is visible for staff");+ assert+ .dom(".composer-toggle-no-bump")+ .exists("no-bump toggle is visible for staff");+ });++ test("replying to post as TL3 user shows no toggles in dropdown", async function (assert) {+ updateCurrentUser({+ moderator: false,+ admin: false,+ trust_level: 3,+ whisperer: false,+ groups: [{ id: 13, name: "tl3_group" }],+ });+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ await click(".composer-actions-trigger");++ assert+ .dom(".composer-toggle-whisper")+ .doesNotExist("whisper toggle is not visible for TL3 non-whisperer");+ assert+ .dom(".composer-toggle-no-bump")+ .doesNotExist("no-bump toggle is not visible for TL3 non-whisperer");+ });++ test("replying to post as TL4 user shows no-bump toggle in dropdown", async function (assert) {+ updateCurrentUser({+ moderator: false,+ admin: false,+ trust_level: 4,+ whisperer: false,+ groups: [{ id: 13, name: "tl4_group" }],+ });+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ await click(".composer-actions-trigger");++ assert+ .dom(".composer-toggle-no-bump")+ .exists("no-bump toggle is visible for TL4");+ });++ test("editing post", async function (assert) {+ const composerActions = composerActionsDropdown();++ await visit("/t/internationalization-localization/280");+ await click("article#post_1 button.show-more-actions");+ await click("article#post_1 button.edit");+ await composerActions.expand();++ assert.deepEqual(+ composerActions.actionIds(),+ [],+ "no switch actions are offered while editing a post"+ );+ });++ test("trigger shows correct icon for reply mode", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ assert+ .dom(".composer-actions-trigger svg.d-icon-share")+ .exists("shows share icon when replying");+ });++ test("trigger shows correct icon for create topic mode", async function (assert) {+ await visit("/");+ await click("#create-topic");++ assert+ .dom(".composer-actions-trigger svg.d-icon-far-pen-to-square")+ .exists("shows pen-to-square icon when creating topic");+ });++ test("trigger shows correct icon for editing", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click("article#post_1 button.show-more-actions");+ await click("article#post_1 button.edit");++ assert+ .dom(".composer-actions-trigger svg.d-icon-pencil")+ .exists("shows pencil icon when editing");+ });++ test("trigger shows correct label for reply mode", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");++ assert+ .dom(".composer-actions-trigger")+ .includesText("codinghorror", "shows reply to post label");+ });++ test("trigger shows correct label for create topic mode", async function (assert) {+ await visit("/");+ await click("#create-topic");++ assert+ .dom(".composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.create_topic.label"),+ "shows create topic label"+ );+ });++ test("create topic mode shows correct actions and unlisted toggle", async function (assert) {+ const composer = this.owner.lookup("service:composer");+ const composerActions = composerActionsDropdown();+ updateCurrentUser({ admin: true });++ await visit("/");+ await click("#create-topic");+ await composerActions.expand();++ assert+ .dom(+ ".composer-actions-dropdown [data-action-id='create_private_message']"+ )+ .exists("shows create private message action");++ assert+ .dom(".composer-toggle-unlisted")+ .exists("unlisted toggle is visible for staff in create topic mode");++ await click(".composer-toggle-unlisted .d-toggle-switch__checkbox");+ composer.model.set("noBump", true);++ assert+ .dom(+ ".composer-toggle-unlisted .d-toggle-switch__checkbox[aria-checked='true']"+ )+ .exists("unlisted toggle is on after click");++ await composerActions.selectRowByValue("create_private_message");++ assert.false(+ composer.model.unlistTopic,+ "unlisted state is cleared when switching to a private message"+ );+ assert.false(+ composer.model.noBump,+ "no-bump state is cleared when switching to a private message"+ );++ await composerActions.expand();+ assert+ .dom(".composer-toggle-unlisted")+ .doesNotExist("unlisted toggle is not shown in private message mode");+ });++ test("create topic mode does not show reply_as_new_topic", async function (assert) {+ const composerActions = composerActionsDropdown();++ await visit("/");+ await click("#create-topic");+ await composerActions.expand();++ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_as_new_topic']")+ .doesNotExist("does not show reply_as_new_topic in create topic mode");+ });+});++function stubDraftResponse() {+ sinon.stub(Draft, "get").resolves({+ draft:+ '{"reply":"dum de dum da ba.","action":"createTopic","title":"dum da ba dum dum","categoryId":null,"archetypeId":"regular","metaData":null,"composerTime":540879,"typingTime":3400}',+ draft_sequence: 0,+ });+}++acceptance(+ `Composer Actions With New Topic Draft (new composer actions)`,+ function (needs) {+ needs.user({ whisperer: true });++ needs.site({+ can_tag_topics: true,+ });++ needs.settings({+ enable_new_composer_actions: true,+ });++ test("shared draft", async function (assert) {+ updateCurrentUser({ draft_count: 1 });+ stubDraftResponse();++ await visit("/");+ await click("button.topic-drafts-menu-trigger");+ await waitFor(".topic-drafts-menu-content");+ await click(+ ".topic-drafts-menu-content .topic-drafts-item:first-child button"+ );++ await fillIn(+ "#reply-title",+ "This is the new text for the title using 'quotes'"+ );+ await fillIn(".d-editor-input", "This is the new text for the post");++ const tags = selectKit(".mini-tag-chooser");+ await tags.expand();+ await tags.selectRowByName("monkey");++ const composerActions = composerActionsDropdown();+ await composerActions.expand();+ await composerActions.selectRowByValue("shared_draft");++ assert.strictEqual(tags.header().name(), "monkey", "tags are not reset");+ assert+ .dom("#reply-title")+ .hasValue("This is the new text for the title using 'quotes'");++ assert+ .dom("#reply-control .btn-primary.create .d-button-label")+ .hasText(i18n("composer.create_shared_draft"));+ assert+ .dom(".composer-actions-trigger svg.d-icon-far-clipboard")+ .exists("shared draft icon is visible");++ await composerActions.expand();+ assert+ .dom(".composer-actions-dropdown [data-action-id='create_topic']")+ .exists("can switch back to create topic from shared draft mode");+ assert+ .dom(+ ".composer-actions-dropdown [data-action-id='create_private_message']"+ )+ .exists("can switch to PM from shared draft mode");+ });++ test("reply_as_new_topic with new_topic draft", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click(".create.reply");++ stubDraftResponse();++ const composerActions = composerActionsDropdown();+ await composerActions.expand();+ await composerActions.selectRowByValue("reply_as_new_topic");++ assert+ .dom(".dialog-body")+ .hasText(i18n("composer.composer_actions.reply_as_new_topic.confirm"));+ await click(".dialog-footer .btn-primary");++ assert.dom(".d-editor-input").hasValue(/^Continuing the discussion from/);+ });+ }+);++acceptance(`Prioritize Username (new composer actions)`, function (needs) {+ needs.user();+ needs.settings({+ prioritize_username_in_ux: true,+ display_name_on_posts: false,+ enable_new_composer_actions: true,+ });++ test("Reply to post use username", async function (assert) {+ await visit("/t/short-topic-with-two-posts/54079");+ await click("article#post_2 button.reply");++ assert.dom(".composer-actions-trigger").includesText("james_john");+ });++ test("Quotes use username", async function (assert) {+ await visit("/t/short-topic-with-two-posts/54079");+ await selectText("#post_2 p");+ await click(".insert-quote");+ assert+ .dom(".d-editor-input")+ .hasValue(+ '[quote="james_john, post:2, topic:54079, full:true"]\nThis is a short topic.\n[/quote]\n\n'+ );+ });+});++acceptance(`Prioritize Full Name (new composer actions)`, function (needs) {+ needs.user();+ needs.settings({+ prioritize_username_in_ux: false,+ display_name_on_posts: true,+ enable_new_composer_actions: true,+ });++ test("Reply to post use full name", async function (assert) {+ await visit("/t/short-topic-with-two-posts/54079");+ await click("article#post_2 button.reply");++ assert+ .dom(".composer-actions-trigger")+ .includesText("james, john, the third");+ });++ test("Quotes use full name", async function (assert) {+ await visit("/t/short-topic-with-two-posts/54079");+ await selectText("#post_2 p");+ await click(".insert-quote");+ assert+ .dom(".d-editor-input")+ .hasValue(+ '[quote="james, john, the third, post:2, topic:54079, full:true, username:james_john"]\nThis is a short topic.\n[/quote]\n\n'+ );+ });++ test("Quoting a nested quote returns the correct username", async function (assert) {+ await visit("/t/short-topic-with-two-posts/54079");+ await selectText("#post_4 p");+ await click(".insert-quote");+ assert+ .dom(".d-editor-input")+ .hasValue(+ '[quote="james_john, post:2, topic:54079"]\nThis is a short topic.\n[/quote]\n\n'+ );+ });+});++acceptance(`Slow Mode (new composer actions)`, function (needs) {+ needs.user();+ needs.settings({ enable_new_composer_actions: true });+ needs.pretender((server, helper) => {+ server.get("/t/130.json", () => {+ const json = cloneJSON(topicFixtures["/t/130.json"]);+ json.slow_mode_seconds = 600;+ json.slow_mode_enabled_until = "2040-01-01T04:00:00.000Z";+ return helper.response(json);+ });+ });++ test("trigger shows the regular reply label with the slow-mode icon", async function (assert) {+ await visit("/t/internationalization-localization/130");+ await click("article#post_1 button.reply");++ assert+ .dom(".composer-actions-trigger svg.d-icon-hourglass-start")+ .exists("uses the slow-mode hourglass icon");+ assert+ .dom(".composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.reply_to_topic.trigger"),+ "falls back to the standard reply-to-topic trigger label"+ );+ });+});++acceptance(+ `Prioritizing Name fall back (new composer actions)`,+ function (needs) {+ needs.user();+ needs.settings({+ prioritize_username_in_ux: false,+ display_name_on_posts: true,+ enable_new_composer_actions: true,+ });++ test("Quotes fall back to username if name is not present", async function (assert) {+ await visit("/t/internationalization-localization/130");+ // select a user with no name+ await selectText("#post_1 p");+ await click(".insert-quote");+ assert+ .dom(".d-editor-input")+ .hasValue(+ '[quote="bianca, post:1, topic:130, full:true"]\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas a varius ipsum. Nunc euismod, metus non vulputate malesuada, ligula metus pharetra tortor, vel sodales arcu lacus sed mauris. Nam semper, orci vitae fringilla placerat, dui tellus convallis felis, ultricies laoreet sapien mi et metus. Mauris facilisis, mi fermentum rhoncus feugiat, dolor est vehicula leo, id porta leo ex non enim. In a ligula vel tellus commodo scelerisque non in ex. Pellentesque semper leo quam, nec varius est viverra eget. Donec vehicula sem et massa faucibus tempus.\n[/quote]\n\n'+ );+ });+ }+);diff --git a/frontend/discourse/tests/acceptance/composer-new-test.js b/frontend/discourse/tests/acceptance/composer-new-test.jsnew file mode 100644index 00000000000..fbeb60f1930--- /dev/null+++ b/frontend/discourse/tests/acceptance/composer-new-test.js@@ -0,0 +1,352 @@+import { click, fillIn, settled, visit } from "@ember/test-helpers";+import { module, test } from "qunit";+import sinon from "sinon";+import { cloneJSON } from "discourse/lib/object";+import { withPluginApi } from "discourse/lib/plugin-api";+import { CREATE_TOPIC } from "discourse/models/composer";+import Draft from "discourse/models/draft";+import TopicFixtures from "discourse/tests/fixtures/topic";+import {+ acceptance,+ updateCurrentUser,+} from "discourse/tests/helpers/qunit-helpers";+import selectKit from "discourse/tests/helpers/select-kit-helper";+import { i18n } from "discourse-i18n";++acceptance(`Composer (new composer actions)`, function (needs) {+ needs.user({+ id: 5,+ username: "kris",+ whisperer: true,+ });+ needs.settings({+ general_category_id: 1,+ default_composer_category: 1,+ enable_new_composer_actions: true,+ });+ needs.site({+ can_tag_topics: true,+ categories: [+ {+ id: 1,+ name: "General",+ slug: "general",+ permission: 1,+ topic_template: null,+ },+ ],+ });+ needs.pretender((server, helper) => {+ server.put("/u/kris.json", () => helper.response({ user: {} }));+ server.get("/t/960.json", () => {+ const topicList = cloneJSON(TopicFixtures["/t/9/1.json"]);+ topicList.post_stream.posts[2].post_type = 4;+ return helper.response(topicList);+ });+ });++ test("Replying to the first post in a topic is a topic reply", async function (assert) {+ await visit("/t/internationalization-localization/280");++ await click("#post_1 .reply.create");+ assert+ .dom(".composer-actions-trigger")+ .includesText(i18n("composer.composer_actions.reply_to_topic.trigger"));++ await click("#post_1 .reply.create");+ assert+ .dom(".composer-actions-trigger")+ .includesText(i18n("composer.composer_actions.reply_to_topic.trigger"));+ });++ test("Composer can toggle whispers when whisperer user", async function (assert) {+ await visit("/t/this-is-a-test-topic/9");+ await click(".topic-post[data-post-number='1'] button.reply");++ await click(".composer-actions-trigger");++ assert+ .dom(".composer-toggle-whisper")+ .exists("whisper toggle item is visible in dropdown");++ await click(".composer-toggle-whisper .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-whisper .d-toggle-switch__checkbox[aria-checked='true']"+ )+ .exists("sets the post type to whisper");++ await click(".composer-toggle-whisper .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-whisper .d-toggle-switch__checkbox[aria-checked='false']"+ )+ .exists("removes the whisper mode");+ });++ module(+ "Composer can switch between new topic and new PM in different contexts",+ function () {+ test("within post/topic context", async function (assert) {+ const composer = this.owner.lookup("service:composer");++ await visit("/t/this-is-a-test-topic/54081");+ await click(".topic-post[data-post-number='1'] button.reply");+ await click(".composer-actions-trigger");+ assert+ .dom(+ ".composer-actions-dropdown [data-action-id='create_private_message']"+ )+ .doesNotExist("New message option is not present when in reply mode");+ await click(".composer-actions-trigger");++ await visit("/");+ await composer.openNewTopic();+ await settled();+ await click(".composer-actions-trigger");+ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_to_topic']")+ .doesNotExist(+ "stale topic context is cleared when opening a fresh new-topic composer"+ );+ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_to_post']")+ .doesNotExist(+ "stale post context is cleared when opening a fresh new-topic composer"+ );++ await click("[data-action-id='create_private_message']");+ assert+ .dom(".save-or-cancel button")+ .hasText(i18n("composer.create_pm"));++ await click(".composer-actions-trigger");+ await click("[data-action-id='create_topic']");+ assert+ .dom(".save-or-cancel button")+ .hasText(i18n("composer.create_topic"));+ });++ test("fresh new message clears stale reply context", async function (assert) {+ const composer = this.owner.lookup("service:composer");++ await visit("/t/this-is-a-test-topic/54081");+ await click(".topic-post[data-post-number='1'] button.reply");++ await visit("/");+ await composer.openNewMessage({ recipients: "shade" });+ await settled();++ await click(".composer-actions-trigger");+ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_to_topic']")+ .doesNotExist(+ "stale topic context is cleared when opening a fresh message composer"+ );+ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_to_post']")+ .doesNotExist(+ "stale post context is cleared when opening a fresh message composer"+ );+ });++ test("topic context is cleared after a successful save", async function (assert) {+ await visit("/t/internationalization-localization/280");+ await click("article#post_3 button.reply");+ await fillIn(".d-editor-input", "this is a successful reply");+ await click("#reply-control button.create");++ await visit("/");+ await click("#create-topic");+ await click(".composer-actions-trigger");++ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_to_topic']")+ .doesNotExist(+ "reply_to_topic is not surfaced after the previous composer was saved"+ );+ assert+ .dom(".composer-actions-dropdown [data-action-id='reply_to_post']")+ .doesNotExist(+ "reply_to_post is not surfaced after the previous composer was saved"+ );+ });+ }+ );++ test("Composer can toggle between reply and createTopic", async function (assert) {+ updateCurrentUser({ admin: true });+ await visit("/t/this-is-a-test-topic/54081");+ await click(".topic-post[data-post-number='1'] button.reply");++ await click(".composer-actions-trigger");+ await click(".composer-toggle-whisper .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-whisper .d-toggle-switch__checkbox[aria-checked='true']"+ )+ .exists("sets the post type to whisper");+ await click(".composer-actions-trigger");++ await visit("/");+ assert.dom("#create-topic").exists("the create topic button is visible");++ await click("#create-topic");+ assert+ .dom(".composer-whisper-indicator.--whispering")+ .doesNotExist("should reset the state of the composer's model");+ assert+ .dom(".save-or-cancel button .d-icon-far-eye-slash")+ .doesNotExist("the save button should not use the whisper icon");++ await click(".composer-actions-trigger");+ await click(".composer-toggle-unlisted .d-toggle-switch__checkbox");++ assert+ .dom(+ ".composer-toggle-unlisted .d-toggle-switch__checkbox[aria-checked='true']"+ )+ .exists("sets the topic to unlisted");++ await visit("/t/this-is-a-test-topic/9");++ await click(".topic-post[data-post-number='1'] button.reply");+ assert+ .dom(".composer-whisper-indicator.--whispering")+ .doesNotExist("should reset the state of the composer's model");+ assert+ .dom(".composer-whisper-indicator.--public")+ .exists("the closed-state whisper indicator shows the reply is public");+ });++ test("Composer whisper toggle not shown when replying to whisper", async function (assert) {+ await visit("/t/topic-with-whisper/960");++ await click(".topic-post[data-post-number='3'] button.reply");+ await click(".composer-actions-trigger");+ assert+ .dom(".composer-toggle-whisper")+ .doesNotExist("whisper toggle is not available when reply to whisper");+ await click(".composer-actions-trigger");++ await click(".composer-actions-trigger");+ await click("[data-action-id='reply_to_topic']");++ await click(".composer-actions-trigger");+ assert+ .dom(".composer-toggle-whisper")+ .exists("whisper toggle is available when reply to topic");+ });++ test("Composer whisper toggle available when replying to topic after whisper", async function (assert) {+ await visit("/t/topic-with-whisper/54081");++ await click(".topic-post[data-post-number='3'] button.reply");+ await click("#reply-control .discard-button");+ await click(".timeline-footer-controls button.create");++ await click(".composer-actions-trigger");+ assert+ .dom(".composer-toggle-whisper")+ .exists("whisper toggle is available when reply to topic");+ });++ test("Can switch states without abandon popup", async function (assert) {+ await visit("/t/internationalization-localization/280");++ const longText = "a".repeat(256);++ sinon.stub(Draft, "get").resolves({+ draft: null,+ draft_sequence: 0,+ });++ await click(".btn-primary.create.btn");++ await fillIn(".d-editor-input", longText);++ assert+ .dom(".composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.reply_to_topic.trigger"),+ "the mode should be: reply to topic"+ );++ await click("article#post_3 button.reply");++ await click(".composer-actions-trigger");+ await click("[data-action-id='reply_as_new_topic']");++ assert.dom(".d-modal__body").doesNotExist("abandon popup shouldn't come");++ assert+ .dom(".d-editor-input")+ .includesValue(longText, "entered text should still be there");++ assert+ .dom(".composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.create_topic.label"),+ "mode should have changed to create topic"+ );+ });+});++acceptance(+ `Composer - Customizations (new composer actions)`,+ function (needs) {+ needs.user();+ needs.site({ can_tag_topics: true });+ needs.settings({+ enable_new_composer_actions: true,+ });++ function customComposerAction(composer) {+ const tags = composer.tags || [];+ const hasMonkey = tags.some(+ (t) => (typeof t === "string" ? t : t.name) === "monkey"+ );+ return hasMonkey && composer.action === CREATE_TOPIC;+ }++ needs.hooks.beforeEach(() => {+ withPluginApi((api) => {+ api.customizeComposerText({+ actionTitle(model) {+ if (customComposerAction(model)) {+ return "custom text";+ }+ },++ saveLabel(model) {+ if (customComposerAction(model)) {+ return "composer.emoji";+ }+ },+ });+ });+ });++ test("Supports text customization", async function (assert) {+ await visit("/");+ await click("#create-topic");+ assert+ .dom(".composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.create_topic.label"),+ "trigger shows create topic label"+ );+ assert+ .dom(".save-or-cancel button")+ .hasText(i18n("composer.create_topic"));+ const tags = selectKit(".mini-tag-chooser");+ await tags.expand();+ await tags.selectRowByName("monkey");+ assert.dom(".composer-actions-trigger").includesText("custom text");+ assert.dom(".save-or-cancel button").hasText(i18n("composer.emoji"));+ });+ }+);diff --git a/frontend/discourse/tests/acceptance/keyboard-shortcuts-new-test.js b/frontend/discourse/tests/acceptance/keyboard-shortcuts-new-test.jsnew file mode 100644index 00000000000..a4fbe02acc5--- /dev/null+++ b/frontend/discourse/tests/acceptance/keyboard-shortcuts-new-test.js@@ -0,0 +1,52 @@+import { triggerKeyEvent, visit } from "@ember/test-helpers";+import { module, test } from "qunit";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";+import { i18n } from "discourse-i18n";++acceptance(+ "Keyboard Shortcuts - Authenticated Users (new composer actions)",+ function (needs) {+ needs.user();+ needs.settings({+ enable_new_composer_actions: true,+ });++ module("context aware create new shortcuts", function () {+ test("C key opens composer in new topic mode from topics list", async function (assert) {+ await visit("/");+ await triggerKeyEvent(document, "keypress", "C");++ assert+ .dom(".composer-action-create-topic .composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.create_topic.label"),+ "composer shows create topic title"+ );+ });++ test("C key opens composer in new PM mode from messages list", async function (assert) {+ await visit("/my/messages");+ await triggerKeyEvent(document, "keypress", "C");++ assert+ .dom(".composer-action-private-message .composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.create_personal_message.label"),+ "composer shows create message title"+ );+ });++ test("C key opens composer in new PM mode from PM topic", async function (assert) {+ await visit("/t/pm-for-testing/12");+ await triggerKeyEvent(document, "keypress", "C");++ assert+ .dom(".composer-action-private-message .composer-actions-trigger")+ .includesText(+ i18n("composer.composer_actions.create_personal_message.label"),+ "composer shows create message title"+ );+ });+ });+ }+);diff --git a/frontend/discourse/tests/helpers/qunit-helpers.js b/frontend/discourse/tests/helpers/qunit-helpers.jsindex 5f37b985feb..6c6f8c94fe8 100644--- a/frontend/discourse/tests/helpers/qunit-helpers.js+++ b/frontend/discourse/tests/helpers/qunit-helpers.js@@ -89,7 +89,7 @@ import Site from "discourse/models/site";import { clearAddedTrackedTopicProperties } from "discourse/models/topic";import User from "discourse/models/user";import { clearResolverOptions } from "discourse/resolver";-import { _clearSnapshots } from "discourse/select-kit/components/composer-actions";+import { _clearSnapshots as _clearComposerActionsSnapshotsOld } from "discourse/select-kit/components/composer-actions";import { enableClearA11yAnnouncementsInTests } from "discourse/services/a11y";import {clearDisabledDefaultKeyboardBindings,@@ -228,7 +228,8 @@ export function testCleanup(container, app) {clearDisabledDefaultKeyboardBindings();clearNavItems();setTopicList(null);- _clearSnapshots();+ container?.lookup?.("service:composer-action-state")?.clear();+ _clearComposerActionsSnapshotsOld();cleanUpComposerUploadHandler();cleanUpComposerUploadMarkdownResolver();cleanUpComposerUploadPreProcessor();diff --git a/frontend/discourse/tests/unit/lib/composer/action-items-test.js b/frontend/discourse/tests/unit/lib/composer/action-items-test.jsnew file mode 100644index 00000000000..90ca87f6867--- /dev/null+++ b/frontend/discourse/tests/unit/lib/composer/action-items-test.js@@ -0,0 +1,244 @@+import { setupTest } from "ember-qunit";+import { module, test } from "qunit";+import sinon from "sinon";+import { ComposerActionItemBuilder } from "discourse/lib/composer/action-items";+import {+ CREATE_SHARED_DRAFT,+ CREATE_TOPIC,+ PRIVATE_MESSAGE,+ REPLY,+} from "discourse/models/composer";+import { logIn } from "discourse/tests/helpers/qunit-helpers";++function topic(attrs = {}) {+ return {+ id: 1,+ title: "Test topic",+ isPrivateMessage: false,+ ...attrs,+ };+}++function post(attrs = {}) {+ return {+ id: 10,+ username: "codinghorror",+ ...attrs,+ };+}++module("Unit | Lib | composer action items", function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ logIn(this.owner);+ this.composerActionState = this.owner.lookup(+ "service:composer-action-state"+ );+ this.composerActionState.clear();+ this.owner.lookup("service:site").set("shared_drafts_category_id", null);+ });++ function build(testContext, context = {}) {+ const {+ action = REPLY,+ topic: topicArg = topic(),+ post: postArg = null,+ replyOptions = {},+ composerModel = {},+ snapshots = {},+ } = context;++ if (snapshots.topic || snapshots.post) {+ testContext.composerActionState.remember({+ topic: snapshots.topic,+ post: snapshots.post,+ });+ }++ if (context.site) {+ testContext.owner.lookup("service:site").setProperties(context.site);+ }++ return new ComposerActionItemBuilder(+ testContext,+ action,+ topicArg,+ postArg,+ replyOptions,+ composerModel+ ).build();+ }++ function ids(testContext, context) {+ return build(testContext, context).map((item) => item.id);+ }++ test("reply to post", function (assert) {+ assert.deepEqual(+ ids(this, {+ post: post(),+ replyOptions: {+ userAvatar: true,+ userLink: true,+ topicLink: true,+ },+ }),+ ["reply_to_topic", "reply_as_new_topic"]+ );+ });++ test("reply to topic", function (assert) {+ assert.deepEqual(+ ids(this, {+ post: null,+ replyOptions: {+ topicLink: true,+ },+ }),+ ["reply_as_new_topic"]+ );+ });++ test("reply as new topic", function (assert) {+ assert.true(+ ids(this, {+ topic: topic({ isPrivateMessage: false }),+ }).includes("reply_as_new_topic")+ );+ });++ test("reply as new group message", function (assert) {+ assert.deepEqual(+ ids(this, {+ topic: topic({+ isPrivateMessage: true,+ details: {+ allowed_users: [{ username: "one" }, { username: "two" }],+ allowed_groups: [],+ },+ }),+ }),+ ["reply_as_new_group_message"]+ );+ });++ test("create topic with snapshots restores reply targets", function (assert) {+ assert.deepEqual(+ ids(this, {+ action: CREATE_TOPIC,+ topic: null,+ snapshots: {+ topic: topic(),+ post: post(),+ },+ }),+ ["reply_to_post", "reply_to_topic", "create_private_message"]+ );+ });++ test("fresh create topic/message with no snapshots does not show stale reply targets", function (assert) {+ assert.deepEqual(+ ids(this, {+ action: CREATE_TOPIC,+ topic: null,+ snapshots: {},+ }),+ ["create_private_message"]+ );++ assert.deepEqual(+ ids(this, {+ action: PRIVATE_MESSAGE,+ topic: null,+ snapshots: {},+ }),+ ["create_topic"]+ );+ });++ test("shared draft and PM/create topic switching options", function (assert) {+ assert.deepEqual(+ ids(this, {+ action: CREATE_TOPIC,+ topic: null,+ site: { shared_drafts_category_id: 24 },+ }),+ ["shared_draft", "create_private_message"]+ );++ assert.deepEqual(+ ids(this, {+ action: CREATE_SHARED_DRAFT,+ topic: null,+ }),+ ["create_topic", "create_private_message"]+ );++ assert.deepEqual(+ ids(this, {+ action: PRIVATE_MESSAGE,+ topic: null,+ snapshots: { topic: topic() },+ }),+ ["create_topic", "reply_to_topic"]+ );+ });++ test("toggle actions are included when composer allows them", function (assert) {+ const composer = this.owner.lookup("service:composer");+ sinon.stub(composer, "canToggleWhisper").value(true);+ sinon.stub(composer, "canToggleNoBump").value(true);+ sinon.stub(composer, "canUnlistTopic").value(true);++ const composerModel = {+ whisper: true,+ noBump: false,+ unlistTopic: true,+ toggleProperty() {},+ };++ const items = build(this, {+ action: REPLY,+ topic: topic(),+ composerModel,+ });++ const toggleWhisper = items.find((item) => item.id === "toggle_whisper");+ const toggleTopicBump = items.find(+ (item) => item.id === "toggle_topic_bump"+ );+ const toggleUnlisted = items.find((item) => item.id === "toggle_unlisted");++ assert.true(toggleWhisper?.isToggle, "includes whisper toggle");+ assert.true(toggleWhisper?.state, "whisper state reads from model");++ assert.true(toggleTopicBump?.isToggle, "includes no-bump toggle");+ assert.false(toggleTopicBump?.state, "no-bump state reads from model");++ assert.true(toggleUnlisted?.isToggle, "includes unlisted toggle");+ assert.true(toggleUnlisted?.state, "unlisted state reads from model");+ });++ test("toggle actions are excluded when composer disallows them", function (assert) {+ const composer = this.owner.lookup("service:composer");+ sinon.stub(composer, "canToggleWhisper").value(false);+ sinon.stub(composer, "canToggleNoBump").value(false);+ sinon.stub(composer, "canUnlistTopic").value(false);++ const actionIds = ids(this, {+ action: CREATE_TOPIC,+ topic: topic(),+ composerModel: {+ whisper: false,+ noBump: false,+ unlistTopic: false,+ toggleProperty() {},+ },+ });++ assert.false(actionIds.includes("toggle_whisper"));+ assert.false(actionIds.includes("toggle_topic_bump"));+ assert.false(actionIds.includes("toggle_unlisted"));+ });+});diff --git a/frontend/discourse/tests/unit/services/composer-action-state-test.js b/frontend/discourse/tests/unit/services/composer-action-state-test.jsnew file mode 100644index 00000000000..aa462d5ccb4--- /dev/null+++ b/frontend/discourse/tests/unit/services/composer-action-state-test.js@@ -0,0 +1,73 @@+import { getOwner } from "@ember/owner";+import { setupTest } from "ember-qunit";+import { module, test } from "qunit";++function topic(id = 1) {+ return { id, title: `Topic ${id}` };+}++function post(id = 10) {+ return { id, username: `user${id}` };+}++module("Unit | Service | composer-action-state", function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.composerActionState = getOwner(this).lookup(+ "service:composer-action-state"+ );+ });++ test("remember stores topic/post when provided", function (assert) {+ const rememberedTopic = topic();+ const rememberedPost = post();++ this.composerActionState.remember({+ topic: rememberedTopic,+ post: rememberedPost,+ });++ assert.deepEqual(this.composerActionState.snapshot, {+ topic: rememberedTopic,+ post: rememberedPost,+ });+ });++ test("null topic does not erase existing snapshot during intentional mode switches", function (assert) {+ const rememberedTopic = topic();+ const rememberedPost = post();++ this.composerActionState.remember({+ topic: rememberedTopic,+ post: rememberedPost,+ });+ this.composerActionState.remember({ topic: null, post: null });++ assert.deepEqual(this.composerActionState.snapshot, {+ topic: rememberedTopic,+ post: rememberedPost,+ });+ });++ test("clear removes stale context", function (assert) {+ this.composerActionState.remember({ topic: topic(), post: post() });+ this.composerActionState.clear();++ assert.deepEqual(this.composerActionState.snapshot, {+ topic: null,+ post: null,+ });+ });++ test("selectAction returns false for plugin/custom actions", async function (assert) {+ assert.false(+ await this.composerActionState.selectAction("plugin_action", {+ options: {},+ composerModel: {},+ topic: null,+ post: null,+ })+ );+ });+});diff --git a/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/extend-composer-actions.js b/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/extend-composer-actions.jsindex 38d3afbec0c..5bf5bd65b07 100644--- a/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/extend-composer-actions.js+++ b/plugins/discourse-post-voting/assets/javascripts/discourse/initializers/extend-composer-actions.js@@ -92,6 +92,57 @@ export default {}});+ api.registerValueTransformer(+ "composer-actions-content",+ ({ value, context }) => {+ const { action, composerModel } = context;++ if (action === CREATE_TOPIC) {+ if (+ composerModel.createAsPostVoting &&+ !composerModel.onlyPostVotingInThisCategory+ ) {+ value.push({+ name: i18n(+ "composer.composer_actions.remove_as_post_voting.label"+ ),+ description: i18n(+ "composer.composer_actions.remove_as_post_voting.desc"+ ),+ icon: "plus",+ id: "togglePostVoting",+ });+ } else if (!composerModel.onlyPostVotingInThisCategory) {+ value.push({+ name: i18n(+ "composer.composer_actions.create_as_post_voting.label"+ ),+ description: i18n(+ "composer.composer_actions.create_as_post_voting.desc"+ ),+ icon: "plus",+ id: "togglePostVoting",+ });+ }+ }++ return value;+ }+ );++ api.registerBehaviorTransformer(+ "composer-actions-on-select",+ ({ context, next }) => {+ if (context.actionId === "togglePostVoting") {+ context.model.toggleProperty("createAsPostVoting");+ context.model.notifyPropertyChange("replyOptions");+ context.model.notifyPropertyChange("action");+ } else {+ next();+ }+ }+ );+api.modifyClass("model:composer", {pluginId: "discourse-post-voting",diff --git a/plugins/discourse-post-voting/test/javascripts/acceptance/composer-new-test.js b/plugins/discourse-post-voting/test/javascripts/acceptance/composer-new-test.jsnew file mode 100644index 00000000000..b02b6423e0e--- /dev/null+++ b/plugins/discourse-post-voting/test/javascripts/acceptance/composer-new-test.js@@ -0,0 +1,119 @@+import { click, fillIn, visit } from "@ember/test-helpers";+import { test } from "qunit";+import Category from "discourse/models/category";+import { parsePostData } from "discourse/tests/helpers/create-pretender";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";+import selectKit from "discourse/tests/helpers/select-kit-helper";+import { i18n } from "discourse-i18n";++let createAsPostVotingSetInRequest = false;++acceptance("composer (new composer actions)", function (needs) {+ needs.user();+ needs.settings({+ post_voting_enabled: true,+ enable_new_composer_actions: true,+ });++ needs.hooks.afterEach(function () {+ createAsPostVotingSetInRequest = false;+ });++ needs.pretender((server, helper) => {+ server.post("/posts", (request) => {+ const data = parsePostData(request.requestBody);+ if (+ String(data.create_as_post_voting) === "true" ||+ String(data.only_post_voting_in_this_category) === "true"+ ) {+ createAsPostVotingSetInRequest = true;+ }++ return helper.response({+ post: {+ topic_id: 280,+ },+ });+ });+ });++ test("Creating new topic with post voting format", async function (assert) {+ await visit("/");+ await click("#create-topic");++ const categoryChooser = selectKit(".category-chooser");+ await categoryChooser.expand();+ await categoryChooser.selectRowByValue(2);++ await click(".composer-actions-trigger");+ await click("[data-action-id='togglePostVoting']");++ assert+ .dom(".composer-actions-trigger")+ .includesText(+ i18n("composer.create_post_voting.label"),+ "displays the right composer action title when creating Post Voting topic"+ );++ assert+ .dom(".create .d-button-label")+ .hasText(+ i18n("composer.create_post_voting.label"),+ "displays the right label for composer create button"+ );++ await click(".composer-actions-trigger");+ await click("[data-action-id='togglePostVoting']");++ assert+ .dom(".composer-actions-trigger")+ .doesNotIncludeText(+ i18n("composer.create_post_voting.label"),+ "reverts to original composer title when post voting format is disabled"+ );++ await click(".composer-actions-trigger");+ await click("[data-action-id='togglePostVoting']");++ await fillIn("#reply-title", "this is some random topic title");+ await fillIn(".d-editor-input", "this is some random body");+ await click(".create");++ assert.true(+ createAsPostVotingSetInRequest,+ "submits the right request to create topic as Post Voting formatted"+ );+ });++ test("Creating new topic in category with Post Voting create default", async function (assert) {+ Category.findById(2).set("create_as_post_voting_default", true);++ await visit("/");+ await click("#create-topic");++ const categoryChooser = selectKit(".category-chooser");+ await categoryChooser.expand();+ await categoryChooser.selectRowByValue(2);++ assert+ .dom(".composer-actions-trigger")+ .includesText(i18n("composer.create_post_voting.label"));+ });++ test("Creating new topic in category with only_post_voting_in_this_category enabled", async function (assert) {+ const category = Category.findById(2);+ category.set("only_post_voting_in_this_category", true);++ await visit("/");+ await click("#create-topic");++ const categoryChooser = selectKit(".category-chooser");+ await categoryChooser.expand();++ await categoryChooser.selectRowByValue(2);++ assert+ .dom(".composer-actions-trigger")+ .includesText(i18n("composer.create_post_voting.label"));+ });+});diff --git a/plugins/discourse-presence/test/javascripts/acceptance/discourse-presence-new-test.js b/plugins/discourse-presence/test/javascripts/acceptance/discourse-presence-new-test.jsnew file mode 100644index 00000000000..ae6c0ed0b90--- /dev/null+++ b/plugins/discourse-presence/test/javascripts/acceptance/discourse-presence-new-test.js@@ -0,0 +1,58 @@+import { click, fillIn, visit } from "@ember/test-helpers";+import { test } from "qunit";+import User from "discourse/models/user";+import { presentUserIds } from "discourse/tests/helpers/presence-pretender";+import { acceptance } from "discourse/tests/helpers/qunit-helpers";++acceptance(+ "Discourse Presence Plugin (new composer actions)",+ function (needs) {+ needs.user({ whisperer: true });+ needs.settings({+ enable_new_composer_actions: true,+ });+ needs.pretender((server, helper) => {+ server.get("/drafts/topic_280.json", function () {+ return helper.response(200, { draft: null });+ });+ });++ test("Uses whisper channel for whispers via actions dropdown", async function (assert) {+ await visit("/t/internationalization-localization/280");++ await click("#topic-footer-buttons .btn.create");+ assert.dom(".d-editor-input").exists("the composer input is visible");++ await fillIn(".d-editor-input", "this is the content of my reply");++ assert.deepEqual(+ presentUserIds("/discourse-presence/reply/280"),+ [User.current().id],+ "publishes reply presence when typing"+ );++ await click(".composer-actions-trigger");+ await click(".composer-toggle-whisper .d-toggle-switch__checkbox");++ assert.deepEqual(+ presentUserIds("/discourse-presence/reply/280"),+ [],+ "removes reply presence"+ );++ assert.deepEqual(+ presentUserIds("/discourse-presence/whisper/280"),+ [User.current().id],+ "adds whisper presence"+ );++ await click("#reply-control button.create");++ assert.deepEqual(+ presentUserIds("/discourse-presence/whisper/280"),+ [],+ "leaves whisper channel when composer closes"+ );+ });+ }+);diff --git a/public/images/upcoming_changes/enable_new_composer_actions.png b/public/images/upcoming_changes/enable_new_composer_actions.pngnew file mode 100644index 00000000000..6b007c12e7fBinary files /dev/null and b/public/images/upcoming_changes/enable_new_composer_actions.png differdiff --git a/spec/system/page_objects/components/composer.rb b/spec/system/page_objects/components/composer.rbindex ecd30b738b3..e68972fe064 100644--- a/spec/system/page_objects/components/composer.rb+++ b/spec/system/page_objects/components/composer.rb@@ -43,6 +43,11 @@ module PageObjectsselfend+ def open_composer_actions_new+ find(".composer-actions-trigger").click+ self+ end+def click_toolbar_button(button_class)find(".d-editor-button-bar button.#{button_class}").clickself@@ -122,11 +127,20 @@ module PageObjects!actions.include?(action)end+ def has_no_action_id?(action_id)+ has_no_css?(".composer-actions-dropdown [data-action-id='#{action_id}']")+ end+def select_action(action)find(action(action)).clickselfend+ def select_action_by_id(action_id)+ find(".composer-actions-dropdown [data-action-id='#{action_id}']").click+ self+ end+def reply_button_focused?page.has_css?("#{@composer_id} .btn-primary:focus")enddiff --git a/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjs b/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjsindex 8e561adaf04..3934729aba2 100644--- a/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjs+++ b/themes/horizon/javascripts/discourse/components/composer-peek-mode-toggle.gjs@@ -34,7 +34,7 @@ export default class ComposerPeekModeToggle extends Component {@preventFocus={{true}}@icon="discourse-sidebar"@title="composer.peek_mode_toggle"- class="btn-mini-toggle no-text peek-mode-toggle btn-transparent"+ class="btn-small no-text peek-mode-toggle btn-transparent"/></template>}