Skip to content

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

FIX: use site setting to show my threads chat footer tab (#25277)

David Battersby67244a231800
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;
}
<template>
diff --git a/plugins/chat/config/settings.yml b/plugins/chat/config/settings.yml
index 15ff53917f8..07a3b5a2241 100644
--- a/plugins/chat/config/settings.yml
+++ b/plugins/chat/config/settings.yml
@@ -12,6 +12,10 @@ chat:
default: "3|11" # 3: @staff, 11: @trust_level_1
allow_any: false
refresh: true
+ chat_threads_enabled:
+ client: true
+ default: false
+ hidden: true
needs_chat_seeded:
default: true
hidden: true
diff --git a/plugins/chat/db/migrate/20240118120825_add_threads_enabled_site_setting.rb b/plugins/chat/db/migrate/20240118120825_add_threads_enabled_site_setting.rb
new file mode 100644
index 00000000000..e0d502dd9d0
--- /dev/null
+++ b/plugins/chat/db/migrate/20240118120825_add_threads_enabled_site_setting.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class AddThreadsEnabledSiteSetting < ActiveRecord::Migration[7.0]
+ def up
+ SiteSetting.chat_threads_enabled = false
+
+ threading_enabled_channels =
+ DB.query_single("SELECT name FROM chat_channels WHERE threading_enabled = 't'")
+
+ return unless threading_enabled_channels.present?
+
+ DB.exec("UPDATE site_settings SET value = 't' WHERE name = 'chat_threads_enabled'")
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/plugins/chat/spec/services/chat/update_channel_spec.rb b/plugins/chat/spec/services/chat/update_channel_spec.rb
index 84e4fb89e0f..92729aa778f 100644
--- a/plugins/chat/spec/services/chat/update_channel_spec.rb
+++ b/plugins/chat/spec/services/chat/update_channel_spec.rb
@@ -142,6 +142,17 @@ RSpec.describe Chat::UpdateChannel do
end
end
end
+
+ describe "#update_site_settings" do
+ before do
+ SiteSetting.chat_threads_enabled = false
+ params[:threading_enabled] = true
+ end
+
+ it "sets chat_threads_enabled to true" do
+ expect { result }.to change { SiteSetting.chat_threads_enabled }.from(false).to(true)
+ end
+ end
end
end
end
diff --git a/plugins/chat/spec/system/chat_footer_spec.rb b/plugins/chat/spec/system/chat_footer_spec.rb
index 5b028c5f0ab..b693071f03c 100644
--- a/plugins/chat/spec/system/chat_footer_spec.rb
+++ b/plugins/chat/spec/system/chat_footer_spec.rb
@@ -14,6 +14,8 @@ RSpec.describe "Chat footer on mobile", type: :system, mobile: true do
context "with multiple tabs" do
it "shows footer" do
+ SiteSetting.chat_threads_enabled = false
+
visit("/")
chat_page.open_from_header
@@ -37,9 +39,7 @@ RSpec.describe "Chat footer on mobile", type: :system, mobile: true do
end
it "shows threads tab when user has threads" do
- thread = Fabricate(:chat_thread, channel: channel, original_message: message)
- Fabricate(:chat_message, chat_channel: channel, thread: thread)
- thread.update!(replies_count: 1)
+ SiteSetting.chat_threads_enabled = true
visit("/")
chat_page.open_from_header
@@ -51,6 +51,7 @@ RSpec.describe "Chat footer on mobile", type: :system, mobile: true do
context "with only 1 tab" do
before do
+ SiteSetting.chat_threads_enabled = false
SiteSetting.direct_message_enabled_groups = "3" # staff only
end