FIX: use site setting to show my threads chat footer tab (#25277)
Fixes an issue with delayed rendering of the My Threads tab in chat mobile footer. Previously we made an ajax request to determine the number of threads a user had before rendering the tab, however it is much faster (and better UX) if we can rely on a site setting for this. The new chat_threads_enabled site setting is set to true when the site has chat channels with threading enabled.
This commit is contained in:
parent
fdf332f3aa
commit
67244a2318
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue