From 79d2eb5beb926f804b40787583714d60b77e4643 Mon Sep 17 00:00:00 2001 From: David Battersby Date: Fri, 11 Oct 2024 13:05:07 +0400 Subject: [PATCH] FEATURE: enable threading in chat DM channels (#29170) Support threads in DMs and group chats so members can keep their conversations organized. This change adds a new toggle switch for threads within the Chat Channel Settings screen. For new direct message channels threading is enabled by default. We have made a decision to exclude direct message threads from the My Threads screen for now. --- .../chat/api/channels_controller.rb | 8 ++--- .../app/models/chat/direct_message_channel.rb | 1 + .../chat/routes/channel-info-settings.gjs | 30 +++++++++++++++++-- plugins/chat/lib/chat/guardian_extensions.rb | 2 +- .../chat/spec/fabricators/chat_fabricator.rb | 1 + .../spec/lib/chat/guardian_extensions_spec.rb | 4 +-- .../chat/direct_message_channel_spec.rb | 6 ++++ .../spec/system/channel_settings_page_spec.rb | 17 +++++++++++ 8 files changed, 58 insertions(+), 11 deletions(-) diff --git a/plugins/chat/app/controllers/chat/api/channels_controller.rb b/plugins/chat/app/controllers/chat/api/channels_controller.rb index 6e6ca0ef379..56dc148ec8d 100644 --- a/plugins/chat/app/controllers/chat/api/channels_controller.rb +++ b/plugins/chat/app/controllers/chat/api/channels_controller.rb @@ -1,12 +1,8 @@ # frozen_string_literal: true class Chat::Api::ChannelsController < Chat::ApiController - CHANNEL_EDITABLE_PARAMS ||= %i[name description slug] - CATEGORY_CHANNEL_EDITABLE_PARAMS ||= %i[ - auto_join_users - allow_channel_wide_mentions - threading_enabled - ] + CHANNEL_EDITABLE_PARAMS ||= %i[name description slug threading_enabled] + CATEGORY_CHANNEL_EDITABLE_PARAMS ||= %i[auto_join_users allow_channel_wide_mentions] def index permitted = params.permit(:filter, :limit, :offset, :status) diff --git a/plugins/chat/app/models/chat/direct_message_channel.rb b/plugins/chat/app/models/chat/direct_message_channel.rb index 2e5a1b8e2a9..23eea91aa8b 100644 --- a/plugins/chat/app/models/chat/direct_message_channel.rb +++ b/plugins/chat/app/models/chat/direct_message_channel.rb @@ -3,6 +3,7 @@ module Chat class DirectMessageChannel < Channel alias_method :direct_message, :chatable + before_validation(on: :create) { self.threading_enabled = true } def direct_message_channel? true diff --git a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs index 292cfaf8098..75fea4dfed5 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat/routes/channel-info-settings.gjs @@ -98,10 +98,14 @@ export default class ChatRouteChannelInfoSettings extends Component { return this.args.channel.isCategoryChannel && this.args.channel.isOpen; } - get toggleThreadingAvailable() { + get toggleThreadingCategoryChannel() { return this.args.channel.isCategoryChannel && this.args.channel.isOpen; } + get toggleThreadingDirectMessage() { + return this.args.channel.isDirectMessageChannel && this.args.channel.isOpen; + } + get channelWideMentionsDescription() { return I18n.t("chat.settings.channel_wide_mentions_description", { channel: this.args.channel.title, @@ -420,6 +424,28 @@ export default class ChatRouteChannelInfoSettings extends Component { {{/if}} + + {{#if this.toggleThreadingDirectMessage}} + + <:action> + + + + <:description> + {{this.toggleThreadingDescription}} + + + {{/if}} {{/if}} @@ -482,7 +508,7 @@ export default class ChatRouteChannelInfoSettings extends Component { {{/if}} - {{#if this.toggleThreadingAvailable}} + {{#if this.toggleThreadingCategoryChannel}} <:action>