diff --git a/Providers/MMFCustomersGroupsServiceProvider.php b/Providers/MMFCustomersGroupsServiceProvider.php index 47ce823..b34874e 100644 --- a/Providers/MMFCustomersGroupsServiceProvider.php +++ b/Providers/MMFCustomersGroupsServiceProvider.php @@ -102,22 +102,44 @@ class MMFCustomersGroupsServiceProvider extends ServiceProvider { // Update the list of recipients if some groups have been selected. Eventy::addAction('conversation.send_reply_save', function($conversation, $request) { - $groups = $request->groups; + $groups_cc = $request->groups_cc; + $groups_bcc = $request->groups_bcc; // Return early if no group has been selected. - if ( empty($groups) ) return; - // Get the list of e-mails included in the selected groups. - $emails = new Collection; - foreach ( $groups as $group_id ) { - $group = CustomersGroup::find($group_id); - $emails = $emails->concat($group->emails()); + if ( empty($groups_cc) && empty($groups_bcc) ) return; + + // Cc - Get the list of e-mails included in the selected groups. + if ( !empty($groups_cc) ) { + $emails = new Collection; + foreach ( $groups_cc as $group_id ) { + $group = CustomersGroup::find($group_id); + $emails = $emails->concat($group->emails()); + } + $emails = $emails->unique('email')->pluck('email'); + // Update the list of Cc emails. + $cc = array_unique(array_merge( + $conversation->getCcArray(), + $emails->toArray() + )); + $conversation->setCc($cc); } - $emails = $emails->unique('email')->pluck('email'); - // Update the list of cc emails. - $cc = array_unique(array_merge( - $conversation->getCcArray(), - $emails->toArray() - )); - $conversation->setCc($cc); + + // Bcc - Get the list of e-mails included in the selected groups. + if ( !empty($groups_bcc) ) { + $emails = new Collection; + foreach ( $groups_bcc as $group_id ) { + $group = CustomersGroup::find($group_id); + $emails = $emails->concat($group->emails()); + } + $emails = $emails->unique('email')->pluck('email'); + // Update the list of Bcc emails. + $bcc = array_unique(array_merge( + $conversation->getBccArray(), + $emails->toArray() + )); + $conversation->setBcc($bcc); + } + + // TODO: Check if this explicit save() call is required. $conversation->save(); }, 20, 2); } diff --git a/Resources/views/conversations/partials/groups-selection.blade.php b/Resources/views/conversations/partials/groups-selection.blade.php index 8ec33d2..a28e73b 100644 --- a/Resources/views/conversations/partials/groups-selection.blade.php +++ b/Resources/views/conversations/partials/groups-selection.blade.php @@ -7,9 +7,9 @@ @include('partials/flash_messages') - -
- + +
+
@foreach ( $groups as $group ) @@ -22,7 +22,34 @@ > + {{ $group->name }} + +
+
+ @endforeach +
+
+ + +
+ +
+
+ @foreach ( $groups as $group ) +
+
+