3 * @copyright Copyright (C) 2020, Friendica
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\Network\HTTPException;
30 * Interacting with the /notification command
32 class Notification extends BaseModule
34 public static function init(array $parameters = [])
37 throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
41 public static function post(array $parameters = [])
43 $request_id = $parameters['id'] ?? false;
46 $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
48 switch ($_POST['submit']) {
49 case DI::l10n()->t('Discard'):
52 case DI::l10n()->t('Ignore'):
57 DI::baseUrl()->redirect('notifications/intros');
61 public static function rawContent(array $parameters = [])
63 // @TODO: Replace with parameter from router
64 if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
66 $success = DI::notify()->setSeen();
67 } catch (\Exception $e) {
68 DI::logger()->warning('set all seen failed.', ['exception' => $e]);
72 System::jsonExit(['result' => (($success) ? 'success' : 'fail')]);
77 * Redirect to the notifications main page or to the url for the chosen notifications
80 * @throws HTTPException\InternalServerErrorException
82 public static function content(array $parameters = [])
84 $request_id = $parameters['id'] ?? false;
88 $notify = DI::notify()->getByID($request_id);
89 DI::notify()->setSeen(true, $notify);
91 if (!empty($notify->link)) {
92 System::externalRedirect($notify->link);
95 } catch (HTTPException\NotFoundException $e) {
96 info(DI::l10n()->t('Invalid notification.'));
99 DI::baseUrl()->redirect();
102 DI::baseUrl()->redirect('notifications/system');