mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 18:02:46 +08:00
FIX: Display new DM button when public channels are disabled (#28306)
This commit is contained in:
parent
1d6e54e54c
commit
79f871b558
|
@ -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">
|
||||
|
|
|
@ -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|}}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user