3 namespace Friendica\Module\Notifications;
5 use Friendica\BaseModule;
6 use Friendica\Core\System;
8 use Friendica\Network\HTTPException;
11 * Interacting with the /notification command
13 class Notification extends BaseModule
15 public static function init(array $parameters = [])
18 throw new HTTPException\UnauthorizedException(DI::l10n()->t('Permission denied.'));
22 public static function post(array $parameters = [])
24 $request_id = $parameters['id'] ?? false;
26 if (DI::args()->get(1) == 'action' && $request_id) {
27 $intro = DI::intro()->selectFirst(['id' => $request_id, 'uid' => local_user()]);
29 switch ($_POST['submit']) {
30 case DI::l10n()->t('Discard'):
33 case DI::l10n()->t('Ignore'):
38 DI::baseUrl()->redirect('notifications/intros');
42 public static function rawContent(array $parameters = [])
44 // @TODO: Replace with parameter from router
45 if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
47 $success = DI::notify()->setAllSeen();
48 }catch (\Exception $e) {
52 header('Content-type: application/json; charset=utf-8');
54 'result' => ($success) ? 'success' : 'fail',
61 * Redirect to the notifications main page or to the url for the chosen notifications
64 * @throws HTTPException\InternalServerErrorException
66 public static function content(array $parameters = [])
68 // @TODO: Replace with parameter from router
69 if (DI::args()->getArgc() > 2 && DI::args()->get(1) === 'view' && intval(DI::args()->get(2))) {
71 $notification = DI::notify()->getByID(DI::args()->get(2));
72 $notification->setSeen();
74 if (!empty($notification->link)) {
75 System::externalRedirect($notification->link);
78 } catch (HTTPException\NotFoundException $e) {
79 info(DI::l10n()->t('Invalid notification.'));
82 DI::baseUrl()->redirect();
85 // @TODO: Replace with parameter from router
86 DI::baseUrl()->redirect('notifications/system');