From 6d917f82d7a0b5d9b724cd566fc7c8163ca74cea Mon Sep 17 00:00:00 2001 From: FreeScout Date: Sat, 16 Dec 2023 21:15:02 -0800 Subject: [PATCH] Add as CC a customer who was in CC and replied to the conversation - #3613 --- app/Conversation.php | 2 +- .../Controllers/ConversationsController.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/Conversation.php b/app/Conversation.php index 722ca84a2..2bca11cf0 100644 --- a/app/Conversation.php +++ b/app/Conversation.php @@ -1643,7 +1643,7 @@ public static function typeToName($type) } /** - * Get emails which are excluded from CC and BCC. + * Get emails which should be excluded from CC and BCC. */ public function getExcludeArray($mailbox = null) { diff --git a/app/Http/Controllers/ConversationsController.php b/app/Http/Controllers/ConversationsController.php index f06ca6479..417e1d010 100755 --- a/app/Http/Controllers/ConversationsController.php +++ b/app/Http/Controllers/ConversationsController.php @@ -236,7 +236,24 @@ public function view(Request $request, $id) $template = 'conversations/create'; } + // CC. $exclude_array = $conversation->getExcludeArray($mailbox); + $cc = $conversation->getCcArray($exclude_array); + + // If last reply came from customer who was mentioned in CC before, + // we need to add this customer as CC. + // https://github.com/freescout-helpdesk/freescout/issues/3613 + foreach ($threads as $thread) { + if ($thread->isUserMessage() && !$thread->isDraft()) { + break; + } + if ($thread->isCustomerMessage()) { + if ($thread->customer_id != $conversation->customer_id) { + $cc[] = $thread->from; + } + break; + } + } // Get data for creating a phone conversation. $name = []; @@ -352,7 +369,7 @@ public function view(Request $request, $id) 'to' => $new_conv_to, 'to_customers' => $to_customers, 'prev_conversations' => $prev_conversations, - 'cc' => $conversation->getCcArray($exclude_array), + 'cc' => $cc, 'bcc' => [], //$conversation->getBccArray($exclude_array), // Data for creating a phone conversation. 'name' => $name,