]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Notifications/Ping.php
Merge pull request #11532 from tobiasd/2022.05-CHANGELOG
[friendica.git] / src / Module / Notifications / Ping.php
index 50c823203249ba32dbc15b4b99860b22860f60ca..7dc215826024dd0ccfa6a5b17c631542fec5c9db 100644 (file)
@@ -33,10 +33,12 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Group;
 use Friendica\Model\Post;
+use Friendica\Model\User;
 use Friendica\Model\Verb;
 use Friendica\Module\Register;
 use Friendica\Module\Response;
 use Friendica\Navigation\Notifications\Entity;
+use Friendica\Navigation\Notifications\Exception\NoMessageException;
 use Friendica\Navigation\Notifications\Factory;
 use Friendica\Navigation\Notifications\Repository;
 use Friendica\Navigation\Notifications\ValueObject;
@@ -86,7 +88,7 @@ class Ping extends BaseModule
 
                if (local_user()) {
                        if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
-                               $notifications = $this->notificationRepo->selectForUser(local_user(), [], ['limit' => 50]);
+                               $notifications = $this->notificationRepo->selectDetailedForUser(local_user());
                        } else {
                                $notifications = $this->notificationRepo->selectDigestForUser(local_user());
                        }
@@ -182,11 +184,26 @@ class Ping extends BaseModule
                                }
                        }
 
-                       $sysnotify_count = $notifications->countUnseen();
+                       $owner = User::getOwnerDataById(local_user());
 
-                       $navNotifications = array_map(function (Entity\Notification $notification) {
-                               return $this->formattedNavNotification->createFromNotification($notification);
+                       $navNotifications = array_map(function (Entity\Notification $notification) use ($owner) {
+                               if (!DI::notify()->NotifyOnDesktop($notification)) {
+                                       return null;
+                               }
+                               if (($notification->type == Post\UserNotification::TYPE_NONE) && in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])) {
+                                       return null;
+                               }
+                               try {
+                                       return $this->formattedNavNotification->createFromNotification($notification);
+                               } catch (NoMessageException $e) {
+                                       return null;
+                               }
                        }, $notifications->getArrayCopy());
+                       $navNotifications = array_filter($navNotifications);
+
+                       $sysnotify_count = array_reduce($navNotifications, function (int $carry, ValueObject\FormattedNavNotification $navNotification) {
+                               return $carry + ($navNotification->seen ? 0 : 1);
+                       }, 0);
 
                        // merge all notification types in one array
                        foreach ($intros as $intro) {
@@ -277,9 +294,7 @@ class Ping extends BaseModule
 
                if (isset($_GET['callback'])) {
                        // JSONP support
-                       header("Content-type: application/javascript");
-                       echo $_GET['callback'] . '(' . json_encode(['result' => $data]) . ')';
-                       exit;
+                       System::httpExit($_GET['callback'] . '(' . json_encode(['result' => $data]) . ')', Response::TYPE_BLANK, 'application/javascript');
                } else {
                        System::jsonExit(['result' => $data]);
                }