Skip to content

Commit

Permalink
Copy attachments when creating a new conversation from some message - c…
Browse files Browse the repository at this point in the history
…loses #3647
  • Loading branch information
freescout-help-desk committed Jan 4, 2024
1 parent 359f6c4 commit e5da621
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
5 changes: 2 additions & 3 deletions app/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,8 @@ public static function deleteAttachments($attachments)
public function duplicate($thread_id = null)
{
$new_attachment = $this->replicate();
if ($thread_id) {
$new_attachment->thread_id = $thread_id;
}

$new_attachment->thread_id = $thread_id;

$new_attachment->save();

Expand Down
15 changes: 14 additions & 1 deletion app/Http/Controllers/ConversationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,14 @@ public function create(Request $request, $mailbox_id)

// Create conversation from thread
$thread = null;
$attachments = [];
if (!empty($request->from_thread_id)) {
$orig_thread = Thread::find($request->from_thread_id);
if ($orig_thread) {
$subject = $orig_thread->conversation->subject;
$subject = preg_replace('/^Fwd:/i', 'Re: ', $subject);

$thread = new \App\Thread();
$thread = new Thread();
$thread->body = $orig_thread->body;
// If this is a forwarded message, try to fetch From
preg_match_all("/From:[^<\n]+<([^<\n]+)>/m", html_entity_decode(strip_tags($thread->body)), $m);
Expand All @@ -422,6 +423,17 @@ public function create(Request $request, $mailbox_id)
}
}
}

// Clone attachments.
$orig_attachments = Attachment::where('thread_id', $orig_thread->id)->get();

if (count($orig_attachments)) {
$conversation->has_attachments = true;
$thread->has_attachments = true;
foreach ($orig_attachments as $attachment) {
$attachments[] = $attachment->duplicate();
}
}
}
}

Expand All @@ -443,6 +455,7 @@ public function create(Request $request, $mailbox_id)
'after_send' => $after_send,
'to' => $to,
'from_aliases' => $mailbox->getAliases(true, true),
'attachments' => $attachments,
]);
}

Expand Down
20 changes: 18 additions & 2 deletions resources/views/conversations/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,24 @@
</div>
@action('conversation.create_form.after_subject', $conversation, $mailbox, $thread)

<div class="thread-attachments attachments-upload">
<ul></ul>
@php
if (!isset($attachments)) {
//$attachments = $conversation->getAttachments();
$attachments = [];
}
@endphp
<div class="thread-attachments attachments-upload" @if (count($attachments)) style="display: block" @endif>
@foreach ($attachments as $attachment)
<input type="hidden" name="attachments_all[]" value="{{ $attachment->id }}">
<input type="hidden" name="attachments[]" value="{{ $attachment->id }}" class="atachment-upload-{{ $attachment->id }}">
@endforeach
<ul>
@foreach ($attachments as $attachment)
<li class="atachment-upload-{{ $attachment->id }} attachment-loaded">
<img src="{{ asset('img/loader-tiny.gif') }}" width="16" height="16"> <a href="{{ $attachment->url() }}" class="break-words" target="_blank">{{ $attachment->file_name }}<span class="ellipsis">…</span> </a> <span class="text-help">({{ $attachment->getSizeName() }})</span> <i class="glyphicon glyphicon-remove" data-attachment-id="{{ $attachment->id }}"></i>
</li>
@endforeach
</ul>
</div>

<div class="form-group{{ $errors->has('body') ? ' has-error' : '' }} conv-reply-body">
Expand Down

0 comments on commit e5da621

Please sign in to comment.