]> git.mxchange.org Git - friendica.git/commitdiff
Rename classes
authornupplaPhil <admin@philipp.info>
Sun, 26 Jan 2020 19:30:24 +0000 (20:30 +0100)
committernupplaPhil <admin@philipp.info>
Sun, 26 Jan 2020 19:30:24 +0000 (20:30 +0100)
- Repository/Model Notification => Notify
- Factory/Object Notification => Notification

17 files changed:
include/api.php
include/enotify.php
mod/ping.php
src/Collection/Notifications.php [deleted file]
src/Collection/Notifies.php [new file with mode: 0644]
src/DI.php
src/Factory/Notification/Introduction.php [new file with mode: 0644]
src/Factory/Notification/IntroductionFactory.php [deleted file]
src/Factory/Notification/Notification.php [new file with mode: 0644]
src/Factory/Notification/NotificationFactory.php [deleted file]
src/Model/Notification.php [deleted file]
src/Model/Notify.php [new file with mode: 0644]
src/Module/Notifications/Introductions.php
src/Module/Notifications/Notification.php
src/Module/Notifications/Notifications.php
src/Repository/Notification.php [deleted file]
src/Repository/Notify.php [new file with mode: 0644]

index 0729c2a0f89c88712bd4a3e329c3c44596a25d7a..f43ee2d1bae693903319081120d9e0aeee31f3f8 100644 (file)
@@ -23,7 +23,7 @@ use Friendica\Model\Contact;
 use Friendica\Model\Group;
 use Friendica\Model\Item;
 use Friendica\Model\Mail;
-use Friendica\Model\Notification;
+use Friendica\Model\Notify;
 use Friendica\Model\Photo;
 use Friendica\Model\Profile;
 use Friendica\Model\User;
@@ -5907,7 +5907,7 @@ function api_friendica_notification($type)
                throw new BadRequestException("Invalid argument count");
        }
 
-       $notifications = DI::notification()->select(['uid' => api_user()], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]);
+       $notifications = DI::notify()->select(['uid' => api_user()], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]);
 
        if ($type == "xml") {
                $xmlnotes = false;
@@ -5955,10 +5955,10 @@ function api_friendica_notification_seen($type)
        $id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
 
        try {
-               $notification = DI::notification()->getByID($id);
+               $notification = DI::notify()->getByID($id);
                $notification->setSeen();
 
-               if ($notification->otype === Notification::OTYPE_ITEM) {
+               if ($notification->otype === Notify::OTYPE_ITEM) {
                        $item = Item::selectFirstForUser(api_user(), [], ['id' => $notification->iid, 'uid' => api_user()]);
                        if (DBA::isResult($item)) {
                                // we found the item, return it to the user
index f509367efbd8edd21cf2cf80351980c4dfdac089..144460693d1fc58ec2aea0df3bf1e5cc172f5fcf 100644 (file)
@@ -12,7 +12,7 @@ use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Item;
 use Friendica\Model\ItemContent;
-use Friendica\Model\Notification;
+use Friendica\Model\Notify;
 use Friendica\Model\User;
 use Friendica\Model\UserItem;
 use Friendica\Protocol\Activity;
@@ -161,7 +161,7 @@ function notification($params)
 
                // if it's a post figure out who's post it is.
                $item = null;
-               if ($params['otype'] === Notification::OTYPE_ITEM && $parent_id) {
+               if ($params['otype'] === Notify::OTYPE_ITEM && $parent_id) {
                        $item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id, 'deleted' => false]);
                }
 
@@ -483,7 +483,7 @@ function notification($params)
        $notify_id = 0;
 
        if ($show_in_notification_page) {
-               $notification = DI::notification()->insert([
+               $notification = DI::notify()->insert([
                        'name'   => $params['source_name'],
                        'url'    => $params['source_link'],
                        'photo'  => $params['source_photo'],
@@ -498,7 +498,7 @@ function notification($params)
                $notification->link = DI::baseUrl() . '/notification/view/' . $notification->id;
                $notification->msg  = Renderer::replaceMacros($epreamble, ['$itemlink' => $notification->link]);
 
-               DI::notification()->update($notification);
+               DI::notify()->update($notification);
 
                $itemlink  = $notification->link;
                $notify_id = $notification->id;
index a786d379f2493f911317a8432514b4f3a50a1e60..dd57ba34d68eb3308fb3ca8847b038333410723b 100644 (file)
@@ -433,7 +433,7 @@ function ping_get_notifications($uid)
                                $notification["message"] = $notification["msg_cache"];
                        } else {
                                $notification["name"] = strip_tags(BBCode::convert($notification["name"]));
-                               $notification["message"] = Friendica\Model\Notification::formatMessage($notification["name"], strip_tags(BBCode::convert($notification["msg"])));
+                               $notification["message"] = Friendica\Model\Notify::formatMessage($notification["name"], strip_tags(BBCode::convert($notification["msg"])));
 
                                q(
                                        "UPDATE `notify` SET `name_cache` = '%s', `msg_cache` = '%s' WHERE `id` = %d",
diff --git a/src/Collection/Notifications.php b/src/Collection/Notifications.php
deleted file mode 100644 (file)
index 1c04bdf..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-
-namespace Friendica\Collection;
-
-use Friendica\BaseCollection;
-use Friendica\Model;
-
-class Notifications extends BaseCollection
-{
-       /**
-        * @return Model\Notification
-        */
-       public function current()
-       {
-               return parent::current();
-       }
-}
diff --git a/src/Collection/Notifies.php b/src/Collection/Notifies.php
new file mode 100644 (file)
index 0000000..0d64ee7
--- /dev/null
@@ -0,0 +1,17 @@
+<?php
+
+namespace Friendica\Collection;
+
+use Friendica\BaseCollection;
+use Friendica\Model;
+
+class Notifies extends BaseCollection
+{
+       /**
+        * @return Model\Notify
+        */
+       public function current()
+       {
+               return parent::current();
+       }
+}
index 8f80bf68dde12bc765462f790b7eb5d66a912558..3034bd971c6c371f06a905d342b2a6be6565710f 100644 (file)
@@ -245,19 +245,19 @@ abstract class DI
        }
 
        /**
-        * @return \Friendica\Factory\Notification\NotificationFactory
+        * @return \Friendica\Factory\Notification\Notification
         */
-       public static function factNotification()
+       public static function notification()
        {
-               return self::$dice->create(Factory\Notification\NotificationFactory::class);
+               return self::$dice->create(Factory\Notification\Notification::class);
        }
 
        /**
-        * @return \Friendica\Factory\Notification\IntroductionFactory
+        * @return \Friendica\Factory\Notification\Introduction
         */
-       public static function factNotIntro()
+       public static function notificationIntro()
        {
-               return self::$dice->create(Factory\Notification\IntroductionFactory::class);
+               return self::$dice->create(Factory\Notification\Introduction::class);
        }
 
        //
@@ -273,11 +273,11 @@ abstract class DI
        }
 
        /**
-        * @return Repository\Notification
+        * @return Repository\Notify
         */
-       public static function notification()
+       public static function notify()
        {
-               return self::$dice->create(Repository\Notification::class);
+               return self::$dice->create(Repository\Notify::class);
        }
 
        /**
diff --git a/src/Factory/Notification/Introduction.php b/src/Factory/Notification/Introduction.php
new file mode 100644 (file)
index 0000000..6b192ec
--- /dev/null
@@ -0,0 +1,211 @@
+<?php
+
+namespace Friendica\Factory\Notification;
+
+use Exception;
+use Friendica\App;
+use Friendica\App\BaseURL;
+use Friendica\BaseFactory;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig\IPConfig;
+use Friendica\Core\Protocol;
+use Friendica\Core\Session\ISession;
+use Friendica\Database\Database;
+use Friendica\Model\Contact;
+use Friendica\Module\BaseNotifications;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Object;
+use Friendica\Util\Proxy;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Factory for creating notification objects based on introductions
+ * Currently, there are two main types of introduction based notifications:
+ * - Friend suggestion
+ * - Friend/Follower request
+ */
+class Introduction extends BaseFactory
+{
+       /** @var Database */
+       private $dba;
+       /** @var BaseURL */
+       private $baseUrl;
+       /** @var L10n */
+       private $l10n;
+       /** @var IPConfig */
+       private $pConfig;
+       /** @var ISession */
+       private $session;
+       /** @var string */
+       private $nick;
+
+       public function __construct(LoggerInterface $logger, Database $dba, BaseURL $baseUrl, L10n $l10n, App $app, IPConfig $pConfig, ISession $session)
+       {
+               parent::__construct($logger);
+
+               $this->dba          = $dba;
+               $this->baseUrl      = $baseUrl;
+               $this->l10n         = $l10n;
+               $this->pConfig      = $pConfig;
+               $this->session      = $session;
+               $this->nick         = $app->user['nickname'] ?? '';
+       }
+
+       /**
+        * Get introductions
+        *
+        * @param bool $all     If false only include introductions into the query
+        *                      which aren't marked as ignored
+        * @param int  $start   Start the query at this point
+        * @param int  $limit   Maximum number of query results
+        * @param int  $id      When set, only the introduction with this id is displayed
+        *
+        * @return Object\Notification\Introduction[]
+        */
+       public function getList(bool $all = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT, int $id = 0)
+       {
+               $sql_extra     = "";
+
+               if (empty($id)) {
+                       if (!$all) {
+                               $sql_extra = " AND NOT `ignore` ";
+                       }
+
+                       $sql_extra .= " AND NOT `intro`.`blocked` ";
+               } else {
+                       $sql_extra = sprintf(" AND `intro`.`id` = %d ", intval($id));
+               }
+
+               $formattedNotifications = [];
+
+               try {
+                       /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
+                       $stmtNotifications = $this->dba->p(
+                               "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
+                               `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
+                               `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
+                               `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
+                               `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
+                               `gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
+                       FROM `intro`
+                               LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
+                               LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
+                               LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
+                       WHERE `intro`.`uid` = ? $sql_extra
+                       LIMIT ?, ?",
+                               $_SESSION['uid'],
+                               $start,
+                               $limit
+                       );
+
+                       while ($notification = $this->dba->fetch($stmtNotifications)) {
+                               // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
+                               // We have to distinguish between these two because they use different data.
+                               // Contact suggestions
+                               if ($notification['fid'] ?? '') {
+                                       $return_addr = bin2hex($this->nick . '@' .
+                                                              $this->baseUrl->getHostName() .
+                                                              (($this->baseUrl->getURLPath()) ? '/' . $this->baseUrl->getURLPath() : ''));
+
+                                       $formattedNotifications[] = new Introduction([
+                                               'label'          => 'friend_suggestion',
+                                               'str_type'       => $this->l10n->t('Friend Suggestion'),
+                                               'intro_id'       => $notification['intro_id'],
+                                               'madeby'         => $notification['name'],
+                                               'madeby_url'     => $notification['url'],
+                                               'madeby_zrl'     => Contact::magicLink($notification['url']),
+                                               'madeby_addr'    => $notification['addr'],
+                                               'contact_id'     => $notification['contact-id'],
+                                               'photo'          => (!empty($notification['fphoto']) ? Proxy::proxifyUrl($notification['fphoto'], false, Proxy::SIZE_SMALL) : "images/person-300.jpg"),
+                                               'name'           => $notification['fname'],
+                                               'url'            => $notification['furl'],
+                                               'zrl'            => Contact::magicLink($notification['furl']),
+                                               'hidden'         => $notification['hidden'] == 1,
+                                               'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
+                                               'note'           => $notification['note'],
+                                               'request'        => $notification['frequest'] . '?addr=' . $return_addr]);
+
+                                       // Normal connection requests
+                               } else {
+                                       $notification = $this->getMissingData($notification);
+
+                                       if (empty($notification['url'])) {
+                                               continue;
+                                       }
+
+                                       // Don't show these data until you are connected. Diaspora is doing the same.
+                                       if ($notification['gnetwork'] === Protocol::DIASPORA) {
+                                               $notification['glocation'] = "";
+                                               $notification['gabout']    = "";
+                                               $notification['ggender']   = "";
+                                       }
+
+                                       $formattedNotifications[] = new Introduction([
+                                               'label'          => (($notification['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'),
+                                               'str_type'       => (($notification['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')),
+                                               'dfrn_id'        => $notification['issued-id'],
+                                               'uid'            => $this->session->get('uid'),
+                                               'intro_id'       => $notification['intro_id'],
+                                               'contact_id'     => $notification['contact-id'],
+                                               'photo'          => (!empty($notification['photo']) ? Proxy::proxifyUrl($notification['photo'], false, Proxy::SIZE_SMALL) : "images/person-300.jpg"),
+                                               'name'           => $notification['name'],
+                                               'location'       => BBCode::convert($notification['glocation'], false),
+                                               'about'          => BBCode::convert($notification['gabout'], false),
+                                               'keywords'       => $notification['gkeywords'],
+                                               'gender'         => $notification['ggender'],
+                                               'hidden'         => $notification['hidden'] == 1,
+                                               'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
+                                               'url'            => $notification['url'],
+                                               'zrl'            => Contact::magicLink($notification['url']),
+                                               'addr'           => $notification['gaddr'],
+                                               'network'        => $notification['gnetwork'],
+                                               'knowyou'        => $notification['knowyou'],
+                                               'note'           => $notification['note'],
+                                       ]);
+                               }
+                       }
+               } catch (Exception $e) {
+                       $this->logger->warning('Select failed.', ['uid' => $_SESSION['uid'], 'exception' => $e]);
+               }
+
+               return $formattedNotifications;
+       }
+
+       /**
+        * Check for missing contact data and try to fetch the data from
+        * from other sources
+        *
+        * @param array $intro The input array with the intro data
+        *
+        * @return array The array with the intro data
+        *
+        * @throws InternalServerErrorException
+        */
+       private function getMissingData(array $intro)
+       {
+               // If the network and the addr isn't available from the gcontact
+               // table entry, take the one of the contact table entry
+               if (empty($intro['gnetwork']) && !empty($intro['network'])) {
+                       $intro['gnetwork'] = $intro['network'];
+               }
+               if (empty($intro['gaddr']) && !empty($intro['addr'])) {
+                       $intro['gaddr'] = $intro['addr'];
+               }
+
+               // If the network and addr is still not available
+               // get the missing data data from other sources
+               if (empty($intro['gnetwork']) || empty($intro['gaddr'])) {
+                       $ret = Contact::getDetailsByURL($intro['url']);
+
+                       if (empty($intro['gnetwork']) && !empty($ret['network'])) {
+                               $intro['gnetwork'] = $ret['network'];
+                       }
+                       if (empty($intro['gaddr']) && !empty($ret['addr'])) {
+                               $intro['gaddr'] = $ret['addr'];
+                       }
+               }
+
+               return $intro;
+       }
+}
diff --git a/src/Factory/Notification/IntroductionFactory.php b/src/Factory/Notification/IntroductionFactory.php
deleted file mode 100644 (file)
index 0988821..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-<?php
-
-namespace Friendica\Factory\Notification;
-
-use Exception;
-use Friendica\App;
-use Friendica\App\BaseURL;
-use Friendica\BaseFactory;
-use Friendica\Content\Text\BBCode;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig\IPConfig;
-use Friendica\Core\Protocol;
-use Friendica\Core\Session\ISession;
-use Friendica\Database\Database;
-use Friendica\Model\Contact;
-use Friendica\Module\BaseNotifications;
-use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Object\Notification\Introduction;
-use Friendica\Util\Proxy;
-use Psr\Log\LoggerInterface;
-
-/**
- * Factory for creating notification objects based on introductions
- * Currently, there are two main types of introduction based notifications:
- * - Friend suggestion
- * - Friend/Follower request
- */
-class IntroductionFactory extends BaseFactory
-{
-       /** @var Database */
-       private $dba;
-       /** @var BaseURL */
-       private $baseUrl;
-       /** @var L10n */
-       private $l10n;
-       /** @var IPConfig */
-       private $pConfig;
-       /** @var ISession */
-       private $session;
-       /** @var string */
-       private $nick;
-
-       public function __construct(LoggerInterface $logger, Database $dba, BaseURL $baseUrl, L10n $l10n, App $app, IPConfig $pConfig, ISession $session)
-       {
-               parent::__construct($logger);
-
-               $this->dba          = $dba;
-               $this->baseUrl      = $baseUrl;
-               $this->l10n         = $l10n;
-               $this->pConfig      = $pConfig;
-               $this->session      = $session;
-               $this->nick         = $app->user['nickname'] ?? '';
-       }
-
-       /**
-        * Get introductions
-        *
-        * @param bool $all     If false only include introductions into the query
-        *                      which aren't marked as ignored
-        * @param int  $start   Start the query at this point
-        * @param int  $limit   Maximum number of query results
-        * @param int  $id      When set, only the introduction with this id is displayed
-        *
-        * @return Introduction[]
-        */
-       public function getList(bool $all = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT, int $id = 0)
-       {
-               $sql_extra     = "";
-
-               if (empty($id)) {
-                       if (!$all) {
-                               $sql_extra = " AND NOT `ignore` ";
-                       }
-
-                       $sql_extra .= " AND NOT `intro`.`blocked` ";
-               } else {
-                       $sql_extra = sprintf(" AND `intro`.`id` = %d ", intval($id));
-               }
-
-               $formattedNotifications = [];
-
-               try {
-                       /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
-                       $stmtNotifications = $this->dba->p(
-                               "SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
-                               `fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
-                               `fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
-                               `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
-                               `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
-                               `gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
-                       FROM `intro`
-                               LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
-                               LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
-                               LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
-                       WHERE `intro`.`uid` = ? $sql_extra
-                       LIMIT ?, ?",
-                               $_SESSION['uid'],
-                               $start,
-                               $limit
-                       );
-
-                       while ($notification = $this->dba->fetch($stmtNotifications)) {
-                               // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
-                               // We have to distinguish between these two because they use different data.
-                               // Contact suggestions
-                               if ($notification['fid'] ?? '') {
-                                       $return_addr = bin2hex($this->nick . '@' .
-                                                              $this->baseUrl->getHostName() .
-                                                              (($this->baseUrl->getURLPath()) ? '/' . $this->baseUrl->getURLPath() : ''));
-
-                                       $formattedNotifications[] = new Introduction([
-                                               'label'          => 'friend_suggestion',
-                                               'str_type'       => $this->l10n->t('Friend Suggestion'),
-                                               'intro_id'       => $notification['intro_id'],
-                                               'madeby'         => $notification['name'],
-                                               'madeby_url'     => $notification['url'],
-                                               'madeby_zrl'     => Contact::magicLink($notification['url']),
-                                               'madeby_addr'    => $notification['addr'],
-                                               'contact_id'     => $notification['contact-id'],
-                                               'photo'          => (!empty($notification['fphoto']) ? Proxy::proxifyUrl($notification['fphoto'], false, Proxy::SIZE_SMALL) : "images/person-300.jpg"),
-                                               'name'           => $notification['fname'],
-                                               'url'            => $notification['furl'],
-                                               'zrl'            => Contact::magicLink($notification['furl']),
-                                               'hidden'         => $notification['hidden'] == 1,
-                                               'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
-                                               'note'           => $notification['note'],
-                                               'request'        => $notification['frequest'] . '?addr=' . $return_addr]);
-
-                                       // Normal connection requests
-                               } else {
-                                       $notification = $this->getMissingData($notification);
-
-                                       if (empty($notification['url'])) {
-                                               continue;
-                                       }
-
-                                       // Don't show these data until you are connected. Diaspora is doing the same.
-                                       if ($notification['gnetwork'] === Protocol::DIASPORA) {
-                                               $notification['glocation'] = "";
-                                               $notification['gabout']    = "";
-                                               $notification['ggender']   = "";
-                                       }
-
-                                       $formattedNotifications[] = new Introduction([
-                                               'label'          => (($notification['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'),
-                                               'str_type'       => (($notification['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')),
-                                               'dfrn_id'        => $notification['issued-id'],
-                                               'uid'            => $this->session->get('uid'),
-                                               'intro_id'       => $notification['intro_id'],
-                                               'contact_id'     => $notification['contact-id'],
-                                               'photo'          => (!empty($notification['photo']) ? Proxy::proxifyUrl($notification['photo'], false, Proxy::SIZE_SMALL) : "images/person-300.jpg"),
-                                               'name'           => $notification['name'],
-                                               'location'       => BBCode::convert($notification['glocation'], false),
-                                               'about'          => BBCode::convert($notification['gabout'], false),
-                                               'keywords'       => $notification['gkeywords'],
-                                               'gender'         => $notification['ggender'],
-                                               'hidden'         => $notification['hidden'] == 1,
-                                               'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
-                                               'url'            => $notification['url'],
-                                               'zrl'            => Contact::magicLink($notification['url']),
-                                               'addr'           => $notification['gaddr'],
-                                               'network'        => $notification['gnetwork'],
-                                               'knowyou'        => $notification['knowyou'],
-                                               'note'           => $notification['note'],
-                                       ]);
-                               }
-                       }
-               } catch (Exception $e) {
-                       $this->logger->warning('Select failed.', ['uid' => $_SESSION['uid'], 'exception' => $e]);
-               }
-
-               return $formattedNotifications;
-       }
-
-       /**
-        * Check for missing contact data and try to fetch the data from
-        * from other sources
-        *
-        * @param array $intro The input array with the intro data
-        *
-        * @return array The array with the intro data
-        *
-        * @throws InternalServerErrorException
-        */
-       private function getMissingData(array $intro)
-       {
-               // If the network and the addr isn't available from the gcontact
-               // table entry, take the one of the contact table entry
-               if (empty($intro['gnetwork']) && !empty($intro['network'])) {
-                       $intro['gnetwork'] = $intro['network'];
-               }
-               if (empty($intro['gaddr']) && !empty($intro['addr'])) {
-                       $intro['gaddr'] = $intro['addr'];
-               }
-
-               // If the network and addr is still not available
-               // get the missing data data from other sources
-               if (empty($intro['gnetwork']) || empty($intro['gaddr'])) {
-                       $ret = Contact::getDetailsByURL($intro['url']);
-
-                       if (empty($intro['gnetwork']) && !empty($ret['network'])) {
-                               $intro['gnetwork'] = $ret['network'];
-                       }
-                       if (empty($intro['gaddr']) && !empty($ret['addr'])) {
-                               $intro['gaddr'] = $ret['addr'];
-                       }
-               }
-
-               return $intro;
-       }
-}
diff --git a/src/Factory/Notification/Notification.php b/src/Factory/Notification/Notification.php
new file mode 100644 (file)
index 0000000..5f2c223
--- /dev/null
@@ -0,0 +1,355 @@
+<?php
+
+namespace Friendica\Factory\Notification;
+
+use Exception;
+use Friendica\App;
+use Friendica\App\BaseURL;
+use Friendica\BaseFactory;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\L10n;
+use Friendica\Core\PConfig\IPConfig;
+use Friendica\Core\Protocol;
+use Friendica\Core\Session\ISession;
+use Friendica\Database\Database;
+use Friendica\Model\Item;
+use Friendica\Module\BaseNotifications;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Protocol\Activity;
+use Friendica\Repository;
+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
+ */
+class Notification extends BaseFactory
+{
+       /** @var Database */
+       private $dba;
+       /** @var Repository\Notify */
+       private $notification;
+       /** @var BaseURL */
+       private $baseUrl;
+       /** @var L10n */
+       private $l10n;
+       /** @var string */
+       private $nurl;
+
+       public function __construct(LoggerInterface $logger, Database $dba, Repository\Notify $notification, BaseURL $baseUrl, L10n $l10n, App $app, IPConfig $pConfig, ISession $session)
+       {
+               parent::__construct($logger);
+
+               $this->dba          = $dba;
+               $this->notification = $notification;
+               $this->baseUrl      = $baseUrl;
+               $this->l10n         = $l10n;
+               $this->nurl         = $app->contact['nurl'] ?? '';
+       }
+
+       /**
+        * Format the item query in an 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)
+       {
+               $item['seen'] = ($item['unseen'] > 0 ? false : true);
+
+               // 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['id'] == $item['parent']) ? 'post' : 'comment');
+               $item['link']  = $this->baseUrl->get(true) . '/display/' . $item['parent-guid'];
+               $item['image'] = Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO);
+               $item['url']   = $item['author-link'];
+               $item['text']  = (($item['id'] == $item['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']));
+               $item['when']  = DateTimeFormat::local($item['created'], 'r');
+               $item['ago']   = Temporal::getRelativeDate($item['created']);
+
+               return $item;
+       }
+
+       /**
+        * @param array $item
+        *
+        * @return \Friendica\Object\Notification\Notification
+        *
+        * @throws InternalServerErrorException
+        */
+       private function createFromItem(array $item)
+       {
+               $item = $this->formatItem($item);
+
+               // Transform the different types of notification in an usable array
+               switch ($item['verb'] ?? '') {
+                       case Activity::LIKE:
+                               return new \Friendica\Object\Notification\Notification([
+                                       'label' => 'like',
+                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+                                       'url'   => $item['author-link'],
+                                       'text'  => $this->l10n->t("%s liked %s's post", $item['author-name'], $item['parent-author-name']),
+                                       'when'  => $item['when'],
+                                       'ago'   => $item['ago'],
+                                       'seen'  => $item['seen']]);
+
+                       case Activity::DISLIKE:
+                               return new \Friendica\Object\Notification\Notification([
+                                       'label' => 'dislike',
+                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+                                       'url'   => $item['author-link'],
+                                       'text'  => $this->l10n->t("%s disliked %s's post", $item['author-name'], $item['parent-author-name']),
+                                       'when'  => $item['when'],
+                                       'ago'   => $item['ago'],
+                                       'seen'  => $item['seen']]);
+
+                       case Activity::ATTEND:
+                               return new \Friendica\Object\Notification\Notification([
+                                       'label' => 'attend',
+                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+                                       'url'   => $item['author-link'],
+                                       'text'  => $this->l10n->t("%s is attending %s's event", $item['author-name'], $item['parent-author-name']),
+                                       'when'  => $item['when'],
+                                       'ago'   => $item['ago'],
+                                       'seen'  => $item['seen']]);
+
+                       case Activity::ATTENDNO:
+                               return new \Friendica\Object\Notification\Notification([
+                                       'label' => 'attendno',
+                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+                                       'url'   => $item['author-link'],
+                                       'text'  => $this->l10n->t("%s is not attending %s's event", $item['author-name'], $item['parent-author-name']),
+                                       'when'  => $item['when'],
+                                       'ago'   => $item['ago'],
+                                       'seen'  => $item['seen']]);
+
+                       case Activity::ATTENDMAYBE:
+                               return new \Friendica\Object\Notification\Notification([
+                                       'label' => 'attendmaybe',
+                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+                                       'url'   => $item['author-link'],
+                                       'text'  => $this->l10n->t("%s may attending %s's event", $item['author-name'], $item['parent-author-name']),
+                                       'when'  => $item['when'],
+                                       'ago'   => $item['ago'],
+                                       'seen'  => $item['seen']]);
+
+                       case Activity::FRIEND:
+                               if (!isset($item['object'])) {
+                                       return new \Friendica\Object\Notification\Notification([
+                                               'label' => 'friend',
+                                               'link'  => $item['link'],
+                                               'image' => $item['image'],
+                                               'url'   => $item['url'],
+                                               'text'  => $item['text'],
+                                               'when'  => $item['when'],
+                                               'ago'   => $item['ago'],
+                                               'seen'  => $item['seen']]);
+                               }
+
+                               $xmlHead       = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
+                               $obj           = XML::parseString($xmlHead . $item['object']);
+                               $item['fname'] = $obj->title;
+
+                               return new \Friendica\Object\Notification\Notification([
+                                       'label' => 'friend',
+                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
+                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
+                                       'url'   => $item['author-link'],
+                                       'text'  => $this->l10n->t("%s is now friends with %s", $item['author-name'], $item['fname']),
+                                       'when'  => $item['when'],
+                                       'ago'   => $item['ago'],
+                                       'seen'  => $item['seen']]);
+
+                       default:
+                               return new \Friendica\Object\Notification\Notification($item);
+                               break;
+               }
+       }
+
+       /**
+        * 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 \Friendica\Module\Notifications\Notification[]
+        */
+       public function getSystemList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
+       {
+               $conditions = ['uid' => local_user()];
+
+               if (!$seen) {
+                       $conditions['seen'] = false;
+               }
+
+               $params          = [];
+               $params['order'] = ['date' => 'DESC'];
+               $params['limit'] = [$start, $limit];
+
+               $formattedNotifications = [];
+               try {
+                       $notifications = $this->notification->select($conditions, $params);
+
+                       foreach ($notifications as $notification) {
+                               $formattedNotifications[] = new \Friendica\Object\Notification\Notification([
+                                       'label' => 'notification',
+                                       'link'  => $this->baseUrl->get(true) . '/notification/view/' . $notification->id,
+                                       'image' => Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO),
+                                       'url'   => $notification->url,
+                                       'text'  => strip_tags(BBCode::convert($notification->msg)),
+                                       'when'  => DateTimeFormat::local($notification->date, 'r'),
+                                       'ago'   => Temporal::getRelativeDate($notification->date),
+                                       'seen'  => $notification->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 \Friendica\Object\Notification\Notification[]
+        */
+       public function getNetworkList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
+       {
+               $conditions = ['wall' => false, 'uid' => local_user()];
+
+               if (!$seen) {
+                       $conditions['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'];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
+
+               $formattedNotifications = [];
+
+               try {
+                       $items = Item::selectForUser(local_user(), $fields, $conditions, $params);
+
+                       while ($item = $this->dba->fetch($items)) {
+                               $formattedNotifications[] = $this->createFromItem($item);
+                       }
+               } catch (Exception $e) {
+                       $this->logger->warning('Select failed.', ['conditions' => $conditions, '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 \Friendica\Object\Notification\Notification[]
+        */
+       public function getPersonalList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
+       {
+               $myUrl    = str_replace('http://', '', $this->nurl);
+               $diaspUrl = str_replace('/profile/', '/u/', $myUrl);
+
+               $condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)",
+                       local_user(), public_contact(), $myUrl . '\\]', $diaspUrl . '\\]'];
+
+               if (!$seen) {
+                       $condition[0] .= " AND `unseen`";
+               }
+
+               $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
+                       'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
+
+               $formattedNotifications = [];
+
+               try {
+                       $items = Item::selectForUser(local_user(), $fields, $condition, $params);
+
+                       while ($item = $this->dba->fetch($items)) {
+                               $formattedNotifications[] = $this->createFromItem($item);
+                       }
+               } 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 \Friendica\Object\Notification\Notification[]
+        */
+       public function getHomeList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
+       {
+               $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'];
+               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
+
+               $formattedNotifications = [];
+
+               try {
+                       $items = Item::selectForUser(local_user(), $fields, $condition, $params);
+
+                       while ($item = $this->dba->fetch($items)) {
+                               $item = $this->formatItem($item);
+
+                               // Overwrite specific fields, not default item format
+                               $item['label'] = 'comment';
+                               $item['text']  = $this->l10n->t("%s commented on %s's post", $item['author-name'], $item['parent-author-name']);
+
+                               $formattedNotifications[] = $this->createFromItem($item);
+                       }
+               } catch (Exception $e) {
+                       $this->logger->warning('Select failed.', ['conditions' => $condition, 'exception' => $e]);
+               }
+
+               return $formattedNotifications;
+       }
+}
diff --git a/src/Factory/Notification/NotificationFactory.php b/src/Factory/Notification/NotificationFactory.php
deleted file mode 100644 (file)
index 05dd200..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-<?php
-
-namespace Friendica\Factory\Notification;
-
-use Exception;
-use Friendica\App;
-use Friendica\App\BaseURL;
-use Friendica\BaseFactory;
-use Friendica\Content\Text\BBCode;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig\IPConfig;
-use Friendica\Core\Protocol;
-use Friendica\Core\Session\ISession;
-use Friendica\Database\Database;
-use Friendica\Model\Item;
-use Friendica\Module\BaseNotifications;
-use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Protocol\Activity;
-use Friendica\Repository\Notification;
-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
- */
-class NotificationFactory extends BaseFactory
-{
-       /** @var Database */
-       private $dba;
-       /** @var Notification */
-       private $notification;
-       /** @var BaseURL */
-       private $baseUrl;
-       /** @var L10n */
-       private $l10n;
-       /** @var string */
-       private $nurl;
-
-       public function __construct(LoggerInterface $logger, Database $dba, Notification $notification, BaseURL $baseUrl, L10n $l10n, App $app, IPConfig $pConfig, ISession $session)
-       {
-               parent::__construct($logger);
-
-               $this->dba          = $dba;
-               $this->notification = $notification;
-               $this->baseUrl      = $baseUrl;
-               $this->l10n         = $l10n;
-               $this->nurl         = $app->contact['nurl'] ?? '';
-       }
-
-       /**
-        * Format the item query in an 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)
-       {
-               $item['seen'] = ($item['unseen'] > 0 ? false : true);
-
-               // 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['id'] == $item['parent']) ? 'post' : 'comment');
-               $item['link']  = $this->baseUrl->get(true) . '/display/' . $item['parent-guid'];
-               $item['image'] = Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO);
-               $item['url']   = $item['author-link'];
-               $item['text']  = (($item['id'] == $item['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']));
-               $item['when']  = DateTimeFormat::local($item['created'], 'r');
-               $item['ago']   = Temporal::getRelativeDate($item['created']);
-
-               return $item;
-       }
-
-       /**
-        * @param array $item
-        *
-        * @return \Friendica\Object\Notification\Notification
-        *
-        * @throws InternalServerErrorException
-        */
-       private function createFromItem(array $item)
-       {
-               $item = $this->formatItem($item);
-
-               // Transform the different types of notification in an usable array
-               switch ($item['verb'] ?? '') {
-                       case Activity::LIKE:
-                               return new \Friendica\Object\Notification\Notification([
-                                       'label' => 'like',
-                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
-                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
-                                       'url'   => $item['author-link'],
-                                       'text'  => $this->l10n->t("%s liked %s's post", $item['author-name'], $item['parent-author-name']),
-                                       'when'  => $item['when'],
-                                       'ago'   => $item['ago'],
-                                       'seen'  => $item['seen']]);
-
-                       case Activity::DISLIKE:
-                               return new \Friendica\Object\Notification\Notification([
-                                       'label' => 'dislike',
-                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
-                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
-                                       'url'   => $item['author-link'],
-                                       'text'  => $this->l10n->t("%s disliked %s's post", $item['author-name'], $item['parent-author-name']),
-                                       'when'  => $item['when'],
-                                       'ago'   => $item['ago'],
-                                       'seen'  => $item['seen']]);
-
-                       case Activity::ATTEND:
-                               return new \Friendica\Object\Notification\Notification([
-                                       'label' => 'attend',
-                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
-                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
-                                       'url'   => $item['author-link'],
-                                       'text'  => $this->l10n->t("%s is attending %s's event", $item['author-name'], $item['parent-author-name']),
-                                       'when'  => $item['when'],
-                                       'ago'   => $item['ago'],
-                                       'seen'  => $item['seen']]);
-
-                       case Activity::ATTENDNO:
-                               return new \Friendica\Object\Notification\Notification([
-                                       'label' => 'attendno',
-                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
-                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
-                                       'url'   => $item['author-link'],
-                                       'text'  => $this->l10n->t("%s is not attending %s's event", $item['author-name'], $item['parent-author-name']),
-                                       'when'  => $item['when'],
-                                       'ago'   => $item['ago'],
-                                       'seen'  => $item['seen']]);
-
-                       case Activity::ATTENDMAYBE:
-                               return new \Friendica\Object\Notification\Notification([
-                                       'label' => 'attendmaybe',
-                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
-                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
-                                       'url'   => $item['author-link'],
-                                       'text'  => $this->l10n->t("%s may attending %s's event", $item['author-name'], $item['parent-author-name']),
-                                       'when'  => $item['when'],
-                                       'ago'   => $item['ago'],
-                                       'seen'  => $item['seen']]);
-
-                       case Activity::FRIEND:
-                               if (!isset($item['object'])) {
-                                       return new \Friendica\Object\Notification\Notification([
-                                               'label' => 'friend',
-                                               'link'  => $item['link'],
-                                               'image' => $item['image'],
-                                               'url'   => $item['url'],
-                                               'text'  => $item['text'],
-                                               'when'  => $item['when'],
-                                               'ago'   => $item['ago'],
-                                               'seen'  => $item['seen']]);
-                               }
-
-                               $xmlHead       = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
-                               $obj           = XML::parseString($xmlHead . $item['object']);
-                               $item['fname'] = $obj->title;
-
-                               return new \Friendica\Object\Notification\Notification([
-                                       'label' => 'friend',
-                                       'link'  => $this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
-                                       'image' => Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
-                                       'url'   => $item['author-link'],
-                                       'text'  => $this->l10n->t("%s is now friends with %s", $item['author-name'], $item['fname']),
-                                       'when'  => $item['when'],
-                                       'ago'   => $item['ago'],
-                                       'seen'  => $item['seen']]);
-
-                       default:
-                               return new \Friendica\Object\Notification\Notification($item);
-                               break;
-               }
-       }
-
-       /**
-        * 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 \Friendica\Module\Notifications\Notification[]
-        */
-       public function getSystemList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
-       {
-               $conditions = ['uid' => local_user()];
-
-               if (!$seen) {
-                       $conditions['seen'] = false;
-               }
-
-               $params          = [];
-               $params['order'] = ['date' => 'DESC'];
-               $params['limit'] = [$start, $limit];
-
-               $formattedNotifications = [];
-               try {
-                       $notifications = $this->notification->select($conditions, $params);
-
-                       foreach ($notifications as $notification) {
-                               $formattedNotifications[] = new \Friendica\Object\Notification\Notification([
-                                       'label' => 'notification',
-                                       'link'  => $this->baseUrl->get(true) . '/notification/view/' . $notification->id,
-                                       'image' => Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO),
-                                       'url'   => $notification->url,
-                                       'text'  => strip_tags(BBCode::convert($notification->msg)),
-                                       'when'  => DateTimeFormat::local($notification->date, 'r'),
-                                       'ago'   => Temporal::getRelativeDate($notification->date),
-                                       'seen'  => $notification->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 \Friendica\Object\Notification\Notification[]
-        */
-       public function getNetworkList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
-       {
-               $conditions = ['wall' => false, 'uid' => local_user()];
-
-               if (!$seen) {
-                       $conditions['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'];
-               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
-
-               $formattedNotifications = [];
-
-               try {
-                       $items = Item::selectForUser(local_user(), $fields, $conditions, $params);
-
-                       while ($item = $this->dba->fetch($items)) {
-                               $formattedNotifications[] = $this->createFromItem($item);
-                       }
-               } catch (Exception $e) {
-                       $this->logger->warning('Select failed.', ['conditions' => $conditions, '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 \Friendica\Object\Notification\Notification[]
-        */
-       public function getPersonalList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
-       {
-               $myUrl    = str_replace('http://', '', $this->nurl);
-               $diaspUrl = str_replace('/profile/', '/u/', $myUrl);
-
-               $condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)",
-                       local_user(), public_contact(), $myUrl . '\\]', $diaspUrl . '\\]'];
-
-               if (!$seen) {
-                       $condition[0] .= " AND `unseen`";
-               }
-
-               $fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
-                       'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
-               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
-
-               $formattedNotifications = [];
-
-               try {
-                       $items = Item::selectForUser(local_user(), $fields, $condition, $params);
-
-                       while ($item = $this->dba->fetch($items)) {
-                               $formattedNotifications[] = $this->createFromItem($item);
-                       }
-               } 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 \Friendica\Object\Notification\Notification[]
-        */
-       public function getHomeList(bool $seen = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT)
-       {
-               $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'];
-               $params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
-
-               $formattedNotifications = [];
-
-               try {
-                       $items = Item::selectForUser(local_user(), $fields, $condition, $params);
-
-                       while ($item = $this->dba->fetch($items)) {
-                               $item = $this->formatItem($item);
-
-                               // Overwrite specific fields, not default item format
-                               $item['label'] = 'comment';
-                               $item['text']  = $this->l10n->t("%s commented on %s's post", $item['author-name'], $item['parent-author-name']);
-
-                               $formattedNotifications[] = $this->createFromItem($item);
-                       }
-               } catch (Exception $e) {
-                       $this->logger->warning('Select failed.', ['conditions' => $condition, 'exception' => $e]);
-               }
-
-               return $formattedNotifications;
-       }
-}
diff --git a/src/Model/Notification.php b/src/Model/Notification.php
deleted file mode 100644 (file)
index 75fb958..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-<?php
-
-namespace Friendica\Model;
-
-use Exception;
-use Friendica\BaseModel;
-use Friendica\Content\Text\BBCode;
-use Friendica\Content\Text\HTML;
-use Friendica\Database\Database;
-use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Temporal;
-use Psr\Log\LoggerInterface;
-
-/**
- * Model for an entry in the notify table
- * - Including additional, calculated properties
- *
- * Is used either for frontend interactions or for API-based interaction
- * @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification
- *
- * @property string  hash
- * @property integer type
- * @property string  name   Full name of the contact subject
- * @property string  url    Profile page URL of the contact subject
- * @property string  photo  Profile photo URL of the contact subject
- * @property string  date   YYYY-MM-DD hh:mm:ss local server time
- * @property string  msg
- * @property integer uid       Owner User Id
- * @property string  link   Notification URL
- * @property integer iid       Item Id
- * @property integer parent Parent Item Id
- * @property boolean seen   Whether the notification was read or not.
- * @property string  verb   Verb URL (@see http://activitystrea.ms)
- * @property string  otype  Subject type (`item`, `intro` or `mail`)
- *
- * @property-read string name_cache Full name of the contact subject
- * @property-read string msg_cache  Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name.
- *
- * @property-read integer timestamp  Unix timestamp
- * @property-read string  dateRel       Time since the note was posted, eg "1 hour ago"
- * @property-read string  $msg_html
- * @property-read string  $msg_plain
- */
-class Notification extends BaseModel
-{
-       const OTYPE_ITEM   = 'item';
-       const OTYPE_INTRO  = 'intro';
-       const OTYPE_MAIL   = 'mail';
-       const OTYPE_PERSON = 'person';
-
-       /** @var \Friendica\Repository\Notification */
-       private $repo;
-
-       public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\Notification $repo, array $data = [])
-       {
-               parent::__construct($dba, $logger, $data);
-
-               $this->repo = $repo;
-
-               $this->setNameCache();
-               $this->setTimestamp();
-               $this->setMsg();
-       }
-
-       /**
-        * Set the notification as seen
-        *
-        * @param bool $seen true, if seen
-        *
-        * @return bool True, if the seen state could be saved
-        */
-       public function setSeen(bool $seen = true)
-       {
-               $this->seen = $seen;
-               try {
-                       return $this->repo->update($this);
-               } catch (Exception $e) {
-                       $this->logger->warning('Update failed.', ['$this' => $this, 'exception' => $e]);
-                       return false;
-               }
-       }
-
-       /**
-        * Set some extra properties to the notification from db:
-        *  - timestamp as int in default TZ
-        *  - date_rel : relative date string
-        */
-       private function setTimestamp()
-       {
-               try {
-                       $this->timestamp = strtotime(DateTimeFormat::local($this->date));
-               } catch (Exception $e) {
-               }
-               $this->dateRel = Temporal::getRelativeDate($this->date);
-       }
-
-       /**
-        * Sets the pre-formatted name (caching)
-        *
-        * @throws InternalServerErrorException
-        */
-       private function setNameCache()
-       {
-               $this->name_cache = strip_tags(BBCode::convert($this->source_name ?? ''));
-       }
-
-       /**
-        * Set some extra properties to the notification from db:
-        *  - msg_html: message as html string
-        *  - msg_plain: message as plain text string
-        *  - msg_cache: The pre-formatted message (caching)
-        */
-       private function setMsg()
-       {
-               try {
-                       $this->msg_html  = BBCode::convert($this->msg, false);
-                       $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
-                       $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
-               } catch (InternalServerErrorException $e) {
-               }
-       }
-
-       public function __set($name, $value)
-       {
-               parent::__set($name, $value);
-
-               if ($name == 'date') {
-                       $this->setTimestamp();
-               }
-
-               if ($name == 'msg') {
-                       $this->setMsg();
-               }
-
-               if ($name == 'source_name') {
-                       $this->setNameCache();
-               }
-       }
-
-       /**
-        * Formats a notification message with the notification author
-        *
-        * Replace the name with {0} but ensure to make that only once. The {0} is used
-        * later and prints the name in bold.
-        *
-        * @param string $name
-        * @param string $message
-        *
-        * @return string Formatted message
-        */
-       public static function formatMessage($name, $message)
-       {
-               if ($name != '') {
-                       $pos = strpos($message, $name);
-               } else {
-                       $pos = false;
-               }
-
-               if ($pos !== false) {
-                       $message = substr_replace($message, '{0}', $pos, strlen($name));
-               }
-
-               return $message;
-       }
-}
diff --git a/src/Model/Notify.php b/src/Model/Notify.php
new file mode 100644 (file)
index 0000000..1bb9f29
--- /dev/null
@@ -0,0 +1,166 @@
+<?php
+
+namespace Friendica\Model;
+
+use Exception;
+use Friendica\BaseModel;
+use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\HTML;
+use Friendica\Database\Database;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Temporal;
+use Psr\Log\LoggerInterface;
+
+/**
+ * Model for an entry in the notify table
+ * - Including additional, calculated properties
+ *
+ * Is used either for frontend interactions or for API-based interaction
+ * @see https://github.com/friendica/friendica/blob/develop/doc/API-Entities.md#notification
+ *
+ * @property string  hash
+ * @property integer type
+ * @property string  name   Full name of the contact subject
+ * @property string  url    Profile page URL of the contact subject
+ * @property string  photo  Profile photo URL of the contact subject
+ * @property string  date   YYYY-MM-DD hh:mm:ss local server time
+ * @property string  msg
+ * @property integer uid       Owner User Id
+ * @property string  link   Notification URL
+ * @property integer iid       Item Id
+ * @property integer parent Parent Item Id
+ * @property boolean seen   Whether the notification was read or not.
+ * @property string  verb   Verb URL (@see http://activitystrea.ms)
+ * @property string  otype  Subject type (`item`, `intro` or `mail`)
+ *
+ * @property-read string name_cache Full name of the contact subject
+ * @property-read string msg_cache  Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name.
+ *
+ * @property-read integer timestamp  Unix timestamp
+ * @property-read string  dateRel       Time since the note was posted, eg "1 hour ago"
+ * @property-read string  $msg_html
+ * @property-read string  $msg_plain
+ */
+class Notify extends BaseModel
+{
+       const OTYPE_ITEM   = 'item';
+       const OTYPE_INTRO  = 'intro';
+       const OTYPE_MAIL   = 'mail';
+       const OTYPE_PERSON = 'person';
+
+       /** @var \Friendica\Repository\Notify */
+       private $repo;
+
+       public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\Notify $repo, array $data = [])
+       {
+               parent::__construct($dba, $logger, $data);
+
+               $this->repo = $repo;
+
+               $this->setNameCache();
+               $this->setTimestamp();
+               $this->setMsg();
+       }
+
+       /**
+        * Set the notification as seen
+        *
+        * @param bool $seen true, if seen
+        *
+        * @return bool True, if the seen state could be saved
+        */
+       public function setSeen(bool $seen = true)
+       {
+               $this->seen = $seen;
+               try {
+                       return $this->repo->update($this);
+               } catch (Exception $e) {
+                       $this->logger->warning('Update failed.', ['$this' => $this, 'exception' => $e]);
+                       return false;
+               }
+       }
+
+       /**
+        * Set some extra properties to the notification from db:
+        *  - timestamp as int in default TZ
+        *  - date_rel : relative date string
+        */
+       private function setTimestamp()
+       {
+               try {
+                       $this->timestamp = strtotime(DateTimeFormat::local($this->date));
+               } catch (Exception $e) {
+               }
+               $this->dateRel = Temporal::getRelativeDate($this->date);
+       }
+
+       /**
+        * Sets the pre-formatted name (caching)
+        *
+        * @throws InternalServerErrorException
+        */
+       private function setNameCache()
+       {
+               $this->name_cache = strip_tags(BBCode::convert($this->source_name ?? ''));
+       }
+
+       /**
+        * Set some extra properties to the notification from db:
+        *  - msg_html: message as html string
+        *  - msg_plain: message as plain text string
+        *  - msg_cache: The pre-formatted message (caching)
+        */
+       private function setMsg()
+       {
+               try {
+                       $this->msg_html  = BBCode::convert($this->msg, false);
+                       $this->msg_plain = explode("\n", trim(HTML::toPlaintext($this->msg_html, 0)))[0];
+                       $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
+               } catch (InternalServerErrorException $e) {
+               }
+       }
+
+       public function __set($name, $value)
+       {
+               parent::__set($name, $value);
+
+               if ($name == 'date') {
+                       $this->setTimestamp();
+               }
+
+               if ($name == 'msg') {
+                       $this->setMsg();
+               }
+
+               if ($name == 'source_name') {
+                       $this->setNameCache();
+               }
+       }
+
+       /**
+        * Formats a notification message with the notification author
+        *
+        * Replace the name with {0} but ensure to make that only once. The {0} is used
+        * later and prints the name in bold.
+        *
+        * @param string $name
+        * @param string $message
+        *
+        * @return string Formatted message
+        */
+       public static function formatMessage($name, $message)
+       {
+               if ($name != '') {
+                       $pos = strpos($message, $name);
+               } else {
+                       $pos = false;
+               }
+
+               if ($pos !== false) {
+                       $message = substr_replace($message, '{0}', $pos, strlen($name));
+               }
+
+               return $message;
+       }
+}
index 69c776382b3b51f236f2db29fab5816256c0d2f1..10919a13af058cc7fd6285cdceae78a658cc2dc2 100644 (file)
@@ -26,7 +26,7 @@ class Introductions extends BaseNotifications
 
                $notifications = [
                        'ident'         => 'introductions',
-                       'notifications' => DI::factNotIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
+                       'notifications' => DI::notificationIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id),
                ];
 
                return [
index f7fe6f19038651b329afc4126ca6098fc4701201..9b252562cc162d54a56404eb0cfb96995582ded0 100644 (file)
@@ -24,7 +24,7 @@ class Notification extends BaseModule
                // @TODO: Replace with parameter from router
                if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
                        try {
-                               $success = DI::notification()->setAllSeen();
+                               $success = DI::notify()->setAllSeen();
                        }catch (\Exception $e) {
                                $success = false;
                        }
@@ -48,7 +48,7 @@ class Notification extends BaseModule
                // @TODO: Replace with parameter from router
                if (DI::args()->getArgc() > 2 && DI::args()->get(1) === 'view' && intval(DI::args()->get(2))) {
                        try {
-                               $notification = DI::notification()->getByID(DI::args()->get(2));
+                               $notification = DI::notify()->getByID(DI::args()->get(2));
                                $notification->setSeen();
 
                                if (!empty($notification->link)) {
index bff5026df6ecc6827b0b7821067033d8a02a6186..37b2346663b2f00310147ff72641d93365f9f265 100644 (file)
@@ -31,7 +31,7 @@ class Notifications extends BaseNotifications
                        $notificationHeader = DI::l10n()->t('Network Notifications');
                        $notifications      = [
                                'ident'        => Notification::NETWORK,
-                               'notifications' => DI::factNotification()->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'notifications' => DI::notification()->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
                        ];
 
                        // Get the system notifications
@@ -39,7 +39,7 @@ class Notifications extends BaseNotifications
                        $notificationHeader = DI::l10n()->t('System Notifications');
                        $notifications      = [
                                'ident'        => Notification::SYSTEM,
-                               'notifications' => DI::factNotification()->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'notifications' => DI::notification()->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
                        ];
 
                        // Get the personal notifications
@@ -47,7 +47,7 @@ class Notifications extends BaseNotifications
                        $notificationHeader = DI::l10n()->t('Personal Notifications');
                        $notifications      = [
                                'ident'        => Notification::PERSONAL,
-                               'notifications' => DI::factNotification()->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'notifications' => DI::notification()->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
                        ];
 
                        // Get the home notifications
@@ -55,7 +55,7 @@ class Notifications extends BaseNotifications
                        $notificationHeader = DI::l10n()->t('Home Notifications');
                        $notifications      = [
                                'ident'        => Notification::HOME,
-                               'notifications' => DI::factNotification()->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
+                               'notifications' => DI::notification()->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
                        ];
                        // fallback - redirect to main page
                } else {
diff --git a/src/Repository/Notification.php b/src/Repository/Notification.php
deleted file mode 100644 (file)
index a17d122..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-
-namespace Friendica\Repository;
-
-use Exception;
-use Friendica\BaseRepository;
-use Friendica\Core\Hook;
-use Friendica\Model;
-use Friendica\Collection;
-use Friendica\Network\HTTPException\NotFoundException;
-use Friendica\Util\DateTimeFormat;
-
-class Notification extends BaseRepository
-{
-       protected static $table_name = 'notify';
-
-       protected static $model_class = Model\Notification::class;
-
-       protected static $collection_class = Collection\Notifications::class;
-
-       /**
-        * {@inheritDoc}
-        *
-        * @return Model\Notification
-        */
-       protected function create(array $data)
-       {
-               return new Model\Notification($this->dba, $this->logger, $this, $data);
-       }
-
-       /**
-        * {@inheritDoc}
-        *
-        * @return Collection\Notifications
-        */
-       public function select(array $condition = [], array $params = [])
-       {
-               $params['order'] = $params['order'] ?? ['date' => 'DESC'];
-
-               $condition = array_merge($condition, ['uid' => local_user()]);
-
-               return parent::select($condition, $params);
-       }
-
-       /**
-        * {@inheritDoc}
-        *
-        * @return Model\Notification
-        * @throws NotFoundException
-        */
-       public function getByID(int $id)
-       {
-               return $this->selectFirst(['id' => $id, 'uid' => local_user()]);
-       }
-
-       /**
-        * {@inheritDoc}
-        *
-        * @return bool true on success, false on error
-        * @throws Exception
-        */
-       public function setAllSeen(bool $seen = true)
-       {
-               return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
-       }
-
-       /**
-        * @param array $fields
-        *
-        * @return Model\Notification
-        *
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        * @throws Exception
-        */
-       public function insert(array $fields)
-       {
-               $fields['date']  = DateTimeFormat::utcNow();
-               $fields['abort'] = false;
-
-               Hook::callAll('enotify_store', $fields);
-
-               if ($fields['abort']) {
-                       $this->logger->debug('Abort adding notification entry', ['fields' => $fields]);
-                       return null;
-               }
-
-               $this->logger->debug('adding notification entry', ['fields' => $fields]);
-
-               return parent::insert($fields);
-       }
-}
diff --git a/src/Repository/Notify.php b/src/Repository/Notify.php
new file mode 100644 (file)
index 0000000..2ac1485
--- /dev/null
@@ -0,0 +1,91 @@
+<?php
+
+namespace Friendica\Repository;
+
+use Exception;
+use Friendica\BaseRepository;
+use Friendica\Core\Hook;
+use Friendica\Model;
+use Friendica\Collection;
+use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\Util\DateTimeFormat;
+
+class Notify extends BaseRepository
+{
+       protected static $table_name = 'notify';
+
+       protected static $model_class = Model\Notify::class;
+
+       protected static $collection_class = Collection\Notifies::class;
+
+       /**
+        * {@inheritDoc}
+        *
+        * @return Model\Notify
+        */
+       protected function create(array $data)
+       {
+               return new Model\Notify($this->dba, $this->logger, $this, $data);
+       }
+
+       /**
+        * {@inheritDoc}
+        *
+        * @return Collection\Notifies
+        */
+       public function select(array $condition = [], array $params = [])
+       {
+               $params['order'] = $params['order'] ?? ['date' => 'DESC'];
+
+               $condition = array_merge($condition, ['uid' => local_user()]);
+
+               return parent::select($condition, $params);
+       }
+
+       /**
+        * {@inheritDoc}
+        *
+        * @return Model\Notify
+        * @throws NotFoundException
+        */
+       public function getByID(int $id)
+       {
+               return $this->selectFirst(['id' => $id, 'uid' => local_user()]);
+       }
+
+       /**
+        * {@inheritDoc}
+        *
+        * @return bool true on success, false on error
+        * @throws Exception
+        */
+       public function setAllSeen(bool $seen = true)
+       {
+               return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
+       }
+
+       /**
+        * @param array $fields
+        *
+        * @return Model\Notify
+        *
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws Exception
+        */
+       public function insert(array $fields)
+       {
+               $fields['date']  = DateTimeFormat::utcNow();
+               $fields['abort'] = false;
+
+               Hook::callAll('enotify_store', $fields);
+
+               if ($fields['abort']) {
+                       $this->logger->debug('Abort adding notification entry', ['fields' => $fields]);
+                       return null;
+               }
+
+               $this->logger->debug('adding notification entry', ['fields' => $fields]);
+
+               return parent::insert($fields);
+       }
+}