diff --git a/include/class.orm.php b/include/class.orm.php index f961d39440dcbdc57db64f522a38db867969e9ad..7246dc1b1911a26b83dd0c1de161d21310f0fbc4 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 7e94e08d794274e2d49bbeb63f3213626743c44b..78ba7818b4af3e6589a9a71c10f8b5fb9e2030d1 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 d2a85ae8c3eb0b621386e70f3e58e12c7852aabb..dc9651775c4df11589b56ecc986d9ea1c930aa6b 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...