mirror of
https://github.com/friendica/friendica
synced 2025-05-02 23:44:23 +02:00
ReWork Notification Model/Module/Object/Repository/Factory
- Introduce Repository for interaction with "notify" table - Introduce Factory for read-only notification objects (they're just loosely based on notification the table!) - Introduce Objects for type-safe usage at the presentation layer - Reworked Model, which is now fully based on the notify table, including generated fields (cache, ..)
This commit is contained in:
parent
230bb6dd53
commit
0850fb88dd
17 changed files with 1413 additions and 851 deletions
205
src/Factory/Notification/IntroductionFactory.php
Normal file
205
src/Factory/Notification/IntroductionFactory.php
Normal file
|
@ -0,0 +1,205 @@
|
|||
<?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;
|
||||
|
||||
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 getIntroList(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->getMissingIntroData($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 getMissingIntroData(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;
|
||||
}
|
||||
}
|
355
src/Factory/Notification/NotificationFactory.php
Normal file
355
src/Factory/Notification/NotificationFactory.php
Normal file
|
@ -0,0 +1,355 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Factory\Notification;
|
||||
|
||||
use Exception;
|
||||
use Friendica\App;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig\IPConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Session\ISession;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Module\BaseNotifications;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Repository\Notification;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Proxy;
|
||||
use Friendica\Util\Temporal;
|
||||
use Friendica\Util\XML;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
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(
|
||||
'like',
|
||||
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
|
||||
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
|
||||
$item['author-link'],
|
||||
$this->l10n->t("%s liked %s's post", $item['author-name'], $item['parent-author-name']),
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
|
||||
case Activity::DISLIKE:
|
||||
return new \Friendica\Object\Notification\Notification(
|
||||
'dislike',
|
||||
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
|
||||
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
|
||||
$item['author-link'],
|
||||
$this->l10n->t("%s disliked %s's post", $item['author-name'], $item['parent-author-name']),
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
|
||||
case Activity::ATTEND:
|
||||
return new \Friendica\Object\Notification\Notification(
|
||||
'attend',
|
||||
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
|
||||
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
|
||||
$item['author-link'],
|
||||
$this->l10n->t("%s is attending %s's event", $item['author-name'], $item['parent-author-name']),
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
|
||||
case Activity::ATTENDNO:
|
||||
return new \Friendica\Object\Notification\Notification(
|
||||
'attendno',
|
||||
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
|
||||
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
|
||||
$item['author-link'],
|
||||
$this->l10n->t("%s is not attending %s's event", $item['author-name'], $item['parent-author-name']),
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
|
||||
case Activity::ATTENDMAYBE:
|
||||
return new \Friendica\Object\Notification\Notification(
|
||||
'attendmaybe',
|
||||
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
|
||||
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
|
||||
$item['author-link'],
|
||||
$this->l10n->t("%s may attending %s's event", $item['author-name'], $item['parent-author-name']),
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
|
||||
case Activity::FRIEND:
|
||||
if (!isset($item['object'])) {
|
||||
return new \Friendica\Object\Notification\Notification(
|
||||
'friend',
|
||||
$item['link'],
|
||||
$item['image'],
|
||||
$item['url'],
|
||||
$item['text'],
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
}
|
||||
|
||||
$xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||
$obj = XML::parseString($xmlHead . $item['object']);
|
||||
$item['fname'] = $obj->title;
|
||||
|
||||
return new \Friendica\Object\Notification\Notification(
|
||||
'friend',
|
||||
$this->baseUrl->get(true) . '/display/' . $item['parent-guid'],
|
||||
Proxy::proxifyUrl($item['author-avatar'], false, Proxy::SIZE_MICRO),
|
||||
$item['author-link'],
|
||||
$this->l10n->t("%s is now friends with %s", $item['author-name'], $item['fname']),
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
|
||||
default:
|
||||
return new \Friendica\Object\Notification\Notification(
|
||||
$item['label'],
|
||||
$item['link'],
|
||||
$item['image'],
|
||||
$item['url'],
|
||||
$item['text'],
|
||||
$item['when'] ?? '',
|
||||
$item['ago'] ?? '',
|
||||
$item['seen'] ?? false);
|
||||
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(
|
||||
'notification',
|
||||
$this->baseUrl->get(true) . '/notification/view/' . $notification->id,
|
||||
Proxy::proxifyUrl($notification->photo, false, Proxy::SIZE_MICRO),
|
||||
$notification->url,
|
||||
strip_tags(BBCode::convert($notification->msg)),
|
||||
DateTimeFormat::local($notification->date, 'r'),
|
||||
Temporal::getRelativeDate($notification->date),
|
||||
$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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue