]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Subscription.php
Issue 13221: Diaspora posts are now stored correctly
[friendica.git] / src / Model / Subscription.php
index c6c57c732835da504b97cb9c6f95215636456b5a..10a2d9b4d10d1af6b9b0e051b2c5a4db7c6b4e06 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -25,6 +25,7 @@ use Friendica\Core\Logger;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Factory\Api\Mastodon\Notification as NotificationFactory;
 use Friendica\Navigation\Notifications\Entity;
 use Friendica\Object\Api\Mastodon\Notification;
 use Minishlink\WebPush\VAPID;
@@ -37,8 +38,7 @@ class Subscription
         * @param int   $applicationid
         * @param int   $uid
         * @param array $fields
-        *
-        * @return bool Does it exist?
+        * @return array|bool Array on success, false on failure
         */
        public static function select(int $applicationid, int $uid, array $fields = [])
        {
@@ -53,7 +53,7 @@ class Subscription
         *
         * @return bool Does it exist?
         */
-       public static function exists(int $applicationid, int $uid)
+       public static function exists(int $applicationid, int $uid): bool
        {
                return DBA::exists('subscription', ['application-id' => $applicationid, 'uid' => $uid]);
        }
@@ -64,10 +64,9 @@ class Subscription
         * @param int   $applicationid
         * @param int   $uid
         * @param array $fields subscription fields
-        *
         * @return bool result of update
         */
-       public static function update(int $applicationid, int $uid, array $fields)
+       public static function update(int $applicationid, int $uid, array $fields): bool
        {
                return DBA::update('subscription', $fields, ['application-id' => $applicationid, 'uid' => $uid]);
        }
@@ -76,10 +75,9 @@ class Subscription
         * Insert or replace a subscription record
         *
         * @param array $fields subscription fields
-        *
         * @return bool result of replace
         */
-       public static function replace(array $fields)
+       public static function replace(array $fields): bool
        {
                return DBA::replace('subscription', $fields);
        }
@@ -91,7 +89,7 @@ class Subscription
         * @param int $uid
         * @return bool
         */
-       public static function delete(int $applicationid, int $uid)
+       public static function delete(int $applicationid, int $uid): bool
        {
                return DBA::delete('subscription', ['application-id' => $applicationid, 'uid' => $uid]);
        }
@@ -136,35 +134,25 @@ class Subscription
        /**
         * Prepare push notification
         *
-        * @param int $nid
+        * @param Notification $Notification
         * @return void
         */
-       public static function pushByNotification(Entity\Notification $Notification)
+       public static function pushByNotification(Entity\Notification $notification)
        {
-               $type = \Friendica\Factory\Api\Mastodon\Notification::getType($Notification);
-
-               $desktop_notification = !in_array($type, [Notification::TYPE_RESHARE, Notification::TYPE_LIKE]);
-
-               if (DI::pConfig()->get($Notification->uid, 'system', 'notify_like') && ($type == Notification::TYPE_LIKE)) {
-                       $desktop_notification = true;
-               }
-
-               if (DI::pConfig()->get($Notification->uid, 'system', 'notify_announce') && ($type == Notification::TYPE_RESHARE)) {
-                       $desktop_notification = true;
-               }
+               $type = NotificationFactory::getType($notification);
 
-               if ($desktop_notification) {
-                       notification_from_array($Notification);
+               if (DI::notify()->shouldShowOnDesktop($notification, $type)) {
+                       DI::notify()->createFromNotification($notification);
                }
 
                if (empty($type)) {
                        return;
                }
 
-               $subscriptions = DBA::select('subscription', [], ['uid' => $Notification->uid, $type => true]);
+               $subscriptions = DBA::select('subscription', [], ['uid' => $notification->uid, $type => true]);
                while ($subscription = DBA::fetch($subscriptions)) {
                        Logger::info('Push notification', ['id' => $subscription['id'], 'uid' => $subscription['uid'], 'type' => $type]);
-                       Worker::add(PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $Notification->id);
+                       Worker::add(Worker::PRIORITY_HIGH, 'PushSubscription', $subscription['id'], $notification->id);
                }
                DBA::close($subscriptions);
        }