Skip to content

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

UX: avoid destructive leave group DM on chat drawer (#37613)

Renato Atiliof92be6072471
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 03d5cd45722..5313ce65f7d 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
@@ -592,6 +592,7 @@ export default class ChatRouteChannelInfoSettings extends Component {
leaveClass="btn-danger"
joinIcon="right-to-bracket"
leaveIcon="right-from-bracket"
+ leaveDestructive=true
}}
/>
</:action>
diff --git a/plugins/chat/assets/javascripts/discourse/components/toggle-channel-membership-button.gjs b/plugins/chat/assets/javascripts/discourse/components/toggle-channel-membership-button.gjs
index 8d2299acd7e..353c9fae144 100644
--- a/plugins/chat/assets/javascripts/discourse/components/toggle-channel-membership-button.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/toggle-channel-membership-button.gjs
@@ -76,7 +76,9 @@ export default class ToggleChannelMembershipButton extends Component {
this.isLoading = true;
try {
- if (this.args.channel.chatable.group) {
+ // For DM channels (including group DMs), use non-destructive unfollow
+ // unless explicitly requested to be destructive (e.g., from settings page)
+ if (this.args.channel.chatable.group && this.options.leaveDestructive) {
await this.chatApi.leaveChannel(this.args.channel.id);
} else {
await this.chat.unfollowChannel(this.args.channel);
diff --git a/plugins/chat/spec/system/drawer/index_spec.rb b/plugins/chat/spec/system/drawer/index_spec.rb
index d4dee4155f9..845b26eeea4 100644
--- a/plugins/chat/spec/system/drawer/index_spec.rb
+++ b/plugins/chat/spec/system/drawer/index_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe "Drawer - index", type: :system do
expect(row).to be_non_existent
end
- it "can leave a group message" do
+ it "can close a group message and membership is retained" do
channel =
Fabricate(
:direct_message_channel,
@@ -48,6 +48,8 @@ RSpec.describe "Drawer - index", type: :system do
row.leave
expect(row).to be_non_existent
+ expect(channel.membership_for(current_user)).to be_present
+ expect(channel.membership_for(current_user).following).to be_falsy
end
it "can open browse" do