From: nupplaPhil Date: Sun, 26 Jan 2020 19:30:24 +0000 (+0100) Subject: Rename classes X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0840938dff3a2bdc8db836662fea2bbccff05e03;p=friendica.git Rename classes - Repository/Model Notification => Notify - Factory/Object Notification => Notification --- diff --git a/include/api.php b/include/api.php index 0729c2a0f8..f43ee2d1ba 100644 --- a/include/api.php +++ b/include/api.php @@ -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 diff --git a/include/enotify.php b/include/enotify.php index f509367efb..144460693d 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -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; diff --git a/mod/ping.php b/mod/ping.php index a786d379f2..dd57ba34d6 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -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 index 1c04bdf4d4..0000000000 --- a/src/Collection/Notifications.php +++ /dev/null @@ -1,17 +0,0 @@ -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 index 0000000000..6b192ec1d1 --- /dev/null +++ b/src/Factory/Notification/Introduction.php @@ -0,0 +1,211 @@ +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 index 0988821154..0000000000 --- a/src/Factory/Notification/IntroductionFactory.php +++ /dev/null @@ -1,211 +0,0 @@ -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 index 0000000000..5f2c2231b8 --- /dev/null +++ b/src/Factory/Notification/Notification.php @@ -0,0 +1,355 @@ +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 index 05dd200adb..0000000000 --- a/src/Factory/Notification/NotificationFactory.php +++ /dev/null @@ -1,355 +0,0 @@ -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 index 75fb95829f..0000000000 --- a/src/Model/Notification.php +++ /dev/null @@ -1,166 +0,0 @@ -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 index 0000000000..1bb9f29047 --- /dev/null +++ b/src/Model/Notify.php @@ -0,0 +1,166 @@ +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/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 69c776382b..10919a13af 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -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 [ diff --git a/src/Module/Notifications/Notification.php b/src/Module/Notifications/Notification.php index f7fe6f1903..9b252562cc 100644 --- a/src/Module/Notifications/Notification.php +++ b/src/Module/Notifications/Notification.php @@ -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)) { diff --git a/src/Module/Notifications/Notifications.php b/src/Module/Notifications/Notifications.php index bff5026df6..37b2346663 100644 --- a/src/Module/Notifications/Notifications.php +++ b/src/Module/Notifications/Notifications.php @@ -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 index a17d1223af..0000000000 --- a/src/Repository/Notification.php +++ /dev/null @@ -1,91 +0,0 @@ -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 index 0000000000..2ac14858f5 --- /dev/null +++ b/src/Repository/Notify.php @@ -0,0 +1,91 @@ +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); + } +}