summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Core/Base.php2
-rw-r--r--app/Core/Markdown.php2
-rw-r--r--app/Event/GenericEvent.php22
-rw-r--r--app/Event/ProjectFileEvent.php8
-rw-r--r--app/Job/CommentEventJob.php4
-rw-r--r--app/Job/TaskEventJob.php3
-rw-r--r--app/Job/UserMentionJob.php71
-rw-r--r--app/Model/UserMentionModel.php62
-rw-r--r--app/ServiceProvider/ClassProvider.php1
-rw-r--r--app/ServiceProvider/JobProvider.php5
-rw-r--r--app/Subscriber/NotificationSubscriber.php38
11 files changed, 131 insertions, 87 deletions
diff --git a/app/Core/Base.php b/app/Core/Base.php
index 3dbf47f9..e7ccafaa 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -126,7 +126,6 @@ use Pimple\Container;
* @property \Kanboard\Model\TransitionModel $transitionModel
* @property \Kanboard\Model\UserModel $userModel
* @property \Kanboard\Model\UserLockingModel $userLockingModel
- * @property \Kanboard\Model\UserMentionModel $userMentionModel
* @property \Kanboard\Model\UserNotificationModel $userNotificationModel
* @property \Kanboard\Model\UserNotificationTypeModel $userNotificationTypeModel
* @property \Kanboard\Model\UserNotificationFilterModel $userNotificationFilterModel
@@ -178,6 +177,7 @@ use Pimple\Container;
* @property \Kanboard\Job\ProjectFileEventJob $projectFileEventJob
* @property \Kanboard\Job\NotificationJob $notificationJob
* @property \Kanboard\Job\ProjectMetricJob $projectMetricJob
+ * @property \Kanboard\Job\UserMentionJob $userMentionJob
* @property \Psr\Log\LoggerInterface $logger
* @property \PicoDb\Database $db
* @property \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
diff --git a/app/Core/Markdown.php b/app/Core/Markdown.php
index b83a3ced..b4208e9a 100644
--- a/app/Core/Markdown.php
+++ b/app/Core/Markdown.php
@@ -90,7 +90,7 @@ class Markdown extends Parsedown
$user_id = $this->container['userModel']->getIdByUsername($matches[1]);
if (! empty($user_id)) {
- $url = $this->container['helper']->url->href('UserViewController', 'profile', array('user_id' => $user_id));
+ $url = $this->container['helper']->url->href('UserViewController', 'profile', array('user_id' => $user_id), false, '', true);
return array(
'extent' => strlen($matches[0]),
diff --git a/app/Event/GenericEvent.php b/app/Event/GenericEvent.php
index 94a51479..e87d9481 100644
--- a/app/Event/GenericEvent.php
+++ b/app/Event/GenericEvent.php
@@ -14,6 +14,28 @@ class GenericEvent extends BaseEvent implements ArrayAccess
$this->container = $values;
}
+ public function getTaskId()
+ {
+ if (isset($this->container['task']['id'])) {
+ return $this->container['task']['id'];
+ }
+
+ if (isset($this->container['task_id'])) {
+ return $this->container['task_id'];
+ }
+
+ return null;
+ }
+
+ public function getProjectId()
+ {
+ if (isset($this->container['task']['project_id'])) {
+ return $this->container['task']['project_id'];
+ }
+
+ return null;
+ }
+
public function getAll()
{
return $this->container;
diff --git a/app/Event/ProjectFileEvent.php b/app/Event/ProjectFileEvent.php
index 5d57e463..e1d29c48 100644
--- a/app/Event/ProjectFileEvent.php
+++ b/app/Event/ProjectFileEvent.php
@@ -4,4 +4,12 @@ namespace Kanboard\Event;
class ProjectFileEvent extends GenericEvent
{
+ public function getProjectId()
+ {
+ if (isset($this->container['file']['project_id'])) {
+ return $this->container['file']['project_id'];
+ }
+
+ return null;
+ }
}
diff --git a/app/Job/CommentEventJob.php b/app/Job/CommentEventJob.php
index 47cf8020..62fae40a 100644
--- a/app/Job/CommentEventJob.php
+++ b/app/Job/CommentEventJob.php
@@ -31,7 +31,6 @@ class CommentEventJob extends BaseJob
*
* @param int $commentId
* @param string $eventName
- * @return $this
*/
public function execute($commentId, $eventName)
{
@@ -43,7 +42,8 @@ class CommentEventJob extends BaseJob
$this->dispatcher->dispatch($eventName, $event);
if ($eventName === CommentModel::EVENT_CREATE) {
- $this->userMentionModel->fireEvents($event['comment']['comment'], CommentModel::EVENT_USER_MENTION, $event);
+ $userMentionJob = $this->userMentionJob->withParams($event['comment']['comment'], CommentModel::EVENT_USER_MENTION, $event);
+ $this->queueManager->push($userMentionJob);
}
}
}
diff --git a/app/Job/TaskEventJob.php b/app/Job/TaskEventJob.php
index 7d026a68..acc7fca3 100644
--- a/app/Job/TaskEventJob.php
+++ b/app/Job/TaskEventJob.php
@@ -69,7 +69,8 @@ class TaskEventJob extends BaseJob
$this->dispatcher->dispatch($eventName, $event);
if ($eventName === TaskModel::EVENT_CREATE) {
- $this->userMentionModel->fireEvents($event['task']['description'], TaskModel::EVENT_USER_MENTION, $event);
+ $userMentionJob = $this->userMentionJob->withParams($event['task']['description'], TaskModel::EVENT_USER_MENTION, $event);
+ $this->queueManager->push($userMentionJob);
}
}
}
diff --git a/app/Job/UserMentionJob.php b/app/Job/UserMentionJob.php
new file mode 100644
index 00000000..ebb69094
--- /dev/null
+++ b/app/Job/UserMentionJob.php
@@ -0,0 +1,71 @@
+<?php
+
+namespace Kanboard\Job;
+
+use Kanboard\Event\GenericEvent;
+use Kanboard\Model\UserModel;
+
+/**
+ * Class UserMentionJob
+ *
+ * @package Kanboard\Job
+ * @author Frederic Guillot
+ */
+class UserMentionJob extends BaseJob
+{
+ /**
+ * Set job parameters
+ *
+ * @param string $text
+ * @param string $eventName
+ * @param GenericEvent $event
+ * @return $this
+ */
+ public function withParams($text, $eventName, GenericEvent $event)
+ {
+ $this->jobParams = array($text, $eventName, $event);
+ return $this;
+ }
+
+ /**
+ * Execute job
+ *
+ * @param string $text
+ * @param string $eventName
+ * @param GenericEvent $event
+ */
+ public function execute($text, $eventName, GenericEvent $event)
+ {
+ $users = $this->getMentionedUsers($text);
+
+ foreach ($users as $user) {
+ if ($this->projectPermissionModel->isMember($event->getProjectId(), $user['id'])) {
+ $event['mention'] = $user;
+ $this->dispatcher->dispatch($eventName, $event);
+ }
+ }
+ }
+
+ /**
+ * Get list of mentioned users
+ *
+ * @access public
+ * @param string $text
+ * @return array
+ */
+ public function getMentionedUsers($text)
+ {
+ $users = array();
+
+ if (preg_match_all('/@([^\s,!.:?]+)/', $text, $matches)) {
+ $users = $this->db->table(UserModel::TABLE)
+ ->columns('id', 'username', 'name', 'email', 'language')
+ ->eq('notifications_enabled', 1)
+ ->neq('id', $this->userSession->getId())
+ ->in('username', array_unique($matches[1]))
+ ->findAll();
+ }
+
+ return $users;
+ }
+}
diff --git a/app/Model/UserMentionModel.php b/app/Model/UserMentionModel.php
deleted file mode 100644
index cdb9949e..00000000
--- a/app/Model/UserMentionModel.php
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-
-namespace Kanboard\Model;
-
-use Kanboard\Core\Base;
-use Kanboard\Event\GenericEvent;
-
-/**
- * User Mention
- *
- * @package Kanboard\Model
- * @author Frederic Guillot
- */
-class UserMentionModel extends Base
-{
- /**
- * Get list of mentioned users
- *
- * @access public
- * @param string $content
- * @return array
- */
- public function getMentionedUsers($content)
- {
- $users = array();
-
- if (preg_match_all('/@([^\s]+)/', $content, $matches)) {
- $users = $this->db->table(UserModel::TABLE)
- ->columns('id', 'username', 'name', 'email', 'language')
- ->eq('notifications_enabled', 1)
- ->neq('id', $this->userSession->getId())
- ->in('username', array_unique($matches[1]))
- ->findAll();
- }
-
- return $users;
- }
-
- /**
- * Fire events for user mentions
- *
- * @access public
- * @param string $content
- * @param string $eventName
- * @param GenericEvent $event
- */
- public function fireEvents($content, $eventName, GenericEvent $event)
- {
- if (empty($event['project_id'])) {
- $event['project_id'] = $this->taskFinderModel->getProjectId($event['task_id']);
- }
-
- $users = $this->getMentionedUsers($content);
-
- foreach ($users as $user) {
- if ($this->projectPermissionModel->isMember($event['project_id'], $user['id'])) {
- $event['mention'] = $user;
- $this->dispatcher->dispatch($eventName, $event);
- }
- }
- }
-}
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index c5bf0678..8d471b79 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -91,7 +91,6 @@ class ClassProvider implements ServiceProviderInterface
'TransitionModel',
'UserModel',
'UserLockingModel',
- 'UserMentionModel',
'UserNotificationModel',
'UserNotificationFilterModel',
'UserUnreadNotificationModel',
diff --git a/app/ServiceProvider/JobProvider.php b/app/ServiceProvider/JobProvider.php
index 2194b11c..4e5e0f1a 100644
--- a/app/ServiceProvider/JobProvider.php
+++ b/app/ServiceProvider/JobProvider.php
@@ -10,6 +10,7 @@ use Kanboard\Job\SubtaskEventJob;
use Kanboard\Job\TaskEventJob;
use Kanboard\Job\TaskFileEventJob;
use Kanboard\Job\TaskLinkEventJob;
+use Kanboard\Job\UserMentionJob;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
@@ -62,6 +63,10 @@ class JobProvider implements ServiceProviderInterface
return new ProjectMetricJob($c);
});
+ $container['userMentionJob'] = $container->factory(function ($c) {
+ return new UserMentionJob($c);
+ });
+
return $container;
}
}
diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php
index 7cc68b26..ad16685b 100644
--- a/app/Subscriber/NotificationSubscriber.php
+++ b/app/Subscriber/NotificationSubscriber.php
@@ -15,25 +15,25 @@ class NotificationSubscriber extends BaseSubscriber implements EventSubscriberIn
public static function getSubscribedEvents()
{
return array(
- TaskModel::EVENT_USER_MENTION => 'handleEvent',
- TaskModel::EVENT_CREATE => 'handleEvent',
- TaskModel::EVENT_UPDATE => 'handleEvent',
- TaskModel::EVENT_CLOSE => 'handleEvent',
- TaskModel::EVENT_OPEN => 'handleEvent',
- TaskModel::EVENT_MOVE_COLUMN => 'handleEvent',
- TaskModel::EVENT_MOVE_POSITION => 'handleEvent',
- TaskModel::EVENT_MOVE_SWIMLANE => 'handleEvent',
- TaskModel::EVENT_ASSIGNEE_CHANGE => 'handleEvent',
- SubtaskModel::EVENT_CREATE => 'handleEvent',
- SubtaskModel::EVENT_UPDATE => 'handleEvent',
- SubtaskModel::EVENT_DELETE => 'handleEvent',
- CommentModel::EVENT_CREATE => 'handleEvent',
- CommentModel::EVENT_UPDATE => 'handleEvent',
- CommentModel::EVENT_DELETE => 'handleEvent',
- CommentModel::EVENT_USER_MENTION => 'handleEvent',
- TaskFileModel::EVENT_CREATE => 'handleEvent',
- TaskLinkModel::EVENT_CREATE_UPDATE => 'handleEvent',
- TaskLinkModel::EVENT_DELETE => 'handleEvent',
+ TaskModel::EVENT_USER_MENTION => 'handleEvent',
+ TaskModel::EVENT_CREATE => 'handleEvent',
+ TaskModel::EVENT_UPDATE => 'handleEvent',
+ TaskModel::EVENT_CLOSE => 'handleEvent',
+ TaskModel::EVENT_OPEN => 'handleEvent',
+ TaskModel::EVENT_MOVE_COLUMN => 'handleEvent',
+ TaskModel::EVENT_MOVE_POSITION => 'handleEvent',
+ TaskModel::EVENT_MOVE_SWIMLANE => 'handleEvent',
+ TaskModel::EVENT_ASSIGNEE_CHANGE => 'handleEvent',
+ SubtaskModel::EVENT_CREATE => 'handleEvent',
+ SubtaskModel::EVENT_UPDATE => 'handleEvent',
+ SubtaskModel::EVENT_DELETE => 'handleEvent',
+ CommentModel::EVENT_CREATE => 'handleEvent',
+ CommentModel::EVENT_UPDATE => 'handleEvent',
+ CommentModel::EVENT_DELETE => 'handleEvent',
+ CommentModel::EVENT_USER_MENTION => 'handleEvent',
+ TaskFileModel::EVENT_CREATE => 'handleEvent',
+ TaskLinkModel::EVENT_CREATE_UPDATE => 'handleEvent',
+ TaskLinkModel::EVENT_DELETE => 'handleEvent',
);
}