-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Notifications for simple @-mentioning in comments #1449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e1073cf
522b053
006da9a
a35d4e7
a9671a4
1bcd2ca
70c7781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @author Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
| * | ||
| * @copyright Copyright (c) 2016, ownCloud, Inc. | ||
| * @license AGPL-3.0 | ||
| * | ||
| * This code is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License, version 3, | ||
| * as published by the Free Software Foundation. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License, version 3, | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/> | ||
| * | ||
| */ | ||
|
|
||
| use \OCA\Comments\AppInfo\Application; | ||
|
|
||
| $application = new Application(); | ||
| $application->registerRoutes($this, ['routes' => [ | ||
| ['name' => 'Notifications#view', 'url' => '/notifications/view/{id}', 'verb' => 'GET'], | ||
| ]]); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @author Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
| * | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done (this is for me, Github keeps showing me the dealt-with comments despite code changes, making it hard to track whats left…) |
||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
| * License as published by the Free Software Foundation; either | ||
| * version 3 of the License, or any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| namespace OCA\Comments\AppInfo; | ||
|
|
||
| use OCA\Comments\Controller\Notifications; | ||
| use OCP\AppFramework\App; | ||
|
|
||
| class Application extends App { | ||
|
|
||
| public function __construct (array $urlParams = array()) { | ||
| parent::__construct('comments', $urlParams); | ||
| $container = $this->getContainer(); | ||
|
|
||
| $container->registerAlias('NotificationsController', Notifications::class); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @author Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
| * | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing license
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This library is free software; you can redistribute it and/or | ||
| * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
| * License as published by the Free Software Foundation; either | ||
| * version 3 of the License, or any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public | ||
| * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Comments\Controller; | ||
|
|
||
| use OCP\AppFramework\Controller; | ||
| use OCP\AppFramework\Http\NotFoundResponse; | ||
| use OCP\AppFramework\Http\RedirectResponse; | ||
| use OCP\AppFramework\Http\Response; | ||
| use OCP\Comments\IComment; | ||
| use OCP\Comments\ICommentsManager; | ||
| use OCP\Files\Folder; | ||
| use OCP\IRequest; | ||
| use OCP\IURLGenerator; | ||
| use OCP\IUserSession; | ||
| use OCP\Notification\IManager; | ||
|
|
||
| /** | ||
| * Class Notifications | ||
| * | ||
| * @package OCA\Comments\Controller | ||
| */ | ||
| class Notifications extends Controller { | ||
| /** @var Folder */ | ||
| protected $folder; | ||
|
|
||
| /** @var ICommentsManager */ | ||
| protected $commentsManager; | ||
|
|
||
| /** @var IURLGenerator */ | ||
| protected $urlGenerator; | ||
|
|
||
| /** @var IManager */ | ||
| protected $notificationManager; | ||
|
|
||
| /** @var IUserSession */ | ||
| protected $userSession; | ||
|
|
||
| /** | ||
| * Notifications constructor. | ||
| * | ||
| * @param string $appName | ||
| * @param IRequest $request | ||
| * @param ICommentsManager $commentsManager | ||
| * @param Folder $folder | ||
| * @param IURLGenerator $urlGenerator | ||
| * @param IManager $notificationManager | ||
| * @param IUserSession $userSession | ||
| */ | ||
| public function __construct( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing docs
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| $appName, | ||
| IRequest $request, | ||
| ICommentsManager $commentsManager, | ||
| Folder $folder, | ||
| IURLGenerator $urlGenerator, | ||
| IManager $notificationManager, | ||
| IUserSession $userSession | ||
| ) { | ||
| parent::__construct($appName, $request); | ||
| $this->commentsManager = $commentsManager; | ||
| $this->folder = $folder; | ||
| $this->urlGenerator = $urlGenerator; | ||
| $this->notificationManager = $notificationManager; | ||
| $this->userSession = $userSession; | ||
| } | ||
|
|
||
| /** | ||
| * @NoAdminRequired | ||
| * @NoCSRFRequired | ||
| * | ||
| * @param string $id the comment ID | ||
| * @return Response | ||
| */ | ||
| public function view($id) { | ||
| try { | ||
| $comment = $this->commentsManager->get($id); | ||
| if($comment->getObjectType() !== 'files') { | ||
| return new NotFoundResponse(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as mentioned above, dispatch an event, so announcements can redirect to the given announcement
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now this should not be a problem anymore, because the code path is a result from a registered EventHandler. So, if a different app wants to work with Notifications, it will react upon any event, create the notification pointing to a controller of its own. Thus, to be considered done. |
||
| } | ||
| $files = $this->folder->getById($comment->getObjectId()); | ||
| if(count($files) === 0) { | ||
| $this->markProcessed($comment); | ||
| return new NotFoundResponse(); | ||
| } | ||
|
|
||
| $url = $this->urlGenerator->linkToRouteAbsolute( | ||
| 'files.viewcontroller.showFile', | ||
| [ 'fileid' => $comment->getObjectId() ] | ||
| ); | ||
|
|
||
| $this->markProcessed($comment); | ||
|
|
||
| return new RedirectResponse($url); | ||
| } catch (\Exception $e) { | ||
| return new NotFoundResponse(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Marks the notification about a comment as processed | ||
| * @param IComment $comment | ||
| */ | ||
| protected function markProcessed(IComment $comment) { | ||
| $user = $this->userSession->getUser(); | ||
| if(is_null($user)) { | ||
| return; | ||
| } | ||
| $notification = $this->notificationManager->createNotification(); | ||
| $notification->setApp('comments') | ||
| ->setObject('comment', $comment->getId()) | ||
| ->setSubject('mention') | ||
| ->setUser($user->getUID()); | ||
| $this->notificationManager->markProcessed($notification); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
| * | ||
| * @author Arthur Schiwon <blizzz@arthur-schiwon.de> | ||
| * | ||
| * @license GNU AGPL version 3 or any later version | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| namespace OCA\Comments; | ||
|
|
||
| use OCA\Comments\Activity\Listener as ActivityListener; | ||
| use OCA\Comments\AppInfo\Application; | ||
| use OCA\Comments\Notification\Listener as NotificationListener; | ||
| use OCP\Comments\CommentsEvent; | ||
| use OCP\Comments\ICommentsEventHandler; | ||
|
|
||
| /** | ||
| * Class EventHandler | ||
| * | ||
| * @package OCA\Comments | ||
| */ | ||
| class EventHandler implements ICommentsEventHandler { | ||
| /** @var ActivityListener */ | ||
| private $activityListener; | ||
|
|
||
| /** @var NotificationListener */ | ||
| private $notificationListener; | ||
|
|
||
| public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) { | ||
| $this->activityListener = $activityListener; | ||
| $this->notificationListener = $notificationListener; | ||
| } | ||
|
|
||
| /** | ||
| * @param CommentsEvent $event | ||
| */ | ||
| public function handle(CommentsEvent $event) { | ||
| if($event->getComment()->getObjectType() !== 'files') { | ||
| // this is a 'files'-specific Handler | ||
| return; | ||
| } | ||
|
|
||
| $eventType = $event->getEvent(); | ||
| if( $eventType === CommentsEvent::EVENT_ADD | ||
| ) { | ||
| $this->notificationHandler($event); | ||
| $this->activityHandler($event); | ||
| return; | ||
| } | ||
|
|
||
| $applicableEvents = [ | ||
| CommentsEvent::EVENT_PRE_UPDATE, | ||
| CommentsEvent::EVENT_UPDATE, | ||
| CommentsEvent::EVENT_DELETE, | ||
| ]; | ||
| if(in_array($eventType, $applicableEvents)) { | ||
| $this->notificationHandler($event); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param CommentsEvent $event | ||
| */ | ||
| private function activityHandler(CommentsEvent $event) { | ||
| $this->activityListener->commentEvent($event); | ||
| } | ||
|
|
||
| /** | ||
| * @param CommentsEvent $event | ||
| */ | ||
| private function notificationHandler(CommentsEvent $event) { | ||
| $this->notificationListener->evaluate($event); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please include the type in the url and dispatch an event on the endpoint.
Comments are already used by other apps, which would like to redirect to other parts then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ID is a unique comment ID, not coupled to Actor or Object type. And the URL is still within apps/comments/. Still an issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm should be fine then I guess