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
This commit is contained in:
Régis Hanol 2024-05-14 22:28:11 +02:00
parent 777b8f6d51
commit 906f48694c
3 changed files with 28 additions and 2 deletions

View File

@ -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;
}

View File

@ -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!(

View File

@ -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