Skip to content

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

FIX: Display new DM button when public channels are disabled (#28306)

Mark VanLandingham79f871b558bc
diff --git a/plugins/chat/assets/javascripts/discourse/components/channels-list-direct.gjs b/plugins/chat/assets/javascripts/discourse/components/channels-list-direct.gjs
index 2b97adb5ed3..ba319ea6c8d 100644
--- a/plugins/chat/assets/javascripts/discourse/components/channels-list-direct.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/channels-list-direct.gjs
@@ -3,7 +3,7 @@ import { fn, hash } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import { service } from "@ember/service";
-import { and } from "truth-helpers";
+import { and, not, or } from "truth-helpers";
import DButton from "discourse/components/d-button";
import PluginOutlet from "discourse/components/plugin-outlet";
import concatClass from "discourse/helpers/concat-class";
@@ -17,7 +17,9 @@ export default class ChannelsListDirect extends Component {
@service chat;
@service chatChannelsManager;
@service chatStateManager;
+ @service currentUser;
@service site;
+ @service siteSettings;
@service modal;
get inSidebar() {
@@ -60,8 +62,10 @@ export default class ChannelsListDirect extends Component {
{{#if
(and
this.showDirectMessageChannels
- this.site.desktopView
- this.chatStateManager.isDrawerActive
+ (or
+ this.site.desktopView
+ (not this.chatChannelsManager.displayPublicChannels)
+ )
)
}}
<div class="chat-channel-divider direct-message-channels-section">
diff --git a/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs b/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs
index 13f7d055662..f5ed51e043d 100644
--- a/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/channels-list-public.gjs
@@ -25,32 +25,6 @@ export default class ChannelsListPublic extends Component {
return this.args.inSidebar ?? false;
}
- get publicMessageChannelsEmpty() {
- return (
- this.chatChannelsManager.publicMessageChannels?.length === 0 &&
- this.chatStateManager.hasPreloadedChannels
- );
- }
-
- get displayPublicChannels() {
- if (!this.siteSettings.enable_public_channels) {
- return false;
- }
-
- if (!this.chatStateManager.hasPreloadedChannels) {
- return false;
- }
-
- if (this.publicMessageChannelsEmpty) {
- return (
- this.currentUser?.staff ||
- this.currentUser?.has_joinable_public_channels
- );
- }
-
- return true;
- }
-
get hasUnreadThreads() {
return this.chatTrackingStateManager.hasUnreadThreads;
}
@@ -84,7 +58,9 @@ export default class ChannelsListPublic extends Component {
</LinkTo>
{{/if}}
- {{#if (and this.displayPublicChannels this.site.desktopView)}}
+ {{#if
+ (and this.chatChannelsManager.displayPublicChannels this.site.desktopView)
+ }}
<div class="chat-channel-divider public-channels-section">
{{#if this.inSidebar}}
<span
@@ -119,12 +95,12 @@ export default class ChannelsListPublic extends Component {
(if this.inSidebar "collapsible-sidebar-section")
}}
>
- {{#if this.publicMessageChannelsEmpty}}
+ {{#if this.chatChannelsManager.publicMessageChannelsEmpty}}
<EmptyChannelsList
@title={{i18n "chat.no_public_channels"}}
@ctaTitle={{i18n "chat.no_public_channels_cta"}}
@ctaAction={{this.openBrowseChannels}}
- @showCTA={{this.displayPublicChannels}}
+ @showCTA={{this.chatChannelsManager.displayPublicChannels}}
/>
{{else}}
{{#each this.chatChannelsManager.publicMessageChannels as |channel|}}
diff --git a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js
index d8d78871b2a..b3cea54723c 100644
--- a/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js
+++ b/plugins/chat/assets/javascripts/discourse/services/chat-channels-manager.js
@@ -15,11 +15,13 @@ const DIRECT_MESSAGE_CHANNELS_LIMIT = 20;
*/
export default class ChatChannelsManager extends Service {
- @service chatSubscriptionsManager;
@service chatApi;
+ @service chatSubscriptionsManager;
+ @service chatStateManager;
@service currentUser;
@service router;
@service site;
+ @service siteSettings;
@tracked _cached = new TrackedObject();
async find(id, options = { fetchIfNotFound: true }) {
@@ -158,6 +160,32 @@ export default class ChatChannelsManager extends Service {
}
}
+ get publicMessageChannelsEmpty() {
+ return (
+ this.publicMessageChannels?.length === 0 &&
+ this.chatStateManager.hasPreloadedChannels
+ );
+ }
+
+ get displayPublicChannels() {
+ if (!this.siteSettings.enable_public_channels) {
+ return false;
+ }
+
+ if (!this.chatStateManager.hasPreloadedChannels) {
+ return false;
+ }
+
+ if (this.publicMessageChannelsEmpty) {
+ return (
+ this.currentUser?.staff ||
+ this.currentUser?.has_joinable_public_channels
+ );
+ }
+
+ return true;
+ }
+
#cache(channel) {
if (!channel) {
return;
diff --git a/plugins/chat/spec/system/list_channels/no_sidebar_spec.rb b/plugins/chat/spec/system/list_channels/no_sidebar_spec.rb
index b940841be2b..c080624cbb0 100644
--- a/plugins/chat/spec/system/list_channels/no_sidebar_spec.rb
+++ b/plugins/chat/spec/system/list_channels/no_sidebar_spec.rb
@@ -123,4 +123,25 @@ RSpec.describe "List channels | no sidebar", type: :system do
expect(page).to have_no_css(".direct-message-channels-section")
end
end
+
+ context "when public channels are disabled" do
+ before { SiteSetting.enable_public_channels = false }
+
+ it "shows the create direct message button" do
+ visit("/chat")
+
+ expect(chat).to have_direct_message_channels_section
+ end
+
+ context "with drawer prefered" do
+ before { chat.prefers_drawer }
+
+ it "shows the create direct message button in the drawer" do
+ visit("/")
+ chat.open_from_header
+
+ expect(PageObjects::Pages::ChatDrawer.new).to have_direct_message_channels_section
+ end
+ end
+ end
end
diff --git a/plugins/chat/spec/system/page_objects/chat/chat.rb b/plugins/chat/spec/system/page_objects/chat/chat.rb
index a7428f6e907..f31830c06db 100644
--- a/plugins/chat/spec/system/page_objects/chat/chat.rb
+++ b/plugins/chat/spec/system/page_objects/chat/chat.rb
@@ -134,6 +134,10 @@ module PageObjects
have_selector(".channel-list-empty-message")
end
+ def has_direct_message_channels_section?
+ has_css?(".direct-message-channels-section")
+ end
+
private
def drawer?(expectation:, channel_id: nil, expanded: true)
diff --git a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb
index 5f9f2273f98..91edecc8974 100644
--- a/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb
+++ b/plugins/chat/spec/system/page_objects/chat_drawer/chat_drawer.rb
@@ -145,6 +145,10 @@ module PageObjects
has_no_css?("#{thread_list_button_selector}.has-unreads")
end
+ def has_direct_message_channels_section?
+ has_css?(".direct-message-channels-section")
+ end
+
private
def mouseout