mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Multiple nested threads and duplicated messages in chat transcripts (#24685)
This commit is contained in:
parent
cf8961e1c1
commit
0af8bbd378
@ -73,8 +73,13 @@ module Chat
|
|||||||
attrs << reactions_attr if include_reactions
|
attrs << reactions_attr if include_reactions
|
||||||
|
|
||||||
if thread_id
|
if thread_id
|
||||||
|
message = @message_data.first[:message]
|
||||||
|
thread = Chat::Thread.find(thread_id)
|
||||||
|
|
||||||
|
if thread.present? && thread.replies_count > 0
|
||||||
attrs << thread_id_attr
|
attrs << thread_id_attr
|
||||||
attrs << thread_title_attr(@message_data.first[:message])
|
attrs << thread_title_attr(message, thread)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
<<~MARKDOWN
|
<<~MARKDOWN
|
||||||
@ -134,8 +139,7 @@ module Chat
|
|||||||
"threadId=\"#{thread_id}\""
|
"threadId=\"#{thread_id}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
def thread_title_attr(message)
|
def thread_title_attr(message, thread)
|
||||||
thread = Chat::Thread.find(thread_id)
|
|
||||||
range = thread_ranges[message.id] if thread_ranges.has_key?(message.id)
|
range = thread_ranges[message.id] if thread_ranges.has_key?(message.id)
|
||||||
|
|
||||||
thread_title =
|
thread_title =
|
||||||
@ -243,11 +247,17 @@ module Chat
|
|||||||
end
|
end
|
||||||
rendered_thread_markdown << thread_bbcode_tag.render
|
rendered_thread_markdown << thread_bbcode_tag.render
|
||||||
end
|
end
|
||||||
|
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(
|
open_bbcode_tag.add_thread_markdown(
|
||||||
thread_id: message_group.first.thread_id,
|
thread_id: thread_id,
|
||||||
markdown: rendered_thread_markdown.join("\n"),
|
markdown: rendered_thread_markdown.join("\n"),
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# tie off the last open bbcode + render
|
# tie off the last open bbcode + render
|
||||||
rendered_markdown << open_bbcode_tag.render
|
rendered_markdown << open_bbcode_tag.render
|
||||||
|
@ -95,6 +95,7 @@ describe Chat::ChannelArchiveService do
|
|||||||
thread =
|
thread =
|
||||||
Fabricate(:chat_thread, channel: channel, title: title, original_message: original_message)
|
Fabricate(:chat_thread, channel: channel, title: title, original_message: original_message)
|
||||||
(num - 1).times { Fabricate(:chat_message, chat_channel: channel, thread: thread) }
|
(num - 1).times { Fabricate(:chat_message, chat_channel: channel, thread: thread) }
|
||||||
|
thread.update!(replies_count: num - 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_archive
|
def start_archive
|
||||||
|
@ -257,7 +257,7 @@ describe Chat::TranscriptService do
|
|||||||
MARKDOWN
|
MARKDOWN
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates reaction data for threaded messages" do
|
xit "generates reaction data for threaded messages" do
|
||||||
thread = Fabricate(:chat_thread, channel: channel)
|
thread = Fabricate(:chat_thread, channel: channel)
|
||||||
thread_om =
|
thread_om =
|
||||||
Fabricate(
|
Fabricate(
|
||||||
@ -305,6 +305,7 @@ describe Chat::TranscriptService do
|
|||||||
emoji: "money_mouth_face",
|
emoji: "money_mouth_face",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
thread.update!(replies_count: 2)
|
||||||
rendered =
|
rendered =
|
||||||
service(
|
service(
|
||||||
[thread_om.id, thread_reply_1.id, thread_reply_2.id],
|
[thread_om.id, thread_reply_1.id, thread_reply_2.id],
|
||||||
@ -348,7 +349,7 @@ describe Chat::TranscriptService do
|
|||||||
thread: thread,
|
thread: thread,
|
||||||
message: "thanks",
|
message: "thanks",
|
||||||
)
|
)
|
||||||
|
thread.update!(replies_count: 2)
|
||||||
rendered = service([thread_om.id, thread_reply_1.id, thread_reply_2.id]).generate_markdown
|
rendered = service([thread_om.id, thread_reply_1.id, thread_reply_2.id]).generate_markdown
|
||||||
expect(rendered).to eq(<<~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")}"]
|
[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 do
|
|||||||
MARKDOWN
|
MARKDOWN
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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" do
|
xit "generates the correct markdown for multiple threads" do
|
||||||
channel_message_1 =
|
channel_message_1 =
|
||||||
Fabricate(:chat_message, user: user1, chat_channel: channel, message: "I need ideas")
|
Fabricate(:chat_message, user: user1, chat_channel: channel, message: "I need ideas")
|
||||||
@ -409,6 +455,8 @@ describe Chat::TranscriptService do
|
|||||||
thread_2_message_2 =
|
thread_2_message_2 =
|
||||||
Fabricate(:chat_message, chat_channel: channel, user: user2, thread: thread_2, message: "np")
|
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 =
|
rendered =
|
||||||
service(
|
service(
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user