From b85511b00db778030302255fd6901157c750a2f1 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Sun, 26 Jan 2020 14:30:32 +0100 Subject: [PATCH] Improvements: - Fix API-select - Introduce OTYPE-constants - Rename `IntroductionFactory` methods --- include/api.php | 6 +++--- include/enotify.php | 3 ++- src/Factory/Notification/IntroductionFactory.php | 6 +++--- src/Model/Notification.php | 5 +++++ src/Module/Notifications/Introductions.php | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/api.php b/include/api.php index 4a55c2b919..0729c2a0f8 100644 --- a/include/api.php +++ b/include/api.php @@ -23,6 +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\Photo; use Friendica\Model\Profile; use Friendica\Model\User; @@ -5906,7 +5907,7 @@ function api_friendica_notification($type) throw new BadRequestException("Invalid argument count"); } - $notifications = DI::notification()->select([], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]); + $notifications = DI::notification()->select(['uid' => api_user()], ['order' => ['seen' => 'ASC', 'date' => 'DESC'], 'limit' => 50]); if ($type == "xml") { $xmlnotes = false; @@ -5957,8 +5958,7 @@ function api_friendica_notification_seen($type) $notification = DI::notification()->getByID($id); $notification->setSeen(); - if ($notification->otype == 'item') { - // would be really better with an ItemsManager and $im->getByID() :-P + if ($notification->otype === Notification::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 32f32afec8..f509367efb 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -12,6 +12,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; use Friendica\Model\ItemContent; +use Friendica\Model\Notification; use Friendica\Model\User; use Friendica\Model\UserItem; use Friendica\Protocol\Activity; @@ -160,7 +161,7 @@ function notification($params) // if it's a post figure out who's post it is. $item = null; - if ($params['otype'] === 'item' && $parent_id) { + if ($params['otype'] === Notification::OTYPE_ITEM && $parent_id) { $item = Item::selectFirstForUser($params['uid'], Item::ITEM_FIELDLIST, ['id' => $parent_id, 'deleted' => false]); } diff --git a/src/Factory/Notification/IntroductionFactory.php b/src/Factory/Notification/IntroductionFactory.php index 3f2bb563a1..0988821154 100644 --- a/src/Factory/Notification/IntroductionFactory.php +++ b/src/Factory/Notification/IntroductionFactory.php @@ -63,7 +63,7 @@ class IntroductionFactory extends BaseFactory * * @return Introduction[] */ - public function getIntroList(bool $all = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT, int $id = 0) + public function getList(bool $all = false, int $start = 0, int $limit = BaseNotifications::DEFAULT_PAGE_LIMIT, int $id = 0) { $sql_extra = ""; @@ -128,7 +128,7 @@ class IntroductionFactory extends BaseFactory // Normal connection requests } else { - $notification = $this->getMissingIntroData($notification); + $notification = $this->getMissingData($notification); if (empty($notification['url'])) { continue; @@ -182,7 +182,7 @@ class IntroductionFactory extends BaseFactory * * @throws InternalServerErrorException */ - private function getMissingIntroData(array $intro) + 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 diff --git a/src/Model/Notification.php b/src/Model/Notification.php index 254aaf5f6b..75fb95829f 100644 --- a/src/Model/Notification.php +++ b/src/Model/Notification.php @@ -44,6 +44,11 @@ use Psr\Log\LoggerInterface; */ 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; diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 8ded212c6c..69c776382b 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()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id), + 'notifications' => DI::factNotIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id), ]; return [