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;
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;
$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
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;
// 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]);
}
$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'],
$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;
$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",
+++ /dev/null
-<?php
-
-namespace Friendica\Collection;
-
-use Friendica\BaseCollection;
-use Friendica\Model;
-
-class Notifications extends BaseCollection
-{
- /**
- * @return Model\Notification
- */
- public function current()
- {
- return parent::current();
- }
-}
--- /dev/null
+<?php
+
+namespace Friendica\Collection;
+
+use Friendica\BaseCollection;
+use Friendica\Model;
+
+class Notifies extends BaseCollection
+{
+ /**
+ * @return Model\Notify
+ */
+ public function current()
+ {
+ return parent::current();
+ }
+}
}
/**
- * @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);
}
//
}
/**
- * @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);
}
/**
--- /dev/null
+<?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;
+ }
+}
+++ /dev/null
-<?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;
- }
-}
--- /dev/null
+<?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;
+ }
+}
+++ /dev/null
-<?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;
- }
-}
+++ /dev/null
-<?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;
- }
-}
--- /dev/null
+<?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;
+ }
+}
$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 [
// @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;
}
// @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)) {
$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
$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
$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
$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 {
+++ /dev/null
-<?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);
- }
-}
--- /dev/null
+<?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);
+ }
+}