3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Notifications;
24 use Friendica\BaseModule;
25 use Friendica\Core\System;
27 use Friendica\Model\Contact;
28 use Friendica\Module\Security\Login;
29 use Friendica\Network\HTTPException;
32 * Interacting with the /notification command
34 class Notification extends BaseModule
39 * @throws HTTPException\InternalServerErrorException
40 * @throws HTTPException\NotFoundException
41 * @throws HTTPException\UnauthorizedException
42 * @throws \ImagickException
45 public static function post(array $parameters = [])
48 throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
51 $request_id = $parameters['id'] ?? false;
54 $intro = DI::intro()->selectOneById($request_id, local_user());
56 switch ($_POST['submit']) {
57 case DI::l10n()->t('Discard'):
58 Contact\Introduction::discard($intro);
59 DI::intro()->delete($intro);
61 case DI::l10n()->t('Ignore'):
63 DI::intro()->save($intro);
67 DI::baseUrl()->redirect('notifications/intros');
74 * @throws HTTPException\UnauthorizedException
76 public static function rawContent(array $parameters = [])
79 throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
82 if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
84 DI::notification()->setAllSeenForUser(local_user());
85 $success = DI::notify()->setAllSeenForUser(local_user());
86 } catch (\Exception $e) {
87 DI::logger()->warning('set all seen failed.', ['exception' => $e]);
91 System::jsonExit(['result' => (($success) ? 'success' : 'fail')]);
98 * Redirect to the notifications main page or to the url for the chosen notifications
100 * @throws HTTPException\NotFoundException In case the notification is either not existing or is not for this user
101 * @throws HTTPException\InternalServerErrorException
104 public static function content(array $parameters = []): string
107 notice(DI::l10n()->t('You must be logged in to show this page.'));
108 return Login::form();
111 $request_id = $parameters['id'] ?? false;
114 $Notify = DI::notify()->selectOneById($request_id);
115 if ($Notify->uid !== local_user()) {
116 throw new HTTPException\ForbiddenException();
119 if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
121 DI::notify()->save($Notify);
123 if ($Notify->uriId) {
124 DI::notification()->setAllSeenForUser($Notify->uid, ['target-uri-id' => $Notify->uriId]);
127 DI::notify()->setAllSeenForRelatedNotify($Notify);
130 if ((string)$Notify->link) {
131 System::externalRedirect($Notify->link);
134 DI::baseUrl()->redirect();
137 DI::baseUrl()->redirect('notifications/system');