2016-05-09 08:02:07 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2017-11-06 14:56:42 +00:00
|
|
|
*
|
|
|
|
*
|
2016-05-09 08:02:07 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-05-09 08:02:07 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* 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.
|
2016-05-09 08:02:07 +00:00
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2016-05-09 08:02:07 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-11-06 14:56:42 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2016-05-09 08:02:07 +00:00
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* 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/>.
|
2016-05-09 08:02:07 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2018-09-12 09:23:38 +00:00
|
|
|
use OCP\Files\IRootFolder;
|
2016-05-09 08:02:07 +00:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IURLGenerator;
|
2018-09-12 09:23:38 +00:00
|
|
|
use OCP\IUser;
|
2016-05-09 08:02:07 +00:00
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\Notification\IManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Notifications
|
|
|
|
*
|
|
|
|
* @package OCA\Comments\Controller
|
|
|
|
*/
|
|
|
|
class Notifications extends Controller {
|
2018-09-12 09:23:38 +00:00
|
|
|
/** @var IRootFolder */
|
|
|
|
protected $rootFolder;
|
2016-05-09 08:02:07 +00:00
|
|
|
|
|
|
|
/** @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
|
2018-09-12 09:23:38 +00:00
|
|
|
* @param IRootFolder $rootFolder
|
2016-05-09 08:02:07 +00:00
|
|
|
* @param IURLGenerator $urlGenerator
|
|
|
|
* @param IManager $notificationManager
|
|
|
|
* @param IUserSession $userSession
|
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
|
|
|
ICommentsManager $commentsManager,
|
2018-09-12 09:23:38 +00:00
|
|
|
IRootFolder $rootFolder,
|
2016-05-09 08:02:07 +00:00
|
|
|
IURLGenerator $urlGenerator,
|
|
|
|
IManager $notificationManager,
|
|
|
|
IUserSession $userSession
|
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->commentsManager = $commentsManager;
|
2018-09-12 09:23:38 +00:00
|
|
|
$this->rootFolder = $rootFolder;
|
2016-05-09 08:02:07 +00:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
|
|
|
$this->notificationManager = $notificationManager;
|
|
|
|
$this->userSession = $userSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-12 09:23:38 +00:00
|
|
|
* @PublicPage
|
2016-05-09 08:02:07 +00:00
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param string $id the comment ID
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function view($id) {
|
2018-09-12 09:23:38 +00:00
|
|
|
$currentUser = $this->userSession->getUser();
|
|
|
|
if (!$currentUser instanceof IUser) {
|
|
|
|
return new RedirectResponse(
|
|
|
|
$this->urlGenerator->linkToRoute('core.login.showLoginForm', [
|
|
|
|
'redirect_url' => $this->urlGenerator->linkToRoute(
|
|
|
|
'comments.Notifications.view',
|
|
|
|
['id' => $id]
|
|
|
|
),
|
|
|
|
])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-09 08:02:07 +00:00
|
|
|
try {
|
|
|
|
$comment = $this->commentsManager->get($id);
|
|
|
|
if($comment->getObjectType() !== 'files') {
|
|
|
|
return new NotFoundResponse();
|
|
|
|
}
|
2018-09-12 09:23:38 +00:00
|
|
|
$userFolder = $this->rootFolder->getUserFolder($currentUser->getUID());
|
|
|
|
$files = $userFolder->getById((int)$comment->getObjectId());
|
|
|
|
|
|
|
|
$this->markProcessed($comment, $currentUser);
|
|
|
|
|
|
|
|
if (empty($files)) {
|
2016-05-09 08:02:07 +00:00
|
|
|
return new NotFoundResponse();
|
|
|
|
}
|
|
|
|
|
|
|
|
$url = $this->urlGenerator->linkToRouteAbsolute(
|
2016-10-07 15:27:33 +00:00
|
|
|
'files.viewcontroller.showFile',
|
|
|
|
[ 'fileid' => $comment->getObjectId() ]
|
2016-05-09 08:02:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return new RedirectResponse($url);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return new NotFoundResponse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the notification about a comment as processed
|
|
|
|
* @param IComment $comment
|
2018-09-12 09:23:38 +00:00
|
|
|
* @param IUser $currentUser
|
2016-05-09 08:02:07 +00:00
|
|
|
*/
|
2018-09-12 09:23:38 +00:00
|
|
|
protected function markProcessed(IComment $comment, IUser $currentUser) {
|
2016-05-09 08:02:07 +00:00
|
|
|
$notification = $this->notificationManager->createNotification();
|
|
|
|
$notification->setApp('comments')
|
|
|
|
->setObject('comment', $comment->getId())
|
|
|
|
->setSubject('mention')
|
2018-09-12 09:23:38 +00:00
|
|
|
->setUser($currentUser->getUID());
|
2016-05-09 08:02:07 +00:00
|
|
|
$this->notificationManager->markProcessed($notification);
|
|
|
|
}
|
|
|
|
}
|