Skip to content

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

FIX: Unfollow not leave DM/group DM channels in chat sidebar menu (#37165)

Martin Brennanfe6dd5ed5388
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs
index bea9cad4302..5282b8e08df 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-channel-sidebar-context-menu.gjs
@@ -35,10 +35,6 @@ export default class ChatChannelSidebarContextMenu extends Component {
: "chat.channel_settings.star_channel";
}
- get isGroupChannel() {
- return !!this.channel?.chatable?.group;
- }
-
@action
async toggleStarred() {
if (!this.currentUserMembership || this.isTogglingStarred) {
@@ -67,10 +63,10 @@ export default class ChatChannelSidebarContextMenu extends Component {
@action
async leaveChannel() {
try {
- if (this.isGroupChannel) {
- await this.chatApi.leaveChannel(this.channel.id);
- } else {
+ if (this.channel.isDirectMessageChannel) {
await this.chat.unfollowChannel(this.channel);
+ } else {
+ await this.chatApi.leaveChannel(this.channel.id);
}
this.currentUser.custom_fields.last_chat_channel_id = null;
diff --git a/plugins/chat/spec/system/chat_channel_sidebar_context_menu_spec.rb b/plugins/chat/spec/system/chat_channel_sidebar_context_menu_spec.rb
index 5bc00cdfb57..5cf690b2b55 100644
--- a/plugins/chat/spec/system/chat_channel_sidebar_context_menu_spec.rb
+++ b/plugins/chat/spec/system/chat_channel_sidebar_context_menu_spec.rb
@@ -86,6 +86,24 @@ RSpec.describe "Chat channel sidebar context menu", type: :system do
expect(page).to have_current_path(chat.channel_path(channel_1.slug, channel_1.id))
end
end
+
+ context "when removing a group dm channel" do
+ fab!(:group_dm_channel) do
+ Fabricate(
+ :direct_message_channel,
+ users: [current_user, Fabricate(:user), Fabricate(:user)],
+ )
+ end
+
+ it "removes the channel from sidebar but membership remains" do
+ chat_page.visit_channel(group_dm_channel)
+ chat_sidebar_page.remove_channel(group_dm_channel)
+
+ expect(chat_sidebar_page).to have_no_channel(group_dm_channel)
+ expect(group_dm_channel.membership_for(current_user)).to be_present
+ expect(group_dm_channel.membership_for(current_user).following).to be_falsy
+ end
+ end
end
context "when changing notification settings" do