]> git.mxchange.org Git - friendica.git/commitdiff
Flatten arbitrary contact structure in constructor of FormattedNavNotification
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 10 Nov 2022 15:40:37 +0000 (10:40 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Thu, 10 Nov 2022 15:41:02 +0000 (10:41 -0500)
src/Module/Notifications/Ping.php
src/Navigation/Notifications/Factory/FormattedNavNotification.php
src/Navigation/Notifications/ValueObject/FormattedNavNotification.php

index 2eaa2c4a5ca274faf6ce52e69a82ffe38f797396..76cdd9f77055ce967968eda5d712fd6e07e3d651 100644 (file)
@@ -233,23 +233,19 @@ class Ping extends BaseModule
                        }
 
                        if (count($registrations) <= 1 || $this->pconfig->get($this->session->getLocalUserId(), 'system', 'detailed_notif')) {
-                               foreach ($registrations as $reg) {
+                               foreach ($registrations as $registration) {
                                        $navNotifications[] = $this->formattedNavNotification->createFromParams(
-                                               [
-                                                       'name' => $reg['name'],
-                                                       'url'  => $reg['url'],
-                                               ],
+                                               $registration['name'],
+                                               $registration['url'],
                                                $this->l10n->t('{0} requested registration'),
-                                               new \DateTime($reg['created'], new \DateTimeZone('UTC')),
+                                               new \DateTime($registration['created'], new \DateTimeZone('UTC')),
                                                new Uri($this->baseUrl->get(true) . '/moderation/users/pending')
                                        );
                                }
                        } elseif (count($registrations) > 1) {
                                $navNotifications[] = $this->formattedNavNotification->createFromParams(
-                                       [
-                                               'name' => $registrations[0]['name'],
-                                               'url'  => $registrations[0]['url'],
-                                       ],
+                                       $registrations[0]['name'],
+                                       $registrations[0]['url'],
                                        $this->l10n->t('{0} and %d others requested registration', count($registrations) - 1),
                                        new \DateTime($registrations[0]['created'], new \DateTimeZone('UTC')),
                                        new Uri($this->baseUrl->get(true) . '/moderation/users/pending')
index 434fb3799a749fa0d90e7015bd277246a1161d86..cfb798ac7287f9c5d61ca151ad3c90778e5d11d0 100644 (file)
@@ -28,6 +28,7 @@ use Friendica\Model\Contact;
 use Friendica\Navigation\Notifications\Entity;
 use Friendica\Navigation\Notifications\Exception\NoMessageException;
 use Friendica\Navigation\Notifications\ValueObject;
+use Friendica\Network\HTTPException\ServiceUnavailableException;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Proxy;
 use Friendica\Util\Temporal;
@@ -65,32 +66,39 @@ class FormattedNavNotification extends BaseFactory
        }
 
        /**
-        * @param array     $contact A contact array with the following keys: name, url
+        * @param string    $contact_name
+        * @param string    $contact_url
         * @param string    $message A notification message with the {0} placeholder for the contact name
         * @param \DateTime $date
         * @param Uri       $href
         * @param bool      $seen
         * @return ValueObject\FormattedNavNotification
-        * @throws \Friendica\Network\HTTPException\ServiceUnavailableException
+        * @throws ServiceUnavailableException
         */
-       public function createFromParams(array $contact, string $message, \DateTime $date, Uri $href, bool $seen = false): ValueObject\FormattedNavNotification
+       public function createFromParams(string $contact_name, string $contact_url, string $message, \DateTime $date, Uri $href, bool $seen = false): ValueObject\FormattedNavNotification
        {
-               $contact['photo'] = Contact::getAvatarUrlForUrl($contact['url'], $this->userSession->getLocalUserId(), Proxy::SIZE_MICRO);
+               $contact_photo = Contact::getAvatarUrlForUrl($contact_url, $this->userSession->getLocalUserId(), Proxy::SIZE_MICRO);
 
                $dateMySQL = $date->format(DateTimeFormat::MYSQL);
 
                $templateNotify = [
-                       'contact'   => $contact,
+                       'contact' => [
+                               'name'  => $contact_name,
+                               'url'   => $contact_url,
+                               'photo' => $contact_photo,
+                       ],
                        'href'      => $href->__toString(),
                        'message'   => $message,
                        'seen'      => $seen,
                        'localdate' => DateTimeFormat::local($dateMySQL),
                        'ago'       => Temporal::getRelativeDate($dateMySQL),
-                       'richtext'  => Entity\Notify::formatMessage($contact['name'], $message),
+                       'richtext'  => Entity\Notify::formatMessage($contact_name, $message),
                ];
 
                return new ValueObject\FormattedNavNotification(
-                       $contact,
+                       $contact_name,
+                       $contact_url,
+                       $contact_photo,
                        $date->getTimestamp(),
                        strip_tags($templateNotify['richtext']),
                        Renderer::replaceMacros($this->tpl, ['notify' => $templateNotify]),
@@ -120,7 +128,8 @@ class FormattedNavNotification extends BaseFactory
                }
 
                return $this->createFromParams(
-                       self::$contacts[$notification->actorId],
+                       self::$contacts[$notification->actorId]['name'],
+                       self::$contacts[$notification->actorId]['url'],
                        $message['notification'],
                        $notification->created,
                        new Uri($this->baseUrl->get() . '/notification/' . $notification->id),
@@ -141,7 +150,8 @@ class FormattedNavNotification extends BaseFactory
                }
 
                return $this->createFromParams(
-                       self::$contacts[$intro->cid],
+                       self::$contacts[$intro->cid]['name'],
+                       self::$contacts[$intro->cid]['url'],
                        $msg,
                        $intro->datetime,
                        new Uri($this->baseUrl->get() . '/notifications/intros/' . $intro->id)
index d2fae060aaa93e6fd10fded0442f2b4b39492a41..04c1f6143e51bb77af577fd1655119c2803f4038 100644 (file)
@@ -42,16 +42,23 @@ class FormattedNavNotification extends BaseEntity
        protected $seen;
 
        /**
-        * @param array  $contact   Contact array with the following keys: name, url, photo
-        * @param string $timestamp Unix timestamp
-        * @param string $plaintext Localized notification message with the placeholder replaced by the contact name
-        * @param string $html      Full HTML string of the notification menu element
-        * @param string $href      Absolute URL this notification should send the user to when interacted with
-        * @param bool   $seen      Whether the user interacted with this notification once
+        * @param string $contact_name  Contact display name
+        * @param string $contact_url   Contact profile URL
+        * @param string $contact_photo Contact picture URL
+        * @param string $timestamp     Unix timestamp
+        * @param string $plaintext     Localized notification message with the placeholder replaced by the contact name
+        * @param string $html          Full HTML string of the notification menu element
+        * @param string $href          Absolute URL this notification should send the user to when interacted with
+        * @param bool   $seen          Whether the user interacted with this notification once
         */
-       public function __construct(array $contact, string $timestamp, string $plaintext, string $html, string $href, bool $seen)
+       public function __construct(string $contact_name, string $contact_url, string $contact_photo, string $timestamp, string $plaintext, string $html, string $href, bool $seen)
        {
-               $this->contact   = $contact;
+               // Properties differ from constructor because this structure is used in the "nav-update" Javascript event listener
+               $this->contact = [
+                       'name'  => $contact_name,
+                       'url'   => $contact_url,
+                       'photo' => $contact_photo,
+               ];
                $this->timestamp = $timestamp;
                $this->plaintext = $plaintext;
                $this->html      = $html;