From 79f871b558bc7c64416ef858ec2317207ab10e9a Mon Sep 17 00:00:00 2001 From: Mark VanLandingham Date: Mon, 12 Aug 2024 08:44:51 -0500 Subject: [PATCH] FIX: Display new DM button when public channels are disabled (#28306) --- .../components/channels-list-direct.gjs | 10 ++++-- .../components/channels-list-public.gjs | 34 +++---------------- .../services/chat-channels-manager.js | 30 +++++++++++++++- .../system/list_channels/no_sidebar_spec.rb | 21 ++++++++++++ .../spec/system/page_objects/chat/chat.rb | 4 +++ .../page_objects/chat_drawer/chat_drawer.rb | 4 +++ 6 files changed, 70 insertions(+), 33 deletions(-) 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) + ) ) }}
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 { {{/if}} - {{#if (and this.displayPublicChannels this.site.desktopView)}} + {{#if + (and this.chatChannelsManager.displayPublicChannels this.site.desktopView) + }}
{{#if this.inSidebar}} - {{#if this.publicMessageChannelsEmpty}} + {{#if this.chatChannelsManager.publicMessageChannelsEmpty}} {{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