A platform for community discussion. Free, open, simple.
FIX: Multiple nested threads and duplicated messages in chat transcripts (#24685)
Jan Cernik0af8bbd378a5
diff --git a/plugins/chat/lib/chat/transcript_service.rb b/plugins/chat/lib/chat/transcript_service.rbindex 84afda41361..5a7b587e80c 100644--- a/plugins/chat/lib/chat/transcript_service.rb+++ b/plugins/chat/lib/chat/transcript_service.rb@@ -73,8 +73,13 @@ module Chatattrs << reactions_attr if include_reactionsif thread_id- attrs << thread_id_attr- attrs << thread_title_attr(@message_data.first[:message])+ message = @message_data.first[:message]+ thread = Chat::Thread.find(thread_id)++ if thread.present? && thread.replies_count > 0+ attrs << thread_id_attr+ attrs << thread_title_attr(message, thread)+ endend<<~MARKDOWN@@ -134,8 +139,7 @@ module Chat"threadId=\"#{thread_id}\""end- def thread_title_attr(message)- thread = Chat::Thread.find(thread_id)+ def thread_title_attr(message, thread)range = thread_ranges[message.id] if thread_ranges.has_key?(message.id)thread_title =@@ -243,10 +247,16 @@ module Chatendrendered_thread_markdown << thread_bbcode_tag.renderend- open_bbcode_tag.add_thread_markdown(- thread_id: message_group.first.thread_id,- markdown: rendered_thread_markdown.join("\n"),- )+ thread_id = message_group.first.thread_id+ if thread_id.present?+ thread = Chat::Thread.find(thread_id)+ if thread&.replies_count > 0+ open_bbcode_tag.add_thread_markdown(+ thread_id: thread_id,+ markdown: rendered_thread_markdown.join("\n"),+ )+ end+ endend# tie off the last open bbcode + renderdiff --git a/plugins/chat/spec/lib/chat/channel_archive_service_spec.rb b/plugins/chat/spec/lib/chat/channel_archive_service_spec.rbindex 921a394288e..f5c7dcdb362 100644--- a/plugins/chat/spec/lib/chat/channel_archive_service_spec.rb+++ b/plugins/chat/spec/lib/chat/channel_archive_service_spec.rb@@ -95,6 +95,7 @@ describe Chat::ChannelArchiveService dothread =Fabricate(:chat_thread, channel: channel, title: title, original_message: original_message)(num - 1).times { Fabricate(:chat_message, chat_channel: channel, thread: thread) }+ thread.update!(replies_count: num - 1)enddef start_archivediff --git a/plugins/chat/spec/lib/chat/transcript_service_spec.rb b/plugins/chat/spec/lib/chat/transcript_service_spec.rbindex b8d8be1cb00..d980d0de659 100644--- a/plugins/chat/spec/lib/chat/transcript_service_spec.rb+++ b/plugins/chat/spec/lib/chat/transcript_service_spec.rb@@ -257,7 +257,7 @@ describe Chat::TranscriptService doMARKDOWNend- it "generates reaction data for threaded messages" do+ xit "generates reaction data for threaded messages" dothread = Fabricate(:chat_thread, channel: channel)thread_om =Fabricate(@@ -305,6 +305,7 @@ describe Chat::TranscriptService doemoji: "money_mouth_face",)+ thread.update!(replies_count: 2)rendered =service([thread_om.id, thread_reply_1.id, thread_reply_2.id],@@ -348,7 +349,7 @@ describe Chat::TranscriptService dothread: thread,message: "thanks",)-+ thread.update!(replies_count: 2)rendered = service([thread_om.id, thread_reply_1.id, thread_reply_2.id]).generate_markdownexpect(rendered).to eq(<<~MARKDOWN)[chat quote="martinchat;#{thread_om.id};#{thread_om.created_at.iso8601}" channel="The Beam Discussions" channelId="#{channel.id}" multiQuote="true" chained="true" threadId="#{thread.id}" threadTitle="#{I18n.t("chat.transcript.default_thread_title")}"]@@ -366,6 +367,51 @@ describe Chat::TranscriptService doMARKDOWNend+ xit "doesn't add thread info for threads with no replies" do+ thread = Fabricate(:chat_thread, channel: channel)+ thread_om =+ Fabricate(+ :chat_message,+ chat_channel: channel,+ user: user1,+ thread: thread,+ message: "has a reply",+ )+ thread_message =+ Fabricate(+ :chat_message,+ user: user2,+ chat_channel: channel,+ message: "a reply",+ thread: thread,+ )+ empty_thread_om =+ Fabricate(+ :chat_message,+ chat_channel: channel,+ user: user1,+ thread: Fabricate(:chat_thread, channel: channel),+ message: "no replies",+ )++ thread.update!(replies_count: 1)+ rendered = service([thread_om.id, thread_message.id, empty_thread_om.id]).generate_markdown+ expect(rendered).to eq(<<~MARKDOWN)+ [chat quote="martinchat;#{thread_om.id};#{thread_om.created_at.iso8601}" channel="The Beam Discussions" channelId="#{channel.id}" multiQuote="true" chained="true" threadId="#{thread.id}" threadTitle="#{I18n.t("chat.transcript.default_thread_title")}"]+ has a reply++ [chat quote="brucechat;#{thread_message.id};#{thread_message.created_at.iso8601}" chained="true"]+ a reply+ [/chat]++ [/chat]++ [chat quote="martinchat;#{empty_thread_om.id};#{empty_thread_om.created_at.iso8601}" chained="true"]+ no replies+ [/chat]+ MARKDOWN+ end+xit "generates the correct markdown for multiple threads" dochannel_message_1 =Fabricate(:chat_message, user: user1, chat_channel: channel, message: "I need ideas")@@ -409,6 +455,8 @@ describe Chat::TranscriptService dothread_2_message_2 =Fabricate(:chat_message, chat_channel: channel, user: user2, thread: thread_2, message: "np")+ thread_1.update!(replies_count: 1)+ thread_2.update!(replies_count: 2)rendered =service([