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