]> git.mxchange.org Git - friendica.git/commitdiff
Create new DI shorthands for notification-related factories
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 19 Sep 2021 16:56:24 +0000 (12:56 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 2 Oct 2021 22:15:45 +0000 (18:15 -0400)
include/enotify.php
src/DI.php
src/Module/Notifications/Notifications.php
src/Worker/PushSubscription.php

index 90a17ad25e5dec8481d6bfb3a745ab7ad32d6605..c30b6de86ec6a03aabce139e2182bafc00ac35a2 100644 (file)
@@ -30,7 +30,6 @@ use Friendica\Model\Item;
 use Friendica\Model\Notification;
 use Friendica\Model\Post;
 use Friendica\Model\User;
-use Friendica\Model\Verb;
 use Friendica\Navigation\Notifications;
 use Friendica\Protocol\Activity;
 
@@ -396,10 +395,7 @@ function notification_store_and_send($params, $sitelink, $tsitelink, $hsitelink,
        $notify_id = 0;
 
        if ($show_in_notification_page) {
-               /** @var $factory Notifications\Factory\Notify */
-               $factory = DI::getDice()->create(Notifications\Factory\Notify::class);
-
-               $Notify = $factory->createFromParams($params, $itemlink, $item_id, $uri_id, $parent_id, $parent_uri_id);
+               $Notify = DI::notifyFactory()->createFromParams($params, $itemlink, $item_id, $uri_id, $parent_id, $parent_uri_id);
                try {
                        $Notify = DI::notify()->save($Notify);
                } catch (Notifications\Exception\NotificationCreationInterceptedException $e) {
@@ -572,7 +568,7 @@ function notification_from_array(Notifications\Entity\Notification $Notification
                $subject        = $l10n->t('%1$s Comment to conversation #%2$d by %3$s', $subjectPrefix, $item['parent'], $contact['name']);
        }
 
-       $msg = (new Notifications\Factory\Notification(DI::logger()))->getMessageFromNotification($Notification, DI::baseUrl(), $l10n);
+       $msg = DI::notificationFactory()->getMessageFromNotification($Notification, DI::baseUrl(), $l10n);
        if (empty($msg)) {
                Logger::info('No notification message, quitting', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);
                return false;
index 4168997d4be0a13681aade5321131e2a95c1a6d4..ea7310feedca3805eacd15e9dcb4577f2b3a8216 100644 (file)
@@ -463,11 +463,26 @@ abstract class DI
                return self::$dice->create(Navigation\Notifications\Depository\Notification::class);
        }
 
+       public static function notificationFactory(): Navigation\Notifications\Factory\Notification
+       {
+               return self::$dice->create(Navigation\Notifications\Factory\Notification::class);
+       }
+
        public static function notify(): Navigation\Notifications\Depository\Notify
        {
                return self::$dice->create(Navigation\Notifications\Depository\Notify::class);
        }
 
+       public static function notifyFactory(): Navigation\Notifications\Factory\Notify
+       {
+               return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
+       }
+
+       public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotification
+       {
+               return self::$dice->create(Navigation\Notifications\Factory\FormattedNotification::class);
+       }
+
        //
        // "Protocol" namespace instances
        //
index af8b14512b35795515aaef0ff9e5ad254e82c166..a0e40719c0e6e64a7784c18102459749e1ae603a 100644 (file)
@@ -46,8 +46,7 @@ class Notifications extends BaseNotifications
                $notificationHeader = '';
                $notifications = [];
 
-               /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification $factory */
-               $factory = DI::getDice()->create(\Friendica\Navigation\Notifications\Factory\FormattedNotification::class);
+               $factory = DI::formattedNotificationFactory();
 
                if ((DI::args()->get(1) == 'network')) {
                        $notificationHeader = DI::l10n()->t('Network Notifications');
index ae34abc8775c56377215075eb9fd83da7a46fa67..f07b773198c73090075b356b4210dd41b1e9cfe4 100644 (file)
@@ -82,7 +82,7 @@ class PushSubscription
                        }
                }
 
-               $message = (new Notifications\Factory\Notification(DI::logger()))->getMessageFromNotification($Notification, DI::baseUrl(), $l10n);
+               $message = DI::notificationFactory()->getMessageFromNotification($Notification, DI::baseUrl(), $l10n);
                $title = $message['plain'] ?: '';
 
                $push = Subscription::create([