From 598dedc825c91c61e1e01e9f96084850b5d9f7bf Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Fri, 14 Aug 2015 13:09:30 -0500 Subject: [PATCH] autoresponse: Deadband autoresponses to five minutes Only send one autoresponse to the same user for new messages sent in a five minute window per thread. This will stop looping because of bounces and OoO notifications not flagged as autoreplies --- include/class.orm.php | 5 +++++ include/class.thread.php | 12 +++++++----- include/class.ticket.php | 11 +++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/class.orm.php b/include/class.orm.php index f961d3944..7246dc1b1 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -689,6 +689,11 @@ class SqlFunction { $I->args = $args; return $I; } + + function __call($operator, $other) { + array_unshift($other, $this); + return SqlExpression::__callStatic($operator, $other); + } } class SqlCase extends SqlFunction { diff --git a/include/class.thread.php b/include/class.thread.php index 7e94e08d7..78ba7818b 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -2410,12 +2410,14 @@ implements TemplateVariable { )); } - function getLastMessage() { - return $this->entries->filter(array( + function getLastMessage($criteria=false) { + $entries = $this->entries->filter(array( 'type' => MessageThreadEntry::ENTRY_TYPE - )) - ->order_by('-id') - ->first(); + )); + if ($criteria) + $entries->filter($criteria); + + return $entries->order_by('-id')->first(); } function getEntry($var) { diff --git a/include/class.ticket.php b/include/class.ticket.php index d2a85ae8c..dc9651775 100644 --- a/include/class.ticket.php +++ b/include/class.ticket.php @@ -2212,6 +2212,17 @@ implements RestrictedAccess, Threadable { } } + // Find the last message from this user on this thread + if ($this->getThread()->getLastMessage(array( + 'user_id' => $message->user_id, + 'id__lt' => $message->id, + 'created__gt' => SqlFunction::NOW()->minus(SqlInterval::MINUTE(5)), + ))) { + // One message already from this user in the last five minutes + $alerts = false; + } + + if (!$alerts) return $message; //Our work is done... -- GitLab