From 9b024bda31c94da191e52347416d70d193217555 Mon Sep 17 00:00:00 2001 From: FreeScout Date: Sat, 2 Dec 2023 00:46:47 -0800 Subject: [PATCH] Do not change customer when CCed email replies to a conversation - closes #3551 --- app/Console/Commands/FetchEmails.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/FetchEmails.php b/app/Console/Commands/FetchEmails.php index 58d6b5a96..e24383fea 100644 --- a/app/Console/Commands/FetchEmails.php +++ b/app/Console/Commands/FetchEmails.php @@ -902,6 +902,7 @@ public function saveCustomerThread($mailbox, $message_id, $prev_thread, $from, $ $now = date('Y-m-d H:i:s'); } $conv_cc = $cc; + $prev_conv_cc = $conv_cc; // Customers are created before with email and name $customer = Customer::create($from); @@ -911,6 +912,7 @@ public function saveCustomerThread($mailbox, $message_id, $prev_thread, $from, $ // If reply came from another customer: change customer, add original as CC. // If FreeScout will not change the customer, the reply will be shown // as coming from the original customer (not the real sender) and cause confusion. + // Below after events are fired we roll customer back. if ($conversation->customer_id != $customer->id) { $prev_customer_id = $conversation->customer_id; $prev_customer_email = $conversation->customer_email; @@ -1043,8 +1045,16 @@ public function saveCustomerThread($mailbox, $message_id, $prev_thread, $from, $ } // Conversation customer changed + // if ($prev_customer_id) { + // event(new ConversationCustomerChanged($conversation, $prev_customer_id, $prev_customer_email, null, $customer)); + // } + + // Return original customer back. if ($prev_customer_id) { - event(new ConversationCustomerChanged($conversation, $prev_customer_id, $prev_customer_email, null, $customer)); + $conversation->customer_id = $prev_customer_id; + $conversation->customer_email = $prev_customer_email; + $conversation->setCc(array_merge($prev_conv_cc, array_diff($to, $mailbox->getEmails()))); + $conversation->save(); } return $thread;