Skip to content

A platform for community discussion. Free, open, simple.

UX: Split buttons for chat DMs and groups (#43525)

Penar Musarajc8f4b974bdeb
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sidebar-menu.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sidebar-menu.gjs
index bc9c24e4e69..0820292f63f 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sidebar-menu.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-list-sidebar-menu.gjs
@@ -7,6 +7,7 @@ import DButton from "discourse/ui-kit/d-button";
import DDropdownMenu from "discourse/ui-kit/d-dropdown-menu";
import dIcon from "discourse/ui-kit/helpers/d-icon";
import { i18n } from "discourse-i18n";
+import { MODES } from "discourse/plugins/chat/discourse/components/chat/message-creator/constants";
import ChatModalCreateChannel from "discourse/plugins/chat/discourse/components/chat/modal/create-channel";
import ChatModalNewMessage from "discourse/plugins/chat/discourse/components/chat/modal/new-message";
import {
@@ -41,6 +42,7 @@ const SORT_LABEL_KEYS = {
export default class ChatChannelListSidebarMenu extends Component {
@service chat;
@service chatChannelListPreferences;
+ @service chatGuardian;
@service currentUser;
@service modal;
@service router;
@@ -65,6 +67,10 @@ export default class ChatChannelListSidebarMenu extends Component {
return this.args.data?.showNewMessage && this.chat.userCanDirectMessage;
}
+ get showNewGroupChat() {
+ return this.showNewMessage && this.chatGuardian.canUseGroupChat();
+ }
+
get hasTopLevelActions() {
return this.showCreateChannel || this.showBrowse || this.showNewMessage;
}
@@ -103,6 +109,14 @@ export default class ChatChannelListSidebarMenu extends Component {
this.args.close?.();
}
+ @action
+ openNewGroupChat() {
+ this.modal.show(ChatModalNewMessage, {
+ model: { initialMode: MODES.new_group },
+ });
+ this.args.close?.();
+ }
+
@action
openNewMessage() {
this.modal.show(ChatModalNewMessage);
@@ -157,6 +171,18 @@ export default class ChatChannelListSidebarMenu extends Component {
</dropdown.item>
{{/if}}
+ {{#if this.showNewGroupChat}}
+ <dropdown.item role="none">
+ <DButton
+ data-menu-option-id="startGroupChat"
+ role="menuitem"
+ @action={{this.openNewGroupChat}}
+ @label="chat.direct_messages.new_group"
+ @suffixIcon="plus"
+ />
+ </dropdown.item>
+ {{/if}}
+
{{#if this.hasTopLevelActions}}
<dropdown.divider role="none" />
{{/if}}
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/index.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/index.gjs
index 335dd13caf1..a0718fb9190 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/index.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/message-creator/index.gjs
@@ -8,7 +8,7 @@ import NewGroup from "./new-group";
import Search from "./search";
export default class ChatMessageCreator extends Component {
- @tracked mode = MODES.search;
+ @tracked mode = this.args.initialMode ?? MODES.search;
@autoTrackedArray members = [];
get componentForMode() {
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.gjs
index 81d115b11d3..0b95eadb9a5 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat/modal/new-message.gjs
@@ -22,7 +22,11 @@ export default class ChatModalNewMessage extends Component {
@inline={{@inline}}
@title="chat.new_message_modal.title"
>
- <MessageCreator @channel={{@model}} @onClose={{@closeModal}} />
+ <MessageCreator
+ @channel={{@model}}
+ @initialMode={{@model.initialMode}}
+ @onClose={{@closeModal}}
+ />
</DModal>
{{/if}}
</template>
diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss b/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss
index 0304f77f96a..61052d3fba6 100644
--- a/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-channel-list-options.scss
@@ -15,7 +15,6 @@
}
}
-.chat-channel-list-options-menu,
.chat-channel-list-filter-menu,
.chat-channel-list-sort-menu {
min-width: 17rem;
diff --git a/plugins/chat/config/locales/client.en.yml b/plugins/chat/config/locales/client.en.yml
index 6591bf89cdd..588438b8f6b 100644
--- a/plugins/chat/config/locales/client.en.yml
+++ b/plugins/chat/config/locales/client.en.yml
@@ -637,7 +637,8 @@ en:
direct_messages:
title: "DMs"
aria_label: "Switch to direct messages"
- new: "New direct message or group chat..."
+ new: "New direct message"
+ new_group: "New group chat"
create: "Go"
leave: "Leave channel"
close: "Close channel"
diff --git a/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs b/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs
index 01d619238dd..b3883f11fda 100644
--- a/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs
+++ b/plugins/chat/test/javascripts/components/chat-channel-list-sidebar-menu-test.gjs
@@ -159,7 +159,8 @@ module(
.exists("the sort option is shown behind a fly-out submenu");
});
- test("shows the new message, filter, and sort options for the direct messages header", async function (assert) {
+ test("shows the new message, group chat, filter, and sort options for the direct messages header", async function (assert) {
+ this.siteSettings.chat_max_direct_message_users = 20;
sinon
.stub(getOwner(this).lookup("service:chat"), "userCanDirectMessage")
.value(true);
@@ -181,6 +182,12 @@ module(
i18n("chat.direct_messages.new"),
"the new message action is shown"
);
+ assert
+ .dom('[data-menu-option-id="startGroupChat"]')
+ .hasText(
+ i18n("chat.direct_messages.new_group"),
+ "the new group chat action is shown"
+ );
assert
.dom('[data-menu-option-id="browseChannels"]')
.doesNotExist("the browse option is hidden");
@@ -205,35 +212,51 @@ module(
.exists({ count: 1 }, "exactly one sort choice is checked");
});
- test("starts a personal chat from the direct messages header menu", async function (assert) {
- sinon
- .stub(getOwner(this).lookup("service:chat"), "userCanDirectMessage")
- .value(true);
+ for (const [option, mode] of [
+ ["startDm", "search"],
+ ["startGroupChat", "new-group"],
+ ]) {
+ test(`opens ${mode} from the direct messages header menu`, async function (assert) {
+ this.siteSettings.chat_max_direct_message_users = 20;
+ sinon
+ .stub(getOwner(this).lookup("service:chat"), "userCanDirectMessage")
+ .value(true);
- await render(
- <template>
- <button class="menu-trigger" type="button">Open</button>
- <DMenus />
- <ModalContainer />
- </template>
- );
- const menu = getOwner(this).lookup("service:menu");
- await menu.show(find(".menu-trigger"), {
- component: ChatChannelListSidebarMenu,
- contentRole: "menu",
- identifier: "chat-channel-list-options-menu",
- data: DMS_DATA,
- });
+ await render(
+ <template>
+ <button class="menu-trigger" type="button">Open</button>
+ <DMenus />
+ <ModalContainer />
+ </template>
+ );
+ const menu = getOwner(this).lookup("service:menu");
+ await menu.show(find(".menu-trigger"), {
+ component: ChatChannelListSidebarMenu,
+ contentRole: "menu",
+ identifier: "chat-channel-list-options-menu",
+ data: DMS_DATA,
+ });
- await click('[data-menu-option-id="startDm"]');
+ await click(`[data-menu-option-id="${option}"]`);
- assert
- .dom(".chat-modal-new-message")
- .exists("the new message modal opens");
- assert
- .dom('.fk-d-menu[data-identifier="chat-channel-list-options-menu"]')
- .doesNotExist("the menu closes");
- });
+ assert
+ .dom(".chat-modal-new-message")
+ .exists("the new message modal opens");
+ assert
+ .dom(`.chat-message-creator__${mode}`)
+ .exists("the requested mode is shown immediately");
+ assert
+ .dom('.fk-d-menu[data-identifier="chat-channel-list-options-menu"]')
+ .doesNotExist("the menu closes");
+ if (mode === "new-group") {
+ await click(".chat-message-creator__add-members__close-btn");
+
+ assert
+ .dom(".chat-message-creator__search")
+ .exists("canceling group creation returns to search");
+ }
+ });
+ }
test("hides the new message option when the user cannot send direct messages", async function (assert) {
await render(
@@ -246,6 +269,9 @@ module(
assert
.dom('[data-menu-option-id="startDm"]')
.doesNotExist("the new message action is hidden without permission");
+ assert
+ .dom('[data-menu-option-id="startGroupChat"]')
+ .doesNotExist("the group chat action is hidden without permission");
assert
.dom(".dropdown-menu__divider")
.doesNotExist(
@@ -256,6 +282,24 @@ module(
.exists("the filter option is still shown");
});
+ test("hides group chat when only one recipient is allowed", async function (assert) {
+ this.siteSettings.chat_max_direct_message_users = 1;
+ sinon
+ .stub(getOwner(this).lookup("service:chat"), "userCanDirectMessage")
+ .value(true);
+
+ await render(
+ <template><ChatChannelListSidebarMenu @data={{DMS_DATA}} /></template>
+ );
+
+ assert
+ .dom('[data-menu-option-id="startDm"]')
+ .exists("direct messages are available");
+ assert
+ .dom('[data-menu-option-id="startGroupChat"]')
+ .doesNotExist("group chat is unavailable");
+ });
+
test("hides the create channel option for non-staff", async function (assert) {
await render(
<template>