]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Notifications/Notification.php
Merge pull request #12050 from nupplaphil/bug/notf_session_fix
[friendica.git] / src / Module / Notifications / Notification.php
index a28b5d6f65c102505c435bf1863eeaf1f3661c4c..ff33dd41a2deaab50584057fcf64f170e649dd42 100644 (file)
@@ -27,6 +27,7 @@ use Friendica\Contact\Introduction\Repository\Introduction;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
 use Friendica\Core\System;
+use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Module\Response;
 use Friendica\Module\Security\Login;
@@ -71,14 +72,14 @@ class Notification extends BaseModule
         */
        protected function post(array $request = [])
        {
-               if (!local_user()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        throw new HTTPException\UnauthorizedException($this->l10n->t('Permission denied.'));
                }
 
                $request_id = $this->parameters['id'] ?? false;
 
                if ($request_id) {
-                       $intro = $this->introductionRepo->selectOneById($request_id, local_user());
+                       $intro = $this->introductionRepo->selectOneById($request_id, DI::userSession()->getLocalUserId());
 
                        switch ($_POST['submit']) {
                                case $this->l10n->t('Discard'):
@@ -102,14 +103,14 @@ class Notification extends BaseModule
         */
        protected function rawContent(array $request = [])
        {
-               if (!local_user()) {
+               if (!DI::userSession()->getLocalUserId()) {
                        throw new HTTPException\UnauthorizedException($this->l10n->t('Permission denied.'));
                }
 
                if ($this->args->get(1) === 'mark' && $this->args->get(2) === 'all') {
                        try {
-                               $this->notificationRepo->setAllSeenForUser(local_user());
-                               $success = $this->notifyRepo->setAllSeenForUser(local_user());
+                               $this->notificationRepo->setAllSeenForUser(DI::userSession()->getLocalUserId());
+                               $success = $this->notifyRepo->setAllSeenForUser(DI::userSession()->getLocalUserId());
                        } catch (\Exception $e) {
                                $this->logger->warning('set all seen failed.', ['exception' => $e]);
                                $success = false;
@@ -130,8 +131,8 @@ class Notification extends BaseModule
         */
        protected function content(array $request = []): string
        {
-               if (!local_user()) {
-                       notice($this->l10n->t('You must be logged in to show this page.'));
+               if (!DI::userSession()->getLocalUserId()) {
+                       DI::sysmsg()->addNotice($this->l10n->t('You must be logged in to show this page.'));
                        return Login::form();
                }
 
@@ -149,11 +150,11 @@ class Notification extends BaseModule
        private function handleNotify(int $notifyId)
        {
                $Notify = $this->notifyRepo->selectOneById($notifyId);
-               if ($Notify->uid !== local_user()) {
+               if ($Notify->uid !== DI::userSession()->getLocalUserId()) {
                        throw new HTTPException\ForbiddenException();
                }
 
-               if ($this->pconfig->get(local_user(), 'system', 'detailed_notif')) {
+               if ($this->pconfig->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
                        $Notify->setSeen();
                        $this->notifyRepo->save($Notify);
                } else {
@@ -174,11 +175,11 @@ class Notification extends BaseModule
        private function handleNotification(int $notificationId)
        {
                $Notification = $this->notificationRepo->selectOneById($notificationId);
-               if ($Notification->uid !== local_user()) {
+               if ($Notification->uid !== DI::userSession()->getLocalUserId()) {
                        throw new HTTPException\ForbiddenException();
                }
 
-               if ($this->pconfig->get(local_user(), 'system', 'detailed_notif')) {
+               if ($this->pconfig->get(DI::userSession()->getLocalUserId(), 'system', 'detailed_notif')) {
                        $Notification->setSeen();
                        $this->notificationRepo->save($Notification);
                } else {