]> git.mxchange.org Git - friendica.git/commitdiff
Deprecated the notify table/classes
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 23 Feb 2022 07:10:57 +0000 (02:10 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 14 Mar 2022 11:56:20 +0000 (07:56 -0400)
14 files changed:
database.sql
doc/database.md
doc/database/db_notify.md
src/DI.php
src/Module/BaseNotifications.php
src/Module/Notifications/Notifications.php
src/Navigation/Notifications/Collection/FormattedNotifications.php [deleted file]
src/Navigation/Notifications/Collection/FormattedNotifies.php [new file with mode: 0644]
src/Navigation/Notifications/Entity/Notify.php
src/Navigation/Notifications/Factory/FormattedNotify.php [new file with mode: 0644]
src/Navigation/Notifications/Factory/Notify.php
src/Navigation/Notifications/Repository/Notify.php
src/Navigation/Notifications/ValueObject/FormattedNotify.php [new file with mode: 0644]
static/dbstructure.config.php

index a36adad01588cfe0f7dec8eb30f43d7ec3208e68..39e40c044a5286c726e2cad49c0439c4a6135fd6 100644 (file)
@@ -882,7 +882,7 @@ CREATE TABLE IF NOT EXISTS `notify` (
        FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
        FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
        FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
-) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications';
+) DEFAULT COLLATE utf8mb4_general_ci COMMENT='[Deprecated] User notifications';
 
 --
 -- TABLE notify-threads
index 628e84e2117626435bf4bf974914b31dc69eca78..f64434b8868df11729686d11971231d940b7cc1c 100644 (file)
@@ -37,7 +37,7 @@ Database Tables
 | [mailacct](help/database/db_mailacct) | Mail account data for fetching mails |
 | [manage](help/database/db_manage) | table of accounts that can manage each other |
 | [notification](help/database/db_notification) | notifications |
-| [notify](help/database/db_notify) | notifications |
+| [notify](help/database/db_notify) | [Deprecated] User notifications |
 | [notify-threads](help/database/db_notify-threads) |  |
 | [oembed](help/database/db_oembed) | cache for OEmbed queries |
 | [openwebauth-token](help/database/db_openwebauth-token) | Store OpenWebAuth token to verify contacts |
index 250734e56cacd9a6c4a245d24bbbac0463ed6f7d..88d814c0408ca5ce035428470252de10b7a1dfc1 100644 (file)
@@ -1,7 +1,7 @@
 Table notify
 ===========
 
-notifications
+[Deprecated] User notifications
 
 Fields
 ------
index 708fb7d836da3fe54a7c72bc40d81c4ce1a19a3b..43234946cb3a8881cb1c53a61ac2315207abb853 100644 (file)
@@ -527,9 +527,9 @@ abstract class DI
                return self::$dice->create(Navigation\Notifications\Factory\Notify::class);
        }
 
-       public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotification
+       public static function formattedNotificationFactory(): Navigation\Notifications\Factory\FormattedNotify
        {
-               return self::$dice->create(Navigation\Notifications\Factory\FormattedNotification::class);
+               return self::$dice->create(Navigation\Notifications\Factory\FormattedNotify::class);
        }
 
        //
index d7319fa4ea37681c1e4fcc135f79bf87a7541669..1190e046dfb6ea8742db87fa4a1a4fd258adae1d 100644 (file)
@@ -29,7 +29,7 @@ use Friendica\Content\Pager;
 use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Core\System;
-use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
+use Friendica\Navigation\Notifications\ValueObject\FormattedNotify;
 use Friendica\Network\HTTPException\ForbiddenException;
 use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
@@ -43,29 +43,29 @@ abstract class BaseNotifications extends BaseModule
 {
        /** @var array Array of URL parameters */
        const URL_TYPES = [
-               FormattedNotification::NETWORK  => 'network',
-               FormattedNotification::SYSTEM   => 'system',
-               FormattedNotification::HOME     => 'home',
-               FormattedNotification::PERSONAL => 'personal',
-               FormattedNotification::INTRO    => 'intros',
+               FormattedNotify::NETWORK  => 'network',
+               FormattedNotify::SYSTEM   => 'system',
+               FormattedNotify::HOME     => 'home',
+               FormattedNotify::PERSONAL => 'personal',
+               FormattedNotify::INTRO    => 'intros',
        ];
 
        /** @var array Array of the allowed notifications and their printable name */
        const PRINT_TYPES = [
-               FormattedNotification::NETWORK  => 'Network',
-               FormattedNotification::SYSTEM   => 'System',
-               FormattedNotification::HOME     => 'Home',
-               FormattedNotification::PERSONAL => 'Personal',
-               FormattedNotification::INTRO    => 'Introductions',
+               FormattedNotify::NETWORK  => 'Network',
+               FormattedNotify::SYSTEM   => 'System',
+               FormattedNotify::HOME     => 'Home',
+               FormattedNotify::PERSONAL => 'Personal',
+               FormattedNotify::INTRO    => 'Introductions',
        ];
 
        /** @var array The array of access keys for notification pages */
        const ACCESS_KEYS = [
-               FormattedNotification::NETWORK  => 'w',
-               FormattedNotification::SYSTEM   => 'y',
-               FormattedNotification::HOME     => 'h',
-               FormattedNotification::PERSONAL => 'r',
-               FormattedNotification::INTRO    => 'i',
+               FormattedNotify::NETWORK  => 'w',
+               FormattedNotify::SYSTEM   => 'y',
+               FormattedNotify::HOME     => 'h',
+               FormattedNotify::PERSONAL => 'r',
+               FormattedNotify::INTRO    => 'i',
        ];
 
        /** @var int The default count of items per page */
index e090aa5a38ec32bac76a0002f0dd758cf02db6cb..90ea9c28ba53fdccb85f79a620a84e531e220373 100644 (file)
@@ -28,7 +28,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\Renderer;
 use Friendica\Module\BaseNotifications;
 use Friendica\Module\Response;
-use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
+use Friendica\Navigation\Notifications\ValueObject\FormattedNotify;
 use Friendica\Util\Profiler;
 use Psr\Log\LoggerInterface;
 
@@ -41,14 +41,14 @@ use Psr\Log\LoggerInterface;
  */
 class Notifications extends BaseNotifications
 {
-       /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification */
-       protected $formattedNotificationFactory;
+       /** @var \Friendica\Navigation\Notifications\Factory\FormattedNotify */
+       protected $formattedNotifyFactory;
 
-       public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotification $formattedNotificationFactory, array $server, array $parameters = [])
+       public function __construct(L10n $l10n, App\BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, \Friendica\Navigation\Notifications\Factory\FormattedNotify $formattedNotifyFactory, array $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
-               $this->formattedNotificationFactory = $formattedNotificationFactory;
+               $this->formattedNotifyFactory = $formattedNotifyFactory;
        }
 
        /**
@@ -59,30 +59,30 @@ class Notifications extends BaseNotifications
                $notificationHeader = '';
                $notifications = [];
 
-               $factory = $this->formattedNotificationFactory;
+               $factory = $this->formattedNotifyFactory;
 
                if (($this->args->get(1) == 'network')) {
                        $notificationHeader = $this->t('Network Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::NETWORK,
+                               'ident'        => FormattedNotify::NETWORK,
                                'notifications' => $factory->getNetworkList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
                } elseif (($this->args->get(1) == 'system')) {
                        $notificationHeader = $this->t('System Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::SYSTEM,
+                               'ident'        => FormattedNotify::SYSTEM,
                                'notifications' => $factory->getSystemList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
                } elseif (($this->args->get(1) == 'personal')) {
                        $notificationHeader = $this->t('Personal Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::PERSONAL,
+                               'ident'        => FormattedNotify::PERSONAL,
                                'notifications' => $factory->getPersonalList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
                } elseif (($this->args->get(1) == 'home')) {
                        $notificationHeader = $this->t('Home Notifications');
                        $notifications      = [
-                               'ident'        => FormattedNotification::HOME,
+                               'ident'        => FormattedNotify::HOME,
                                'notifications' => $factory->getHomeList($this->showAll, $this->firstItemNum, self::ITEMS_PER_PAGE),
                        ];
                } else {
@@ -120,7 +120,7 @@ class Notifications extends BaseNotifications
                        ];
                        // Loop trough ever notification This creates an array with the output html for each
                        // notification and apply the correct template according to the notificationtype (label).
-                       /** @var FormattedNotification $Notification */
+                       /** @var FormattedNotify $Notification */
                        foreach ($notifications['notifications'] as $Notification) {
                                $notificationArray = $Notification->toArray();
 
diff --git a/src/Navigation/Notifications/Collection/FormattedNotifications.php b/src/Navigation/Notifications/Collection/FormattedNotifications.php
deleted file mode 100644 (file)
index 8dad2f6..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-/**
- * @copyright Copyright (C) 2010-2022, the Friendica project
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- *
- */
-
-namespace Friendica\Navigation\Notifications\Collection;
-
-use Friendica\BaseCollection;
-use Friendica\Navigation\Notifications\ValueObject;
-
-class FormattedNotifications extends BaseCollection
-{
-       /**
-        * @return ValueObject\FormattedNotification
-        */
-       public function current(): ValueObject\FormattedNotification
-       {
-               return parent::current();
-       }
-}
diff --git a/src/Navigation/Notifications/Collection/FormattedNotifies.php b/src/Navigation/Notifications/Collection/FormattedNotifies.php
new file mode 100644 (file)
index 0000000..0b907ca
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Navigation\Notifications\Collection;
+
+use Friendica\BaseCollection;
+use Friendica\Navigation\Notifications\ValueObject;
+
+/**
+ * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Collection\FormattedNotifications instead
+ */
+class FormattedNotifies extends BaseCollection
+{
+       /**
+        * @return ValueObject\FormattedNotify
+        */
+       public function current(): ValueObject\FormattedNotify
+       {
+               return parent::current();
+       }
+}
index bf47bdafc676e9df24bc4601e531a7b522f90d56..8f8166ab9037cde9152f79c9d8f4a7ba0c718489 100644 (file)
@@ -46,6 +46,8 @@ use Psr\Http\Message\UriInterface;
  * @property-read $uriId
  * @property-read $parentUriId
  * @property-read $id
+ *
+ * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Entity\Notification instead
  */
 class Notify extends BaseEntity
 {
diff --git a/src/Navigation/Notifications/Factory/FormattedNotify.php b/src/Navigation/Notifications/Factory/FormattedNotify.php
new file mode 100644 (file)
index 0000000..2551de1
--- /dev/null
@@ -0,0 +1,378 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Navigation\Notifications\Factory;
+
+use Exception;
+use Friendica\App\BaseURL;
+use Friendica\BaseFactory;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\L10n;
+use Friendica\Core\Protocol;
+use Friendica\Database\Database;
+use Friendica\Model\Contact;
+use Friendica\Model\Post;
+use Friendica\Module\BaseNotifications;
+use Friendica\Navigation\Notifications\Collection\FormattedNotifies;
+use Friendica\Navigation\Notifications\Repository;
+use Friendica\Navigation\Notifications\ValueObject;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Protocol\Activity;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Proxy;
+use Friendica\Util\Temporal;
+use Friendica\Util\XML;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Factory for creating notification objects based on items
+ * Currently, there are the following types of item based notifications:
+ * - network
+ * - system
+ * - home
+ * - personal
+ *
+ * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Factory\FormattedNotification instead
+ */
+class FormattedNotify extends BaseFactory
+{
+       /** @var Database */
+       private $dba;
+       /** @var Repository\Notify */
+       private $notify;
+       /** @var BaseURL */
+       private $baseUrl;
+       /** @var L10n */
+       private $l10n;
+
+       public function __construct(LoggerInterface $logger, Database $dba, Repository\Notify $notification, BaseURL $baseUrl, L10n $l10n)
+       {
+               parent::__construct($logger);
+
+               $this->dba     = $dba;
+               $this->notify  = $notification;
+               $this->baseUrl = $baseUrl;
+               $this->l10n    = $l10n;
+       }
+
+       /**
+        * @param array $formattedItem The return of $this->formatItem
+        *
+        * @return ValueObject\FormattedNotify
+        */
+       private function createFromFormattedItem(array $formattedItem): ValueObject\FormattedNotify
+       {
+               // Transform the different types of notification in a usable array
+               switch ($formattedItem['verb'] ?? '') {
+                       case Activity::LIKE:
+                               return new ValueObject\FormattedNotify(
+                                       'like',
+                                       $this->baseUrl->get(true) . '/display/' . $formattedItem['parent-guid'],
+                                       $formattedItem['author-avatar'],
+                                       $formattedItem['author-link'],
+                                       $this->l10n->t("%s liked %s's post", $formattedItem['author-name'], $formattedItem['parent-author-name']),
+                                       $formattedItem['when'],
+                                       $formattedItem['ago'],
+                                       $formattedItem['seen']
+                               );
+
+                       case Activity::DISLIKE:
+                               return new ValueObject\FormattedNotify(
+                                       'dislike',
+                                       $this->baseUrl->get(true) . '/display/' . $formattedItem['parent-guid'],
+                                       $formattedItem['author-avatar'],
+                                       $formattedItem['author-link'],
+                                       $this->l10n->t("%s disliked %s's post", $formattedItem['author-name'], $formattedItem['parent-author-name']),
+                                       $formattedItem['when'],
+                                       $formattedItem['ago'],
+                                       $formattedItem['seen']
+                               );
+
+                       case Activity::ATTEND:
+                               return new ValueObject\FormattedNotify(
+                                       'attend',
+                                       $this->baseUrl->get(true) . '/display/' . $formattedItem['parent-guid'],
+                                       $formattedItem['author-avatar'],
+                                       $formattedItem['author-link'],
+                                       $this->l10n->t("%s is attending %s's event", $formattedItem['author-name'], $formattedItem['parent-author-name']),
+                                       $formattedItem['when'],
+                                       $formattedItem['ago'],
+                                       $formattedItem['seen']
+                               );
+
+                       case Activity::ATTENDNO:
+                               return new ValueObject\FormattedNotify(
+                                       'attendno',
+                                       $this->baseUrl->get(true) . '/display/' . $formattedItem['parent-guid'],
+                                       $formattedItem['author-avatar'],
+                                       $formattedItem['author-link'],
+                                       $this->l10n->t("%s is not attending %s's event", $formattedItem['author-name'], $formattedItem['parent-author-name']),
+                                       $formattedItem['when'],
+                                       $formattedItem['ago'],
+                                       $formattedItem['seen']
+                               );
+
+                       case Activity::ATTENDMAYBE:
+                               return new ValueObject\FormattedNotify(
+                                       'attendmaybe',
+                                       $this->baseUrl->get(true) . '/display/' . $formattedItem['parent-guid'],
+                                       $formattedItem['author-avatar'],
+                                       $formattedItem['author-link'],
+                                       $this->l10n->t("%s may attending %s's event", $formattedItem['author-name'], $formattedItem['parent-author-name']),
+                                       $formattedItem['when'],
+                                       $formattedItem['ago'],
+                                       $formattedItem['seen']
+                               );
+
+                       case Activity::FRIEND:
+                               if (!isset($formattedItem['object'])) {
+                                       return new ValueObject\FormattedNotify(
+                                               'friend',
+                                               $formattedItem['link'],
+                                               $formattedItem['image'],
+                                               $formattedItem['url'],
+                                               $formattedItem['text'],
+                                               $formattedItem['when'],
+                                               $formattedItem['ago'],
+                                               $formattedItem['seen']
+                                       );
+                               }
+
+                               $xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
+                               $obj     = XML::parseString($xmlHead . $formattedItem['object']);
+
+                               $formattedItem['fname'] = $obj->title;
+
+                               return new ValueObject\FormattedNotify(
+                                       'friend',
+                                       $this->baseUrl->get(true) . '/display/' . $formattedItem['parent-guid'],
+                                       $formattedItem['author-avatar'],
+                                       $formattedItem['author-link'],
+                                       $this->l10n->t("%s is now friends with %s", $formattedItem['author-name'], $formattedItem['fname']),
+                                       $formattedItem['when'],
+                                       $formattedItem['ago'],
+                                       $formattedItem['seen']
+                               );
+
+                       default:
+                               return new ValueObject\FormattedNotify(
+                                       $formattedItem['label'] ?? '',
+                                       $formattedItem['link'] ?? '',
+                                       $formattedItem['image'] ?? '',
+                                       $formattedItem['url'] ?? '',
+                                       $formattedItem['text'] ?? '',
+                                       $formattedItem['when'] ?? '',
+                                       $formattedItem['ago'] ?? '',
+                                       $formattedItem['seen'] ?? false
+                               );
+               }
+       }
+
+       /**
+        * Get system notifications
+        *
+        * @param bool $seen          False => only include notifications into the query
+        *                            which aren't marked as "seen"
+        * @param int  $start         Start the query at this point
+        * @param int  $limit         Maximum number of query results
+        *
+        * @return FormattedNotifies
+        */
+       public function getSystemList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT): FormattedNotifies
+       {
+               $conditions = [];
+               if (!$seen) {
+                       $conditions['seen'] = false;
+               }
+
+               $params          = [];
+               $params['order'] = ['date' => 'DESC'];
+               $params['limit'] = [$start, $limit];
+
+               $formattedNotifications = new FormattedNotifies();
+               try {
+                       $Notifies = $this->notify->selectForUser(local_user(), $conditions, $params);
+
+                       foreach ($Notifies as $Notify) {
+                               $formattedNotifications[] = new ValueObject\FormattedNotify(
+                                       'notification',
+                                       $this->baseUrl->get(true) . '/notification/' . $Notify->id,
+                                       Contact::getAvatarUrlForUrl($Notify->url, $Notify->uid, Proxy::SIZE_MICRO),
+                                       $Notify->url,
+                                       strip_tags(BBCode::toPlaintext($Notify->msg)),
+                                       DateTimeFormat::local($Notify->date->format(DateTimeFormat::MYSQL), 'r'),
+                                       Temporal::getRelativeDate($Notify->date->format(DateTimeFormat::MYSQL)),
+                                       $Notify->seen
+                               );
+                       }
+               } catch (Exception $e) {
+                       $this->logger->warning('Select failed.', ['conditions' => $conditions, 'exception' => $e]);
+               }
+
+               return $formattedNotifications;
+       }
+
+       /**
+        * Get network notifications
+        *
+        * @param bool $seen          False => only include notifications into the query
+        *                            which aren't marked as "seen"
+        * @param int  $start         Start the query at this point
+        * @param int  $limit         Maximum number of query results
+        *
+        * @return FormattedNotifies
+        */
+       public function getNetworkList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT): FormattedNotifies
+       {
+               $condition = ['wall' => false, 'uid' => local_user()];
+
+               if (!$seen) {
+                       $condition['unseen'] = true;
+               }
+
+               $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
+                       'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'gravity'];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
+
+               $formattedNotifications = new FormattedNotifies();
+
+               try {
+                       $userPosts = Post::selectForUser(local_user(), $fields, $condition, $params);
+                       while ($userPost = $this->dba->fetch($userPosts)) {
+                               $formattedNotifications[] = $this->createFromFormattedItem($this->formatItem($userPost));
+                       }
+               } catch (Exception $e) {
+                       $this->logger->warning('Select failed.', ['condition' => $condition, 'exception' => $e]);
+               }
+
+               return $formattedNotifications;
+       }
+
+       /**
+        * Get personal notifications
+        *
+        * @param bool $seen          False => only include notifications into the query
+        *                            which aren't marked as "seen"
+        * @param int  $start         Start the query at this point
+        * @param int  $limit         Maximum number of query results
+        *
+        * @return FormattedNotifies
+        */
+       public function getPersonalList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT): FormattedNotifies
+       {
+               $condition = ['wall' => false, 'uid' => local_user(), 'author-id' => public_contact()];
+
+               if (!$seen) {
+                       $condition['unseen'] = true;
+               }
+
+               $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
+                       'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'gravity'];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
+
+               $formattedNotifications = new FormattedNotifies();
+
+               try {
+                       $userPosts = Post::selectForUser(local_user(), $fields, $condition, $params);
+                       while ($userPost = $this->dba->fetch($userPosts)) {
+                               $formattedNotifications[] = $this->createFromFormattedItem($this->formatItem($userPost));
+                       }
+               } catch (Exception $e) {
+                       $this->logger->warning('Select failed.', ['conditions' => $condition, 'exception' => $e]);
+               }
+
+               return $formattedNotifications;
+       }
+
+       /**
+        * Get home notifications
+        *
+        * @param bool $seen          False => only include notifications into the query
+        *                            which aren't marked as "seen"
+        * @param int  $start         Start the query at this point
+        * @param int  $limit         Maximum number of query results
+        *
+        * @return FormattedNotifies
+        */
+       public function getHomeList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT): FormattedNotifies
+       {
+               $condition = ['wall' => true, 'uid' => local_user()];
+
+               if (!$seen) {
+                       $condition['unseen'] = true;
+               }
+
+               $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
+                       'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'gravity'];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
+
+               $formattedNotifications = new FormattedNotifies();
+
+               try {
+                       $userPosts = Post::selectForUser(local_user(), $fields, $condition, $params);
+                       while ($userPost = $this->dba->fetch($userPosts)) {
+                               $formattedItem = $this->formatItem($userPost);
+
+                               // Overwrite specific fields, not default item format
+                               $formattedItem['label'] = 'comment';
+                               $formattedItem['text']  = $this->l10n->t("%s commented on %s's post", $formattedItem['author-name'], $formattedItem['parent-author-name']);
+
+                               $formattedNotifications[] = $this->createFromFormattedItem($formattedItem);
+                       }
+               } catch (Exception $e) {
+                       $this->logger->warning('Select failed.', ['conditions' => $condition, 'exception' => $e]);
+               }
+
+               return $formattedNotifications;
+       }
+
+       /**
+        * Format the item query in a usable array
+        *
+        * @param array $item The item from the db query
+        *
+        * @return array The item, extended with the notification-specific information
+        *
+        * @throws InternalServerErrorException
+        * @throws Exception
+        */
+       private function formatItem(array $item): array
+       {
+               $item['seen'] = !($item['unseen'] > 0);
+
+               // For feed items we use the user's contact, since the avatar is mostly self choosen.
+               if (!empty($item['network']) && $item['network'] == Protocol::FEED) {
+                       $item['author-avatar'] = $item['contact-avatar'];
+               }
+
+               $item['label'] = (($item['gravity'] == GRAVITY_PARENT) ? 'post' : 'comment');
+               $item['link']  = $this->baseUrl->get(true) . '/display/' . $item['parent-guid'];
+               $item['image'] = $item['author-avatar'];
+               $item['url']   = $item['author-link'];
+               $item['when']  = DateTimeFormat::local($item['created'], 'r');
+               $item['ago']   = Temporal::getRelativeDate($item['created']);
+               $item['text']  = (($item['gravity'] == GRAVITY_PARENT)
+                       ? $this->l10n->t("%s created a new post", $item['author-name'])
+                       : $this->l10n->t("%s commented on %s's post", $item['author-name'], $item['parent-author-name']));
+
+               return $item;
+       }
+}
index fbc61447024504dfbf9d8389e9c43bca731df9f7..d6c777e6f245e6436910d1fcb836712e7a35f7b7 100644 (file)
@@ -26,6 +26,9 @@ use Friendica\Capabilities\ICanCreateFromTableRow;
 use Friendica\Content\Text\BBCode;
 use GuzzleHttp\Psr7\Uri;
 
+/**
+ * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Factory\Notification instead
+ */
 class Notify extends BaseFactory implements ICanCreateFromTableRow
 {
        public function createFromTableRow(array $row): \Friendica\Navigation\Notifications\Entity\Notify
index 6d56258b37baa2b45e2888c88a986f70e19352df..959418bbfa427411c81095edd24c020094fe0105 100644 (file)
@@ -41,6 +41,9 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
 use Psr\Log\LoggerInterface;
 
+/**
+ * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Repository\Notification instead
+ */
 class Notify extends BaseRepository
 {
        /** @var Factory\Notify  */
diff --git a/src/Navigation/Notifications/ValueObject/FormattedNotify.php b/src/Navigation/Notifications/ValueObject/FormattedNotify.php
new file mode 100644 (file)
index 0000000..ac0db65
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Friendica\Navigation\Notifications\ValueObject;
+
+use Friendica\BaseDataTransferObject;
+
+/**
+ * A view-only object for printing item notifications to the frontend
+ *
+ * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\ValueObject\FormattedNotification instead
+ */
+class FormattedNotify extends BaseDataTransferObject
+{
+       const SYSTEM   = 'system';
+       const PERSONAL = 'personal';
+       const NETWORK  = 'network';
+       const INTRO    = 'intro';
+       const HOME     = 'home';
+
+       /** @var string */
+       protected $label = '';
+       /** @var string */
+       protected $link = '';
+       /** @var string */
+       protected $image = '';
+       /** @var string */
+       protected $url = '';
+       /** @var string */
+       protected $text = '';
+       /** @var string */
+       protected $when = '';
+       /** @var string */
+       protected $ago = '';
+       /** @var boolean */
+       protected $seen = false;
+
+       public function __construct(string $label, string $link, string $image, string $url, string $text, string $when, string $ago, bool $seen)
+       {
+               $this->label = $label ?? '';
+               $this->link  = $link  ?? '';
+               $this->image = $image ?? '';
+               $this->url   = $url   ?? '';
+               $this->text  = $text  ?? '';
+               $this->when  = $when  ?? '';
+               $this->ago   = $ago   ?? '';
+               $this->seen  = $seen  ?? false;
+       }
+}
index f7e02b10b942ee4c74bbd89bbfcc90350522ac10..8963b1df604e5215f64daa56e9eee3658f948ec2 100644 (file)
@@ -904,7 +904,7 @@ return [
                ]
        ],
        "notify" => [
-               "comment" => "notifications",
+               "comment" => "[Deprecated] User notifications",
                "fields" => [
                        "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
                        "type" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""],