From 906f48694c7fc3d7f77da9495a11e4680e953f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 14 May 2024 22:28:11 +0200 Subject: [PATCH] FIX: deep linking to a message in a thread Whenever you get a bookmark notification, a mention notification, or click on a bookmark on a message in a long thread, we should ensure we always highlight and show the proper message. Before this fix, we would correctly load the thread, but would always start at the bottom. Internal ref. t/128103 --- .../discourse/components/chat-thread.gjs | 5 +++-- .../chat/spec/system/bookmark_message_spec.rb | 21 +++++++++++++++++++ .../system/page_objects/chat/chat_thread.rb | 4 ++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs index f0f2bfbf108..d7d17565dad 100644 --- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs +++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs @@ -223,11 +223,12 @@ export default class ChatThread extends Component { this.messagesManager.clear(); - findArgs.targetMessageId ??= + findArgs.target_message_id ??= + findArgs.targetMessageId || this.args.targetMessageId || this.args.thread.currentUserMembership?.lastReadMessageId; - if (!findArgs.targetMessageId) { + if (!findArgs.target_message_id) { findArgs.direction = FUTURE; } diff --git a/plugins/chat/spec/system/bookmark_message_spec.rb b/plugins/chat/spec/system/bookmark_message_spec.rb index 816e0beaaef..303416dbbcd 100644 --- a/plugins/chat/spec/system/bookmark_message_spec.rb +++ b/plugins/chat/spec/system/bookmark_message_spec.rb @@ -5,6 +5,7 @@ RSpec.describe "Bookmark message", type: :system do let(:chat_page) { PageObjects::Pages::Chat.new } let(:channel_page) { PageObjects::Pages::ChatChannel.new } + let(:thread_page) { PageObjects::Pages::ChatThread.new } let(:bookmark_modal) { PageObjects::Modals::Bookmark.new } fab!(:category_channel_1) { Fabricate(:category_channel) } @@ -27,6 +28,26 @@ RSpec.describe "Bookmark message", type: :system do expect(channel_page).to have_bookmarked_message(message_1) end + it "supports linking to a bookmark in a long thread" do + category_channel_1.update!(threading_enabled: true) + category_channel_1.add(current_user) + + thread = + chat_thread_chain_bootstrap( + channel: category_channel_1, + users: [current_user, Fabricate(:user)], + messages_count: Chat::MessagesQuery::MAX_PAGE_SIZE + 1, + ) + + first_message = thread.replies.first + + bookmark = Bookmark.create!(bookmarkable: first_message, user: current_user) + + visit bookmark.bookmarkable.url + + expect(thread_page).to have_bookmarked_message(first_message) + end + context "when the user has a bookmark auto_delete_preference" do before do current_user.user_option.update!( 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 5a1c69d2997..5ec9364c9be 100644 --- a/plugins/chat/spec/system/page_objects/chat/chat_thread.rb +++ b/plugins/chat/spec/system/page_objects/chat/chat_thread.rb @@ -140,6 +140,10 @@ module PageObjects messages.edit(message) send_message(message.message + " " + text) if text end + + def has_bookmarked_message?(message) + find(message_by_id_selector(message.id) + ".-bookmarked") + end end end end