diff --git a/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js b/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js index 938dda3c4ef..ea67d8b0f59 100644 --- a/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js +++ b/plugins/chat/assets/javascripts/discourse/lib/chat-message-interactor.js @@ -233,7 +233,7 @@ export default class ChatMessageInteractor { const threadId = this.message.thread?.id; let url; - if (threadId) { + if (this.context === MESSAGE_CONTEXT_THREAD && threadId) { url = getURL(`/chat/c/-/${channelId}/t/${threadId}`); } else { url = getURL(`/chat/c/-/${channelId}/${this.message.id}`); diff --git a/plugins/chat/spec/system/chat_message/channel_spec.rb b/plugins/chat/spec/system/chat_message/channel_spec.rb index 3027f515eff..fb6aef95825 100644 --- a/plugins/chat/spec/system/chat_message/channel_spec.rb +++ b/plugins/chat/spec/system/chat_message/channel_spec.rb @@ -37,5 +37,30 @@ RSpec.describe "Chat message - channel", type: :system, js: true do expect(cdp.read_clipboard).to include("/chat/c/-/#{channel_1.id}/#{message_1.id}") end + + context "when the message is part of a thread" do + before do + SiteSetting.enable_experimental_chat_threaded_discussions = true + channel_1.update!(threading_enabled: true) + end + + fab!(:thread_1) do + chat_thread_chain_bootstrap( + channel: channel_1, + users: [current_user, Fabricate(:user)], + messages_count: 2, + ) + end + + it "copies the link to the message and not to the thread" do + chat.visit_channel(channel_1) + + channel.copy_link(thread_1.original_message) + + expect(cdp.read_clipboard).to include( + "/chat/c/-/#{channel_1.id}/#{thread_1.original_message.id}", + ) + end + end end end diff --git a/plugins/chat/spec/system/chat_message/thread_spec.rb b/plugins/chat/spec/system/chat_message/thread_spec.rb index 15f6e639308..e9b9bfbcfb4 100644 --- a/plugins/chat/spec/system/chat_message/thread_spec.rb +++ b/plugins/chat/spec/system/chat_message/thread_spec.rb @@ -10,8 +10,7 @@ RSpec.describe "Chat message - thread", type: :system, js: true do let(:cdp) { PageObjects::CDP.new } let(:chat) { PageObjects::Pages::Chat.new } - let(:channel) { PageObjects::Pages::ChatChannel.new } - let(:thread) { PageObjects::Pages::ChatThread.new } + let(:thread_page) { PageObjects::Pages::ChatThread.new } let(:message_1) { thread_1.chat_messages.first } before do @@ -28,7 +27,7 @@ RSpec.describe "Chat message - thread", type: :system, js: true do first_message = thread_1.chat_messages.first chat.visit_thread(thread_1) - thread.hover_message(first_message) + thread_page.hover_message(first_message) expect(page).to have_css( ".chat-thread[data-id='#{thread_1.id}'] [data-id='#{first_message.id}'] .chat-message.is-active", @@ -42,7 +41,7 @@ RSpec.describe "Chat message - thread", type: :system, js: true do it "copies the link to the thread" do chat.visit_thread(thread_1) - channel.copy_link(message_1) + thread_page.copy_link(message_1) expect(cdp.read_clipboard).to include("/chat/c/-/#{channel_1.id}/t/#{thread_1.id}") end diff --git a/plugins/chat/spec/system/page_objects/chat/chat_thread.rb b/plugins/chat/spec/system/page_objects/chat/chat_thread.rb index 13e31b1a245..d53b743ab00 100644 --- a/plugins/chat/spec/system/page_objects/chat/chat_thread.rb +++ b/plugins/chat/spec/system/page_objects/chat/chat_thread.rb @@ -66,6 +66,16 @@ module PageObjects end end + def copy_link(message) + hover_message(message) + click_more_button + find("[data-value='copyLink']").click + end + + def click_more_button + find(".more-buttons").click + end + def hover_message(message) message_by_id(message.id).hover end