mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 14:55:48 +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 { on } from "@ember/modifier";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { service } from "@ember/service";
|
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 DButton from "discourse/components/d-button";
|
||||||
import PluginOutlet from "discourse/components/plugin-outlet";
|
import PluginOutlet from "discourse/components/plugin-outlet";
|
||||||
import concatClass from "discourse/helpers/concat-class";
|
import concatClass from "discourse/helpers/concat-class";
|
||||||
|
@ -17,7 +17,9 @@ export default class ChannelsListDirect extends Component {
|
||||||
@service chat;
|
@service chat;
|
||||||
@service chatChannelsManager;
|
@service chatChannelsManager;
|
||||||
@service chatStateManager;
|
@service chatStateManager;
|
||||||
|
@service currentUser;
|
||||||
@service site;
|
@service site;
|
||||||
|
@service siteSettings;
|
||||||
@service modal;
|
@service modal;
|
||||||
|
|
||||||
get inSidebar() {
|
get inSidebar() {
|
||||||
|
@ -60,8 +62,10 @@ export default class ChannelsListDirect extends Component {
|
||||||
{{#if
|
{{#if
|
||||||
(and
|
(and
|
||||||
this.showDirectMessageChannels
|
this.showDirectMessageChannels
|
||||||
|
(or
|
||||||
this.site.desktopView
|
this.site.desktopView
|
||||||
this.chatStateManager.isDrawerActive
|
(not this.chatChannelsManager.displayPublicChannels)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
<div class="chat-channel-divider direct-message-channels-section">
|
<div class="chat-channel-divider direct-message-channels-section">
|
||||||
|
|
|
@ -25,32 +25,6 @@ export default class ChannelsListPublic extends Component {
|
||||||
return this.args.inSidebar ?? false;
|
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() {
|
get hasUnreadThreads() {
|
||||||
return this.chatTrackingStateManager.hasUnreadThreads;
|
return this.chatTrackingStateManager.hasUnreadThreads;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +58,9 @@ export default class ChannelsListPublic extends Component {
|
||||||
</LinkTo>
|
</LinkTo>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if (and this.displayPublicChannels this.site.desktopView)}}
|
{{#if
|
||||||
|
(and this.chatChannelsManager.displayPublicChannels this.site.desktopView)
|
||||||
|
}}
|
||||||
<div class="chat-channel-divider public-channels-section">
|
<div class="chat-channel-divider public-channels-section">
|
||||||
{{#if this.inSidebar}}
|
{{#if this.inSidebar}}
|
||||||
<span
|
<span
|
||||||
|
@ -119,12 +95,12 @@ export default class ChannelsListPublic extends Component {
|
||||||
(if this.inSidebar "collapsible-sidebar-section")
|
(if this.inSidebar "collapsible-sidebar-section")
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{{#if this.publicMessageChannelsEmpty}}
|
{{#if this.chatChannelsManager.publicMessageChannelsEmpty}}
|
||||||
<EmptyChannelsList
|
<EmptyChannelsList
|
||||||
@title={{i18n "chat.no_public_channels"}}
|
@title={{i18n "chat.no_public_channels"}}
|
||||||
@ctaTitle={{i18n "chat.no_public_channels_cta"}}
|
@ctaTitle={{i18n "chat.no_public_channels_cta"}}
|
||||||
@ctaAction={{this.openBrowseChannels}}
|
@ctaAction={{this.openBrowseChannels}}
|
||||||
@showCTA={{this.displayPublicChannels}}
|
@showCTA={{this.chatChannelsManager.displayPublicChannels}}
|
||||||
/>
|
/>
|
||||||
{{else}}
|
{{else}}
|
||||||
{{#each this.chatChannelsManager.publicMessageChannels as |channel|}}
|
{{#each this.chatChannelsManager.publicMessageChannels as |channel|}}
|
||||||
|
|
|
@ -15,11 +15,13 @@ const DIRECT_MESSAGE_CHANNELS_LIMIT = 20;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default class ChatChannelsManager extends Service {
|
export default class ChatChannelsManager extends Service {
|
||||||
@service chatSubscriptionsManager;
|
|
||||||
@service chatApi;
|
@service chatApi;
|
||||||
|
@service chatSubscriptionsManager;
|
||||||
|
@service chatStateManager;
|
||||||
@service currentUser;
|
@service currentUser;
|
||||||
@service router;
|
@service router;
|
||||||
@service site;
|
@service site;
|
||||||
|
@service siteSettings;
|
||||||
@tracked _cached = new TrackedObject();
|
@tracked _cached = new TrackedObject();
|
||||||
|
|
||||||
async find(id, options = { fetchIfNotFound: true }) {
|
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) {
|
#cache(channel) {
|
||||||
if (!channel) {
|
if (!channel) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -123,4 +123,25 @@ RSpec.describe "List channels | no sidebar", type: :system do
|
||||||
expect(page).to have_no_css(".direct-message-channels-section")
|
expect(page).to have_no_css(".direct-message-channels-section")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
@ -134,6 +134,10 @@ module PageObjects
|
||||||
have_selector(".channel-list-empty-message")
|
have_selector(".channel-list-empty-message")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_direct_message_channels_section?
|
||||||
|
has_css?(".direct-message-channels-section")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def drawer?(expectation:, channel_id: nil, expanded: true)
|
def drawer?(expectation:, channel_id: nil, expanded: true)
|
||||||
|
|
|
@ -145,6 +145,10 @@ module PageObjects
|
||||||
has_no_css?("#{thread_list_button_selector}.has-unreads")
|
has_no_css?("#{thread_list_button_selector}.has-unreads")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_direct_message_channels_section?
|
||||||
|
has_css?(".direct-message-channels-section")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def mouseout
|
def mouseout
|
||||||
|
|
Loading…
Reference in New Issue
Block a user