FEATURE: Copy thread messages when copying thread OP (#32139)

This introduces functionality to chat transcripts. If
you select _only_ a thread's OP and press the Copy button,
we will now copy the OP plus all of the thread's replies
into the transcript.

This is being done to make it easier to copy all the context
of a thread easily. The old way of selecting only some messages
inside a thread still works too.

This commit also unskips and refactors some transcript specs.
This commit is contained in:
Martin Brennan
2025-04-04 13:45:37 +10:00
committed by GitHub
parent 568ccdc19d
commit 3d6b7e2574
2 changed files with 122 additions and 36 deletions

View File

@ -166,9 +166,17 @@ module Chat
previous_message = nil
rendered_markdown = []
rendered_thread_markdown = []
all_messages_same_user = messages.count(:user_id) == 1
threading_enabled = @channel.threading_enabled?
thread_id = threading_enabled ? messages.first.thread_id : nil
thread = Chat::Thread.find_by(id: thread_id) if thread_id.present? && threading_enabled
# We are getting only the OP of the thread, let's expand it to
# include all the replies for the thread.
if messages.count == 1 && thread&.original_message_id == messages.first.id
@messages = [messages.first] + messages.first.thread.replies
end
all_messages_same_user = messages.map(&:user_id).uniq.count == 1
open_bbcode_tag =
TranscriptBBCode.new(