diff options
Diffstat (limited to 'apps/comments')
-rw-r--r-- | apps/comments/lib/AppInfo/Application.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Collaboration/CommentersSorter.php | 12 | ||||
-rw-r--r-- | apps/comments/lib/Controller/Notifications.php | 2 | ||||
-rw-r--r-- | apps/comments/lib/EventHandler.php | 6 | ||||
-rw-r--r-- | apps/comments/lib/Listener/LoadAdditionalScripts.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Listener/LoadSidebarScripts.php | 1 | ||||
-rw-r--r-- | apps/comments/lib/Notification/Listener.php | 18 | ||||
-rw-r--r-- | apps/comments/lib/Notification/Notifier.php | 8 | ||||
-rw-r--r-- | apps/comments/lib/Search/Result.php | 2 | ||||
-rw-r--r-- | apps/comments/tests/Unit/AppInfo/ApplicationTest.php | 2 | ||||
-rw-r--r-- | apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php | 4 | ||||
-rw-r--r-- | apps/comments/tests/Unit/EventHandlerTest.php | 1 | ||||
-rw-r--r-- | apps/comments/tests/Unit/Notification/NotifierTest.php | 1 |
13 files changed, 25 insertions, 34 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php index a4c01f3f620..9168948d7c8 100644 --- a/apps/comments/lib/AppInfo/Application.php +++ b/apps/comments/lib/AppInfo/Application.php @@ -42,7 +42,6 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\Util; class Application extends App { - const APP_ID = 'comments'; public function __construct(array $urlParams = []) { diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php index 0db043f918b..80f263acb0c 100644 --- a/apps/comments/lib/Collaboration/CommentersSorter.php +++ b/apps/comments/lib/Collaboration/CommentersSorter.php @@ -48,12 +48,12 @@ class CommentersSorter implements ISorter { */ public function sort(array &$sortArray, array $context) { $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); - if(count($commenters) === 0) { + if (count($commenters) === 0) { return; } foreach ($sortArray as $type => &$byType) { - if(!isset($commenters[$type])) { + if (!isset($commenters[$type])) { continue; } @@ -66,7 +66,7 @@ class CommentersSorter implements ISorter { usort($workArray, function ($a, $b) use ($commenters, $type) { $r = $this->compare($a[1], $b[1], $commenters[$type]); - if($r === 0) { + if ($r === 0) { $r = $a[0] - $b[0]; } return $r; @@ -84,16 +84,16 @@ class CommentersSorter implements ISorter { */ protected function retrieveCommentsInformation($type, $id) { $comments = $this->commentsManager->getForObject($type, $id); - if(count($comments) === 0) { + if (count($comments) === 0) { return []; } $actors = []; foreach ($comments as $comment) { - if(!isset($actors[$comment->getActorType()])) { + if (!isset($actors[$comment->getActorType()])) { $actors[$comment->getActorType()] = []; } - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { + if (!isset($actors[$comment->getActorType()][$comment->getActorId()])) { $actors[$comment->getActorType()][$comment->getActorId()] = 1; } else { $actors[$comment->getActorType()][$comment->getActorId()]++; diff --git a/apps/comments/lib/Controller/Notifications.php b/apps/comments/lib/Controller/Notifications.php index 6610b56b689..030a221a03c 100644 --- a/apps/comments/lib/Controller/Notifications.php +++ b/apps/comments/lib/Controller/Notifications.php @@ -108,7 +108,7 @@ class Notifications extends Controller { try { $comment = $this->commentsManager->get($id); - if($comment->getObjectType() !== 'files') { + if ($comment->getObjectType() !== 'files') { return new NotFoundResponse(); } $userFolder = $this->rootFolder->getUserFolder($currentUser->getUID()); diff --git a/apps/comments/lib/EventHandler.php b/apps/comments/lib/EventHandler.php index 4364550a222..3d78ad43129 100644 --- a/apps/comments/lib/EventHandler.php +++ b/apps/comments/lib/EventHandler.php @@ -49,13 +49,13 @@ class EventHandler implements ICommentsEventHandler { * @param CommentsEvent $event */ public function handle(CommentsEvent $event) { - if($event->getComment()->getObjectType() !== 'files') { + if ($event->getComment()->getObjectType() !== 'files') { // this is a 'files'-specific Handler return; } $eventType = $event->getEvent(); - if($eventType === CommentsEvent::EVENT_ADD + if ($eventType === CommentsEvent::EVENT_ADD ) { $this->notificationHandler($event); $this->activityHandler($event); @@ -67,7 +67,7 @@ class EventHandler implements ICommentsEventHandler { CommentsEvent::EVENT_UPDATE, CommentsEvent::EVENT_DELETE, ]; - if(in_array($eventType, $applicableEvents)) { + if (in_array($eventType, $applicableEvents)) { $this->notificationHandler($event); return; } diff --git a/apps/comments/lib/Listener/LoadAdditionalScripts.php b/apps/comments/lib/Listener/LoadAdditionalScripts.php index ddaf288394b..2ab67a45ab5 100644 --- a/apps/comments/lib/Listener/LoadAdditionalScripts.php +++ b/apps/comments/lib/Listener/LoadAdditionalScripts.php @@ -43,5 +43,4 @@ class LoadAdditionalScripts implements IEventListener { // we properly split it between files list and sidebar Util::addScript(Application::APP_ID, 'comments'); } - } diff --git a/apps/comments/lib/Listener/LoadSidebarScripts.php b/apps/comments/lib/Listener/LoadSidebarScripts.php index 209c62dc406..29d1f2eb394 100644 --- a/apps/comments/lib/Listener/LoadSidebarScripts.php +++ b/apps/comments/lib/Listener/LoadSidebarScripts.php @@ -42,5 +42,4 @@ class LoadSidebarScripts implements IEventListener { // we properly split it between files list and sidebar Util::addScript(Application::APP_ID, 'comments'); } - } diff --git a/apps/comments/lib/Notification/Listener.php b/apps/comments/lib/Notification/Listener.php index ba645ac5779..f157dd4cd31 100644 --- a/apps/comments/lib/Notification/Listener.php +++ b/apps/comments/lib/Notification/Listener.php @@ -45,7 +45,6 @@ class Listener { IManager $notificationManager, IUserManager $userManager ) { - $this->notificationManager = $notificationManager; $this->userManager = $userManager; } @@ -57,15 +56,15 @@ class Listener { $comment = $event->getComment(); $mentions = $this->extractMentions($comment->getMentions()); - if(empty($mentions)) { + if (empty($mentions)) { // no one to notify return; } $notification = $this->instantiateNotification($comment); - foreach($mentions as $uid) { - if(($comment->getActorType() === 'users' && $uid === $comment->getActorId()) + foreach ($mentions as $uid) { + if (($comment->getActorType() === 'users' && $uid === $comment->getActorId()) || !$this->userManager->userExists($uid) ) { // do not notify unknown users or yourself @@ -73,9 +72,8 @@ class Listener { } $notification->setUser($uid); - if($event->getEvent() === CommentsEvent::EVENT_DELETE - || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) - { + if ($event->getEvent() === CommentsEvent::EVENT_DELETE + || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) { $this->notificationManager->markProcessed($notification); } else { $this->notificationManager->notify($notification); @@ -107,12 +105,12 @@ class Listener { * @return string[] containing the mentions, e.g. ['alice', 'bob'] */ public function extractMentions(array $mentions) { - if(empty($mentions)) { + if (empty($mentions)) { return []; } $uids = []; - foreach($mentions as $mention) { - if($mention['type'] === 'user') { + foreach ($mentions as $mention) { + if ($mention['type'] === 'user') { $uids[] = $mention['id']; } } diff --git a/apps/comments/lib/Notification/Notifier.php b/apps/comments/lib/Notification/Notifier.php index 3b502c0c504..01a003eb8dc 100644 --- a/apps/comments/lib/Notification/Notifier.php +++ b/apps/comments/lib/Notification/Notifier.php @@ -96,12 +96,12 @@ class Notifier implements INotifier { * @since 9.0.0 */ public function prepare(INotification $notification, string $languageCode): INotification { - if($notification->getApp() !== 'comments') { + if ($notification->getApp() !== 'comments') { throw new \InvalidArgumentException(); } try { $comment = $this->commentsManager->get($notification->getObjectId()); - } catch(NotFoundException $e) { + } catch (NotFoundException $e) { // needs to be converted to InvalidArgumentException, otherwise none Notifications will be shown at all throw new \InvalidArgumentException('Comment not found', 0, $e); } @@ -118,12 +118,12 @@ class Notifier implements INotifier { switch ($notification->getSubject()) { case 'mention': $parameters = $notification->getSubjectParameters(); - if($parameters[0] !== 'files') { + if ($parameters[0] !== 'files') { throw new \InvalidArgumentException('Unsupported comment object'); } $userFolder = $this->rootFolder->getUserFolder($notification->getUser()); $nodes = $userFolder->getById((int)$parameters[1]); - if(empty($nodes)) { + if (empty($nodes)) { throw new AlreadyProcessedException(); } $node = $nodes[0]; diff --git a/apps/comments/lib/Search/Result.php b/apps/comments/lib/Search/Result.php index 36b0303fc4e..9f0e6936320 100644 --- a/apps/comments/lib/Search/Result.php +++ b/apps/comments/lib/Search/Result.php @@ -29,7 +29,6 @@ use OCP\Files\NotFoundException; use OCP\Search\Result as BaseResult; class Result extends BaseResult { - public $type = 'comment'; public $comment; public $authorId; @@ -108,5 +107,4 @@ class Result extends BaseResult { return $prefix . mb_substr($message, $start, $end - $start) . $suffix; } - } diff --git a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php index d6dd02da24f..dcf17896e49 100644 --- a/apps/comments/tests/Unit/AppInfo/ApplicationTest.php +++ b/apps/comments/tests/Unit/AppInfo/ApplicationTest.php @@ -64,7 +64,7 @@ class ApplicationTest extends TestCase { Notifier::class, ]; - foreach($services as $service) { + foreach ($services as $service) { $s = $c->query($service); $this->assertInstanceOf($service, $s); } diff --git a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php index 82df3dce5e0..f94d935e773 100644 --- a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php +++ b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php @@ -49,9 +49,9 @@ class CommentersSorterTest extends TestCase { */ public function testSort($data) { $commentMocks = []; - foreach($data['actors'] as $actorType => $actors) { + foreach ($data['actors'] as $actorType => $actors) { foreach ($actors as $actorId => $noOfComments) { - for($i=0;$i<$noOfComments;$i++) { + for ($i=0;$i<$noOfComments;$i++) { $mock = $this->createMock(IComment::class); $mock->expects($this->atLeastOnce()) ->method('getActorType') diff --git a/apps/comments/tests/Unit/EventHandlerTest.php b/apps/comments/tests/Unit/EventHandlerTest.php index 3dd5d3d68a2..bb1d660af1e 100644 --- a/apps/comments/tests/Unit/EventHandlerTest.php +++ b/apps/comments/tests/Unit/EventHandlerTest.php @@ -116,5 +116,4 @@ class EventHandlerTest extends TestCase { $this->eventHandler->handle($event); } - } diff --git a/apps/comments/tests/Unit/Notification/NotifierTest.php b/apps/comments/tests/Unit/Notification/NotifierTest.php index 390624c2c85..dbb79176320 100644 --- a/apps/comments/tests/Unit/Notification/NotifierTest.php +++ b/apps/comments/tests/Unit/Notification/NotifierTest.php @@ -616,5 +616,4 @@ class NotifierTest extends TestCase { $this->notifier->prepare($this->notification, $this->lc); } - } |