Move notify to the new paradigm

- Remove unused frion notify template
- Update API test
This commit is contained in:
Hypolite Petovan 2021-09-18 01:08:29 -04:00
parent 1b4e3564a5
commit 47acb6a278
25 changed files with 150 additions and 925 deletions

View file

@ -27,8 +27,8 @@ use Friendica\Content\Pager;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\DI;
use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Object\Notification\Notification;
/**
* Base Module for each tab of the notification display
@ -39,29 +39,29 @@ abstract class BaseNotifications extends BaseModule
{
/** @var array Array of URL parameters */
const URL_TYPES = [
Notification::NETWORK => 'network',
Notification::SYSTEM => 'system',
Notification::HOME => 'home',
Notification::PERSONAL => 'personal',
Notification::INTRO => 'intros',
FormattedNotification::NETWORK => 'network',
FormattedNotification::SYSTEM => 'system',
FormattedNotification::HOME => 'home',
FormattedNotification::PERSONAL => 'personal',
FormattedNotification::INTRO => 'intros',
];
/** @var array Array of the allowed notifications and their printable name */
const PRINT_TYPES = [
Notification::NETWORK => 'Network',
Notification::SYSTEM => 'System',
Notification::HOME => 'Home',
Notification::PERSONAL => 'Personal',
Notification::INTRO => 'Introductions',
FormattedNotification::NETWORK => 'Network',
FormattedNotification::SYSTEM => 'System',
FormattedNotification::HOME => 'Home',
FormattedNotification::PERSONAL => 'Personal',
FormattedNotification::INTRO => 'Introductions',
];
/** @var array The array of access keys for notification pages */
const ACCESS_KEYS = [
Notification::NETWORK => 'w',
Notification::SYSTEM => 'y',
Notification::HOME => 'h',
Notification::PERSONAL => 'r',
Notification::INTRO => 'i',
FormattedNotification::NETWORK => 'w',
FormattedNotification::SYSTEM => 'y',
FormattedNotification::HOME => 'h',
FormattedNotification::PERSONAL => 'r',
FormattedNotification::INTRO => 'i',
];
/** @var int The default count of items per page */

View file

@ -126,9 +126,9 @@ class Delegation extends BaseModule
$identities[$key]['selected'] = ($identity['nickname'] === DI::app()->getLoggedInUserNickname());
$condition = ["`uid` = ? AND `msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", $identity['uid'], Notification\Type::INTRO, Notification\Type::MAIL];
$condition = ["`msg` != '' AND NOT (`type` IN (?, ?)) AND NOT `seen`", Notification\Type::INTRO, Notification\Type::MAIL];
$params = ['distinct' => true, 'expression' => 'parent'];
$notifications = DBA::count('notify', $condition, $params);
$notifications = DI::notify()->countForUser($identity['uid'], $condition, $params);
$params = ['distinct' => true, 'expression' => 'convid'];
$notifications += DBA::count('mail', ['uid' => $identity['uid'], 'seen' => false], $params);

View file

@ -78,7 +78,8 @@ class Notification extends BaseModule
if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
try {
$success = DI::notify()->setSeen();
DI::dba()->update('notification', ['seen' => true], ['uid' => local_user()]);
$success = DI::notify()->setAllSeenForUser(local_user());
} catch (\Exception $e) {
DI::logger()->warning('set all seen failed.', ['exception' => $e]);
$success = false;
@ -97,7 +98,7 @@ class Notification extends BaseModule
* @throws HTTPException\InternalServerErrorException
* @throws \Exception
*/
public static function content(array $parameters = [])
public static function content(array $parameters = []): string
{
if (!local_user()) {
notice(DI::l10n()->t('You must be logged in to show this page.'));
@ -107,17 +108,24 @@ class Notification extends BaseModule
$request_id = $parameters['id'] ?? false;
if ($request_id) {
$notify = DI::notify()->getByID($request_id, local_user());
if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
$notify->seen = true;
DI::notify()->update($notify);
} else {
DI::notify()->setSeen(true, $notify);
$Notify = DI::notify()->selectOneById($request_id);
if ($Notify->uid !== local_user()) {
throw new HTTPException\ForbiddenException();
}
if (!empty($notify->link)) {
System::externalRedirect($notify->link);
if (DI::pConfig()->get(local_user(), 'system', 'detailed_notif')) {
$Notify->setSeen();
DI::notify()->save($Notify);
} else {
if ($Notify->uriId) {
DI::dba()->update('notification', ['seen' => true], ['uid' => $Notify->uid, 'target-uri-id' => $Notify->uriId]);
}
DI::notify()->setAllSeenForRelatedNotify($Notify);
}
if ($Notify->link) {
System::externalRedirect($Notify->link);
}
DI::baseUrl()->redirect();
@ -125,6 +133,6 @@ class Notification extends BaseModule
DI::baseUrl()->redirect('notifications/system');
throw new HTTPException\InternalServerErrorException('Invalid situation.');
return '';
}
}

View file

@ -25,7 +25,9 @@ use Friendica\Content\Nav;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Module\BaseNotifications;
use Friendica\Object\Notification\Notification;
use Friendica\Navigation\Notifications\Collection\FormattedNotifications;
use Friendica\Navigation\Notifications\ValueObject\FormattedNotification;
use Friendica\Network\HTTPException\InternalServerErrorException;
/**
* Prints all notification types except introduction:
@ -42,41 +44,35 @@ class Notifications extends BaseNotifications
public static function getNotifications()
{
$notificationHeader = '';
/** @var Notification[] $notifications */
$notifications = [];
// Get the network notifications
/** @var \Friendica\Navigation\Notifications\Factory\FormattedNotification $factory */
$factory = DI::getDice()->create(\Friendica\Navigation\Notifications\Factory\FormattedNotification::class);
if ((DI::args()->get(1) == 'network')) {
$notificationHeader = DI::l10n()->t('Network Notifications');
$notifications = [
'ident' => Notification::NETWORK,
'notifications' => DI::notification()->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
'ident' => FormattedNotification::NETWORK,
'notifications' => $factory->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
// Get the system notifications
} elseif ((DI::args()->get(1) == 'system')) {
$notificationHeader = DI::l10n()->t('System Notifications');
$notifications = [
'ident' => Notification::SYSTEM,
'notifications' => DI::notification()->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
'ident' => FormattedNotification::SYSTEM,
'notifications' => $factory->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
// Get the personal notifications
} elseif ((DI::args()->get(1) == 'personal')) {
$notificationHeader = DI::l10n()->t('Personal Notifications');
$notifications = [
'ident' => Notification::PERSONAL,
'notifications' => DI::notification()->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
'ident' => FormattedNotification::PERSONAL,
'notifications' => $factory->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
// Get the home notifications
} elseif ((DI::args()->get(1) == 'home')) {
$notificationHeader = DI::l10n()->t('Home Notifications');
$notifications = [
'ident' => Notification::HOME,
'notifications' => DI::notification()->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
'ident' => FormattedNotification::HOME,
'notifications' => $factory->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE),
];
// fallback - redirect to main page
} else {
DI::baseUrl()->redirect('notifications');
}
@ -98,11 +94,10 @@ class Notifications extends BaseNotifications
$notifications = $notificationResult['notifications'] ?? [];
$notificationHeader = $notificationResult['header'] ?? '';
if (!empty($notifications['notifications'])) {
// Loop trough ever notification This creates an array with the output html for each
// notification and apply the correct template according to the notificationtype (label).
/** @var Notification $notification */
/** @var FormattedNotification $notification */
foreach ($notifications['notifications'] as $notification) {
$notification_templates = [
'like' => 'notifications/likes_item.tpl',
@ -116,21 +111,16 @@ class Notifications extends BaseNotifications
'notification' => 'notifications/notification.tpl',
];
$notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification->getLabel()]);
$notificationArray = $notification->toArray();
$notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notificationArray['label']]);
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
'$item_label' => $notification->getLabel(),
'$item_link' => $notification->getLink(),
'$item_image' => $notification->getImage(),
'$item_url' => $notification->getUrl(),
'$item_text' => $notification->getText(),
'$item_when' => $notification->getWhen(),
'$item_ago' => $notification->getAgo(),
'$item_seen' => $notification->isSeen(),
'$notification' => $notificationArray
]);
}
} else {
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
$notificationNoContent = DI::l10n()->t('No more %s notifications.', $notificationResult['ident']);
}
$notificationShowLink = [