diff --git a/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js b/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js index 81607fcf2ad..f818908862a 100644 --- a/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js +++ b/plugins/chat/assets/javascripts/lib/discourse-markdown/chat-transcript.js @@ -30,6 +30,7 @@ const chatTranscriptRule = { return; } + const isThread = threadId && content.includes("[chat"); let wrapperDivToken = state.push("div_chat_transcript_wrap", "div", 1); if (channelName && multiQuote) { @@ -53,7 +54,7 @@ const chatTranscriptRule = { state.push("div_chat_transcript_meta", "div", -1); } - if (threadId) { + if (isThread) { state.push("details_chat_transcript_wrap_open", "details", 1); state.push("summary_chat_transcript_open", "summary", 1); @@ -227,7 +228,7 @@ const chatTranscriptRule = { let messagesToken = state.push("div_chat_transcript_messages", "div", 1); messagesToken.attrs = [["class", "chat-transcript-messages"]]; - if (threadId) { + if (isThread) { const regex = /\[chat/i; const match = regex.exec(content); diff --git a/plugins/chat/spec/lib/chat/pretty_text_spec.rb b/plugins/chat/spec/lib/chat/pretty_text_spec.rb new file mode 100644 index 00000000000..094daf97c18 --- /dev/null +++ b/plugins/chat/spec/lib/chat/pretty_text_spec.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: true + +RSpec.describe PrettyText do + it "allows quoting chained messages" do + cooked = PrettyText.cook <<~MD + [chat quote="jan;101;2023-12-01T21:10:53Z" channel="Tech Talks" channelId="5" multiQuote="true" chained="true"] + message 1 + [/chat] + + [chat quote="Kai;102;2023-12-01T21:10:53Z" chained="true"] + message 2 + + message 3 + [/chat] + MD + + expect(cooked).to include('class="chat-transcript chat-transcript-chained"') + expect(cooked).to include('data-channel-name="Tech Talks"') + expect(cooked).to include('data-channel-id="5"') + end + + it "allows quoting non-chained messages" do + cooked = PrettyText.cook <<~MD + [chat quote="jan;101;2023-12-01T21:10:53Z" channel="Tech Talks" channelId="5"] + message 1 + [/chat] + + [chat quote="Kai;102;2023-12-01T21:10:53Z"] + message 2 + + message 3 + [/chat] + MD + + expect(cooked).to include('class="chat-transcript"') + expect(cooked).to include('data-channel-name="Tech Talks"') + expect(cooked).to include('data-channel-id="5"') + expect(cooked).not_to include("chat-transcript-chained") + end + + it "includes channel metadata" do + cooked = PrettyText.cook <<~MD + [chat quote="alice;103;2023-12-02T10:20:30Z" channel="Game Grove" channelId="5" multiQuote="true"] + message + [/chat] + MD + + expect(cooked).to include( + "
", + ) + end + + it "includes message reactions" do + cooked = PrettyText.cook <<~MD + [chat quote="alice;103;2023-12-02T10:20:30Z" reactions="smile:alice,bob;heart:carol"] + This is a test message with reactions + [/chat] + MD + + expect(cooked).to include( + "