mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 06:46:11 +08:00
90efdd7f9d
This commit starts from a simple observation: cooking messages on the hot path can be slow. Especially with a lot of mentions. To move cooking from the hot path, this commit has made the following changes: - updating cooked, inserting mentions and notifying user of new mentions has been moved inside the `process_message` job. It happens right after the `Chat::MessageProcessor` run, which is where the cooking happens. - the similar existing code in `rebake!` has also been moved to rely on the `process_message`job only - refactored `create_mentions` and `update_mentions` into one single `upsert_mentions` which can be called invariably - allows services to decide if their job is ran inline or later. It avoids to need to know you have to use `Jobs.run_immediately!` in this case, in tests it will be inline per default - made various frontend changes to make the chat-channel component lifecycle clearer. we had to handle `did-update @channel` which was super awkward and creating bugs with listeners which the changes of the PR made clear in failing specs - adds a new `-processed` (and `-not-processed`) class on the chat message, this is made to have a good lifecyle hook in system specs
79 lines
2.4 KiB
Ruby
79 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Chat message - thread", type: :system do
|
|
fab!(:current_user) { Fabricate(:user) }
|
|
fab!(:channel_1) { Fabricate(:chat_channel, threading_enabled: true) }
|
|
fab!(:thread_original_message) { Fabricate(:chat_message_with_service, chat_channel: channel_1) }
|
|
fab!(:thread_message_1) do
|
|
Fabricate(
|
|
:chat_message_with_service,
|
|
chat_channel: channel_1,
|
|
in_reply_to: thread_original_message,
|
|
)
|
|
end
|
|
|
|
let(:chat_page) { PageObjects::Pages::Chat.new }
|
|
let(:thread_page) { PageObjects::Pages::ChatThread.new }
|
|
|
|
before do
|
|
chat_system_bootstrap
|
|
channel_1.add(current_user)
|
|
sign_in(current_user)
|
|
end
|
|
|
|
context "when hovering a message" do
|
|
it "adds an active class" do
|
|
chat_page.visit_thread(thread_message_1.thread)
|
|
|
|
thread_page.hover_message(thread_message_1)
|
|
|
|
expect(page).to have_css(
|
|
".chat-thread[data-id='#{thread_message_1.thread.id}'] [data-id='#{thread_message_1.id}'].chat-message-container.-active",
|
|
)
|
|
end
|
|
end
|
|
|
|
context "when copying text of a message" do
|
|
let(:cdp) { PageObjects::CDP.new }
|
|
|
|
before { cdp.allow_clipboard }
|
|
|
|
it "[mobile] copies the text of a single message", mobile: true do
|
|
chat_page.visit_thread(thread_message_1.thread)
|
|
|
|
thread_page.messages.copy_text(thread_message_1)
|
|
|
|
expect(cdp.read_clipboard.chomp).to eq(thread_message_1.message)
|
|
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.text_copied"))
|
|
end
|
|
end
|
|
|
|
context "when copying link to a message" do
|
|
let(:cdp) { PageObjects::CDP.new }
|
|
|
|
before { cdp.allow_clipboard }
|
|
|
|
it "copies the link to the thread" do
|
|
chat_page.visit_thread(thread_message_1.thread)
|
|
|
|
thread_page.messages.copy_link(thread_message_1)
|
|
|
|
expect(cdp.read_clipboard).to include(
|
|
"/chat/c/-/#{channel_1.id}/t/#{thread_message_1.thread.id}/#{thread_message_1.id}",
|
|
)
|
|
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.link_copied"))
|
|
end
|
|
|
|
it "[mobile] copies the link to the thread", mobile: true do
|
|
chat_page.visit_thread(thread_message_1.thread)
|
|
|
|
thread_page.messages.copy_link(thread_message_1)
|
|
|
|
expect(cdp.read_clipboard).to include(
|
|
"/chat/c/-/#{channel_1.id}/t/#{thread_message_1.thread.id}/#{thread_message_1.id}",
|
|
)
|
|
expect(PageObjects::Components::Toasts.new).to have_success(I18n.t("js.chat.link_copied"))
|
|
end
|
|
end
|
|
end
|