diff --git a/plugins/chat/app/services/chat/update_channel.rb b/plugins/chat/app/services/chat/update_channel.rb index 6960fe44236..7beb3b78784 100644 --- a/plugins/chat/app/services/chat/update_channel.rb +++ b/plugins/chat/app/services/chat/update_channel.rb @@ -37,6 +37,7 @@ module Chat contract default_values_from: :channel step :update_channel step :mark_all_threads_as_read_if_needed + step :update_site_settings_if_needed step :publish_channel_update step :auto_join_users_if_needed @@ -77,6 +78,10 @@ module Chat Jobs.enqueue(Jobs::Chat::MarkAllChannelThreadsRead, channel_id: channel.id) end + def update_site_settings_if_needed + SiteSetting.chat_threads_enabled = Chat::Channel.exists?(threading_enabled: true) + end + def publish_channel_update(channel:, guardian:, **) Chat::Publisher.publish_chat_channel_edit(channel, guardian.user) end diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-footer.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-footer.gjs index 519e3509740..05483883af3 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-footer.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-footer.gjs @@ -1,7 +1,5 @@ import Component from "@glimmer/component"; -import { tracked } from "@glimmer/tracking"; import { inject as service } from "@ember/service"; -import { modifier } from "ember-modifier"; import DButton from "discourse/components/d-button"; import concatClass from "discourse/helpers/concat-class"; import i18n from "discourse-common/helpers/i18n"; @@ -10,33 +8,16 @@ import eq from "truth-helpers/helpers/eq"; export default class ChatFooter extends Component { @service router; @service chat; - @service chatApi; + @service siteSettings; - @tracked threadsEnabled = false; - - updateThreadCount = modifier(() => { - const ajax = this.chatApi.userThreadCount(); - - ajax - .then((result) => { - this.threadsEnabled = result.thread_count > 0; - }) - .catch((error) => { - // eslint-disable-next-line no-console - console.error(error); - }); - - return () => { - ajax?.abort(); - }; - }); + threadsEnabled = this.siteSettings.chat_threads_enabled; get directMessagesEnabled() { return this.chat.userCanAccessDirectMessages; } get shouldRenderFooter() { - return this.directMessagesEnabled || this.threadsEnabled; + return this.threadsEnabled || this.directMessagesEnabled; }