diff --git a/include/class.thread.php b/include/class.thread.php index 58ac294fe4b22f591c303830a828148885da26ae..7069808d354bcbc2111a940079c014edd7c1681a 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -1505,8 +1505,18 @@ implements TemplateVariable { )); //add recipients to thread entry - if ($vars['thread_entry_recipients']) + if ($vars['thread_entry_recipients']) { + $count = 0; + foreach ($vars['thread_entry_recipients'] as $key => $value) + $count = $count + count($value); + + if ($count > 1) + $entry->flags |= ThreadEntry::FLAG_REPLY_ALL; + else + $entry->flags |= ThreadEntry::FLAG_REPLY_USER; + $entry->recipients = json_encode($vars['thread_entry_recipients']); + } if (Collaborator::getIdByUserId($vars['userId'], $vars['threadId'])) @@ -2063,12 +2073,15 @@ class ThreadEvents extends InstrumentedList { function log($object, $state, $data=null, $user=null, $annul=null) { global $thisstaff, $thisclient; - if ($object instanceof Ticket) + if ($object && ($object instanceof Ticket)) // TODO: Use $object->createEvent() (nolint) $event = ThreadEvent::forTicket($object, $state, $user); - elseif ($object instanceof Task) + elseif ($object && ($object instanceof Task)) $event = ThreadEvent::forTask($object, $state, $user); + if (is_null($event)) + return; + # Annul previous entries if requested (for instance, reopening a # ticket will annul an 'closed' entry). This will be useful to # easily prevent repeated statistics. @@ -2867,14 +2880,6 @@ implements TemplateVariable { $vars['pid'] = $message->getId(); $vars['flags'] = 0; - switch ($vars['reply-to']) { - case 'all': - $vars['flags'] |= ThreadEntry::FLAG_REPLY_ALL; - break; - case 'user': - $vars['flags'] |= ThreadEntry::FLAG_REPLY_USER; - break; - } if (!($resp = ResponseThreadEntry::add($vars, $errors))) return $resp; diff --git a/include/class.ticket.php b/include/class.ticket.php index 615931fa0bca9a134e6ac543ee21651ce55c69dd..c45c00b67c16fa6b251ec1d21139f8ced6b16ee9 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2667,6 +2667,26 @@ implements RestrictedAccess, Threadable, Searchable { if ($vars['userId'] == $this->user_id) $isMsg = true; + // Get active recipients of the response + // Initial Message from Tickets created by Agent + if ($vars['reply-to']) + $recipients = $this->getRecipients($vars['reply-to'], $vars['ccs']); + // Messages from Web Portal + elseif (strcasecmp($origin, 'email')) { + $recipients = $this->getRecipients('all'); + foreach ($recipients as $key => $recipient) { + if (!$recipientContact = $recipient->getContact()); + continue; + + $userId = $recipientContact->getUserId() ?: $recipientContact->getId(); + // Do not list the poster as a recipient + if ($userId == $vars['userId']) + unset($recipients[$key]); + } + } + if ($recipients && $recipients instanceof MailingList) + $vars['thread_entry_recipients'] = $recipients->getEmailAddresses(); + if (!($message = $this->getThread()->addMessage($vars, $errors))) return null; @@ -2723,7 +2743,9 @@ implements RestrictedAccess, Threadable, Searchable { $this->onMessage($message, ($autorespond && $alerts), $reopen); //must be called b4 sending alerts to staff. - if ($autorespond && $alerts && $cfg && $cfg->notifyCollabsONNewMessage()) { + if ($autorespond && $alerts + && $cfg && $cfg->notifyCollabsONNewMessage() + && strcasecmp($origin, 'email')) { //when user replies, this is where collabs notified $this->notifyCollaborators($message, array('signature' => '')); } @@ -3821,6 +3843,10 @@ implements RestrictedAccess, Threadable, Searchable { // Start tracking ticket lifecycle events (created should come first!) $ticket->logEvent('created', null, $thisstaff ?: $user); + // Add collaborators (if any) + if (isset($vars['ccs']) && count($vars['ccs'])) + $ticket->addCollaborators($vars['ccs'], array(), $errors); + // Add organizational collaborators if ($org && $org->autoAddCollabs()) { $pris = $org->autoAddPrimaryContactsAsCollabs(); @@ -4044,10 +4070,6 @@ implements RestrictedAccess, Threadable, Searchable { // Effective role for the department $role = $ticket->getRole($thisstaff); - // Add collaborators (if any) - if (isset($vars['ccs']) && count($vars['ccs'])) - $ticket->addCollaborators($vars['ccs'], array(), $errors); - $alert = strcasecmp('none', $vars['reply-to']); // post response - if any $response = null;