Skip to content

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

FIX: new DM channels not being published (#36799)

Sam2e5de56353d7
diff --git a/plugins/chat/app/services/chat/create_direct_message_channel.rb b/plugins/chat/app/services/chat/create_direct_message_channel.rb
index 8c5527bb106..5a4e8cb7e73 100644
--- a/plugins/chat/app/services/chat/create_direct_message_channel.rb
+++ b/plugins/chat/app/services/chat/create_direct_message_channel.rb
@@ -99,7 +99,7 @@ module Chat
channel.update!(optional_params) if !optional_params.empty?
end
- def create_memberships(channel:, target_users:)
+ def create_memberships(channel:, target_users:, guardian:)
always_level = ::Chat::UserChatChannelMembership::NOTIFICATION_LEVELS[:always]
memberships =
@@ -108,7 +108,7 @@ module Chat
user_id: user.id,
chat_channel_id: channel.id,
muted: false,
- following: true,
+ following: user.id == guardian.user.id,
notification_level: always_level,
created_at: Time.zone.now,
updated_at: Time.zone.now,
diff --git a/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rb b/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rb
index 4f352821691..96af40322c6 100644
--- a/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rb
+++ b/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rb
@@ -63,8 +63,9 @@ RSpec.describe Chat::CreateDirectMessageChannel do
[current_user.id, user_1.id, user_2.id],
)
result.channel.user_chat_channel_memberships.each do |membership|
+ should_follow = membership.user_id == current_user.id
expect(membership).to have_attributes(
- following: true,
+ following: should_follow,
muted: false,
notification_level: "always",
)
diff --git a/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb b/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb
index b7882981923..5852e6924ad 100644
--- a/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb
+++ b/plugins/chat/spec/system/message_notifications_with_sidebar_spec.rb
@@ -164,6 +164,33 @@ RSpec.describe "Message notifications - with sidebar", type: :system do
end
end
+ context "when a new direct message channel is created" do
+ fab!(:other_user, :user)
+ let!(:chat_sidebar) { PageObjects::Components::Chat::Sidebar.new }
+
+ it "shows the channel in the sidebar without reload" do
+ visit("/")
+
+ expect(chat_sidebar).to have_start_new_dm
+
+ result =
+ Chat::CreateDirectMessageChannel.call(
+ guardian: other_user.guardian,
+ params: {
+ target_usernames: [current_user.username],
+ },
+ )
+ service_failed!(result) if result.failure?
+
+ dm_channel = result.channel
+
+ create_message(channel: dm_channel, creator: other_user)
+
+ expect(chat_sidebar).to have_direct_message_channel(dm_channel)
+ expect(chat_sidebar).to have_no_start_new_dm
+ end
+ end
+
context "with dm channel" do
fab!(:current_user, :admin)
fab!(:user_1, :user)