Notify => Notification

Notifs => Notifications
This commit is contained in:
nupplaPhil 2020-01-24 18:32:38 +01:00
parent e59a9fbef7
commit 0f932ae723
No known key found for this signature in database
GPG Key ID: D8365C3D36B77D90
19 changed files with 250 additions and 254 deletions

View File

@ -5905,7 +5905,7 @@ function api_friendica_notification($type)
if ($a->argc!==3) { if ($a->argc!==3) {
throw new BadRequestException("Invalid argument count"); throw new BadRequestException("Invalid argument count");
} }
$notes = DI::notify()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50); $notes = DI::notification()->getAll([], ['seen' => 'ASC', 'date' => 'DESC'], 50);
if ($type == "xml") { if ($type == "xml") {
$xmlnotes = []; $xmlnotes = [];
@ -5947,7 +5947,7 @@ function api_friendica_notification_seen($type)
$id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0); $id = (!empty($_REQUEST['id']) ? intval($_REQUEST['id']) : 0);
$nm = DI::notify(); $nm = DI::notification();
$note = $nm->getByID($id); $note = $nm->getByID($id);
if (is_null($note)) { if (is_null($note)) {
throw new BadRequestException("Invalid argument"); throw new BadRequestException("Invalid argument");

View File

@ -516,7 +516,7 @@ function notification($params)
$notify_id = DBA::lastInsertId(); $notify_id = DBA::lastInsertId();
$itemlink = DI::baseUrl().'/notify/view/'.$notify_id; $itemlink = DI::baseUrl().'/notification/view/'.$notify_id;
$msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $itemlink]); $msg = Renderer::replaceMacros($epreamble, ['$itemlink' => $itemlink]);
$msg_cache = format_notification_message($datarray['name_cache'], strip_tags(BBCode::convert($msg))); $msg_cache = format_notification_message($datarray['name_cache'], strip_tags(BBCode::convert($msg)));

View File

@ -443,7 +443,7 @@ function ping_get_notifications($uid)
); );
} }
$notification["href"] = DI::baseUrl() . "/notify/view/" . $notification["id"]; $notification["href"] = DI::baseUrl() . "/notification/view/" . $notification["id"];
if ($notification["visible"] if ($notification["visible"]
&& !$notification["deleted"] && !$notification["deleted"]

View File

@ -257,11 +257,11 @@ abstract class DI
} }
/** /**
* @return Model\Notify * @return Model\Notification
*/ */
public static function notify() public static function notification()
{ {
return self::$dice->create(Model\Notify::class); return self::$dice->create(Model\Notification::class);
} }
/** /**

View File

@ -25,7 +25,7 @@ use Friendica\Network\HTTPException;
* Methods for read and write notifications from/to database * Methods for read and write notifications from/to database
* or for formatting notifications * or for formatting notifications
*/ */
final class Notify final class Notification
{ {
/** @var int The default limit of notifies per page */ /** @var int The default limit of notifies per page */
const DEFAULT_PAGE_LIMIT = 80; const DEFAULT_PAGE_LIMIT = 80;
@ -172,7 +172,7 @@ final class Notify
/** /**
* Format the notification query in an usable array * Format the notification query in an usable array
* *
* @param array $notifies The array from the db query * @param array $notifications The array from the db query
* @param string $ident The notifications identifier (e.g. network) * @param string $ident The notifications identifier (e.g. network)
* *
* @return array * @return array
@ -186,126 +186,126 @@ final class Notify
* bool 'seen' => Is the notification marked as "seen" * bool 'seen' => Is the notification marked as "seen"
* @throws Exception * @throws Exception
*/ */
private function formatList(array $notifies, string $ident = "") private function formatList(array $notifications, string $ident = "")
{ {
$formattedNotifies = []; $formattedNotifies = [];
foreach ($notifies as $notify) { foreach ($notifications as $notification) {
// Because we use different db tables for the notification query // Because we use different db tables for the notification query
// we have sometimes $notify['unseen'] and sometimes $notify['seen]. // we have sometimes $notification['unseen'] and sometimes $notification['seen].
// So we will have to transform $notify['unseen'] // So we will have to transform $notification['unseen']
if (array_key_exists('unseen', $notify)) { if (array_key_exists('unseen', $notification)) {
$notify['seen'] = ($notify['unseen'] > 0 ? false : true); $notification['seen'] = ($notification['unseen'] > 0 ? false : true);
} }
// For feed items we use the user's contact, since the avatar is mostly self choosen. // For feed items we use the user's contact, since the avatar is mostly self choosen.
if (!empty($notify['network']) && $notify['network'] == Protocol::FEED) { if (!empty($notification['network']) && $notification['network'] == Protocol::FEED) {
$notify['author-avatar'] = $notify['contact-avatar']; $notification['author-avatar'] = $notification['contact-avatar'];
} }
// Depending on the identifier of the notification we need to use different defaults // Depending on the identifier of the notification we need to use different defaults
switch ($ident) { switch ($ident) {
case self::SYSTEM: case self::SYSTEM:
$default_item_label = 'notify'; $default_item_label = 'notification';
$default_item_link = $this->baseUrl->get(true) . '/notify/view/' . $notify['id']; $default_item_link = $this->baseUrl->get(true) . '/notification/view/' . $notification['id'];
$default_item_image = ProxyUtils::proxifyUrl($notify['photo'], false, ProxyUtils::SIZE_MICRO); $default_item_image = ProxyUtils::proxifyUrl($notification['photo'], false, ProxyUtils::SIZE_MICRO);
$default_item_url = $notify['url']; $default_item_url = $notification['url'];
$default_item_text = strip_tags(BBCode::convert($notify['msg'])); $default_item_text = strip_tags(BBCode::convert($notification['msg']));
$default_item_when = DateTimeFormat::local($notify['date'], 'r'); $default_item_when = DateTimeFormat::local($notification['date'], 'r');
$default_item_ago = Temporal::getRelativeDate($notify['date']); $default_item_ago = Temporal::getRelativeDate($notification['date']);
break; break;
case self::HOME: case self::HOME:
$default_item_label = 'comment'; $default_item_label = 'comment';
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid']; $default_item_link = $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'];
$default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO); $default_item_image = ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO);
$default_item_url = $notify['author-link']; $default_item_url = $notification['author-link'];
$default_item_text = $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name']); $default_item_text = $this->l10n->t("%s commented on %s's post", $notification['author-name'], $notification['parent-author-name']);
$default_item_when = DateTimeFormat::local($notify['created'], 'r'); $default_item_when = DateTimeFormat::local($notification['created'], 'r');
$default_item_ago = Temporal::getRelativeDate($notify['created']); $default_item_ago = Temporal::getRelativeDate($notification['created']);
break; break;
default: default:
$default_item_label = (($notify['id'] == $notify['parent']) ? 'post' : 'comment'); $default_item_label = (($notification['id'] == $notification['parent']) ? 'post' : 'comment');
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid']; $default_item_link = $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'];
$default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO); $default_item_image = ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO);
$default_item_url = $notify['author-link']; $default_item_url = $notification['author-link'];
$default_item_text = (($notify['id'] == $notify['parent']) $default_item_text = (($notification['id'] == $notification['parent'])
? $this->l10n->t("%s created a new post", $notify['author-name']) ? $this->l10n->t("%s created a new post", $notification['author-name'])
: $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name'])); : $this->l10n->t("%s commented on %s's post", $notification['author-name'], $notification['parent-author-name']));
$default_item_when = DateTimeFormat::local($notify['created'], 'r'); $default_item_when = DateTimeFormat::local($notification['created'], 'r');
$default_item_ago = Temporal::getRelativeDate($notify['created']); $default_item_ago = Temporal::getRelativeDate($notification['created']);
} }
// Transform the different types of notification in an usable array // Transform the different types of notification in an usable array
switch ($notify['verb']) { switch ($notification['verb']) {
case Activity::LIKE: case Activity::LIKE:
$formattedNotify = [ $formattedNotify = [
'label' => 'like', 'label' => 'like',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
'url' => $notify['author-link'], 'url' => $notification['author-link'],
'text' => $this->l10n->t("%s liked %s's post", $notify['author-name'], $notify['parent-author-name']), 'text' => $this->l10n->t("%s liked %s's post", $notification['author-name'], $notification['parent-author-name']),
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
break; break;
case Activity::DISLIKE: case Activity::DISLIKE:
$formattedNotify = [ $formattedNotify = [
'label' => 'dislike', 'label' => 'dislike',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
'url' => $notify['author-link'], 'url' => $notification['author-link'],
'text' => $this->l10n->t("%s disliked %s's post", $notify['author-name'], $notify['parent-author-name']), 'text' => $this->l10n->t("%s disliked %s's post", $notification['author-name'], $notification['parent-author-name']),
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
break; break;
case Activity::ATTEND: case Activity::ATTEND:
$formattedNotify = [ $formattedNotify = [
'label' => 'attend', 'label' => 'attend',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
'url' => $notify['author-link'], 'url' => $notification['author-link'],
'text' => $this->l10n->t("%s is attending %s's event", $notify['author-name'], $notify['parent-author-name']), 'text' => $this->l10n->t("%s is attending %s's event", $notification['author-name'], $notification['parent-author-name']),
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
break; break;
case Activity::ATTENDNO: case Activity::ATTENDNO:
$formattedNotify = [ $formattedNotify = [
'label' => 'attendno', 'label' => 'attendno',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
'url' => $notify['author-link'], 'url' => $notification['author-link'],
'text' => $this->l10n->t("%s is not attending %s's event", $notify['author-name'], $notify['parent-author-name']), 'text' => $this->l10n->t("%s is not attending %s's event", $notification['author-name'], $notification['parent-author-name']),
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
break; break;
case Activity::ATTENDMAYBE: case Activity::ATTENDMAYBE:
$formattedNotify = [ $formattedNotify = [
'label' => 'attendmaybe', 'label' => 'attendmaybe',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
'url' => $notify['author-link'], 'url' => $notification['author-link'],
'text' => $this->l10n->t("%s may attend %s's event", $notify['author-name'], $notify['parent-author-name']), 'text' => $this->l10n->t("%s may attend %s's event", $notification['author-name'], $notification['parent-author-name']),
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
break; break;
case Activity::FRIEND: case Activity::FRIEND:
if (!isset($notify['object'])) { if (!isset($notification['object'])) {
$formattedNotify = [ $formattedNotify = [
'label' => 'friend', 'label' => 'friend',
'link' => $default_item_link, 'link' => $default_item_link,
@ -314,26 +314,26 @@ final class Notify
'text' => $default_item_text, 'text' => $default_item_text,
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
break; break;
} }
/// @todo Check if this part here is used at all /// @todo Check if this part here is used at all
$this->logger->info('Complete data.', ['notify' => $notify, 'callStack' => System::callstack(20)]); $this->logger->info('Complete data.', ['notification' => $notification, 'callStack' => System::callstack(20)]);
$xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; $xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
$obj = XML::parseString($xmlHead . $notify['object']); $obj = XML::parseString($xmlHead . $notification['object']);
$notify['fname'] = $obj->title; $notification['fname'] = $obj->title;
$formattedNotify = [ $formattedNotify = [
'label' => 'friend', 'label' => 'friend',
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'], 'link' => $this->baseUrl->get(true) . '/display/' . $notification['parent-guid'],
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO), 'image' => ProxyUtils::proxifyUrl($notification['author-avatar'], false, ProxyUtils::SIZE_MICRO),
'url' => $notify['author-link'], 'url' => $notification['author-link'],
'text' => $this->l10n->t("%s is now friends with %s", $notify['author-name'], $notify['fname']), 'text' => $this->l10n->t("%s is now friends with %s", $notification['author-name'], $notification['fname']),
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
break; break;
@ -346,7 +346,7 @@ final class Notify
'text' => $default_item_text, 'text' => $default_item_text,
'when' => $default_item_when, 'when' => $default_item_when,
'ago' => $default_item_ago, 'ago' => $default_item_ago,
'seen' => $notify['seen'] 'seen' => $notification['seen']
]; ];
} }

View File

@ -8,7 +8,7 @@ use Friendica\Content\Pager;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Notify; use Friendica\Model\Notification;
use Friendica\Network\HTTPException\ForbiddenException; use Friendica\Network\HTTPException\ForbiddenException;
/** /**
@ -20,29 +20,29 @@ abstract class BaseNotifications extends BaseModule
{ {
/** @var array Array of URL parameters */ /** @var array Array of URL parameters */
const URL_TYPES = [ const URL_TYPES = [
Notify::NETWORK => 'network', Notification::NETWORK => 'network',
Notify::SYSTEM => 'system', Notification::SYSTEM => 'system',
Notify::HOME => 'home', Notification::HOME => 'home',
Notify::PERSONAL => 'personal', Notification::PERSONAL => 'personal',
Notify::INTRO => 'intros', Notification::INTRO => 'intros',
]; ];
/** @var array Array of the allowed notifies and their printable name */ /** @var array Array of the allowed notifies and their printable name */
const PRINT_TYPES = [ const PRINT_TYPES = [
Notify::NETWORK => 'Network', Notification::NETWORK => 'Network',
Notify::SYSTEM => 'System', Notification::SYSTEM => 'System',
Notify::HOME => 'Home', Notification::HOME => 'Home',
Notify::PERSONAL => 'Personal', Notification::PERSONAL => 'Personal',
Notify::INTRO => 'Introductions', Notification::INTRO => 'Introductions',
]; ];
/** @var array The array of access keys for notify pages */ /** @var array The array of access keys for notification pages */
const ACCESS_KEYS = [ const ACCESS_KEYS = [
Notify::NETWORK => 'w', Notification::NETWORK => 'w',
Notify::SYSTEM => 'y', Notification::SYSTEM => 'y',
Notify::HOME => 'h', Notification::HOME => 'h',
Notify::PERSONAL => 'r', Notification::PERSONAL => 'r',
Notify::INTRO => 'i', Notification::INTRO => 'i',
]; ];
/** @var int The default count of items per page */ /** @var int The default count of items per page */
@ -54,12 +54,12 @@ abstract class BaseNotifications extends BaseModule
protected static $firstItemNum; protected static $firstItemNum;
/** /**
* Collects all notifies from the backend * Collects all notifications from the backend
* *
* @return array The determined notification array * @return array The determined notification array
* ['header', 'notifs'] * ['header', 'notifications']
*/ */
abstract public static function getNotifies(); abstract public static function getNotifications();
public static function init(array $parameters = []) public static function init(array $parameters = [])
{ {
@ -104,22 +104,22 @@ abstract class BaseNotifications extends BaseModule
return; return;
} }
System::jsonExit(static::getNotifies()['notifs'] ?? []); System::jsonExit(static::getNotifications()['notifs'] ?? []);
} }
/** /**
* Shows the printable result of notifications for a specific tab * Shows the printable result of notifications for a specific tab
* *
* @param string $notif_header The notification header * @param string $header The notification header
* @param array $notif_content The array with the notifications * @param array $content The array with the notifications
* @param string $notif_nocontent The string in case there are no notifications * @param string $noContent The string in case there are no notifications
* @param array $notif_show_lnk The possible links at the top * @param array $showLink The possible links at the top
* *
* @return string The rendered output * @return string The rendered output
* *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
protected static function printContent(string $notif_header, array $notif_content, string $notif_nocontent, array $notif_show_lnk) protected static function printContent(string $header, array $content, string $noContent, array $showLink)
{ {
// Get the nav tabs for the notification pages // Get the nav tabs for the notification pages
$tabs = self::getTabs(); $tabs = self::getTabs();
@ -129,12 +129,12 @@ abstract class BaseNotifications extends BaseModule
$notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl'); $notif_tpl = Renderer::getMarkupTemplate('notifications/notifications.tpl');
return Renderer::replaceMacros($notif_tpl, [ return Renderer::replaceMacros($notif_tpl, [
'$notif_header' => $notif_header ?? DI::l10n()->t('Notifications'), '$notif_header' => $header ?? DI::l10n()->t('Notifications'),
'$tabs' => $tabs, '$tabs' => $tabs,
'$notif_content' => $notif_content, '$notif_content' => $content,
'$notif_nocontent' => $notif_nocontent, '$notif_nocontent' => $noContent,
'$notif_show_lnk' => $notif_show_lnk, '$notif_show_lnk' => $showLink,
'$notif_paginate' => $pager->renderMinimal(count($notif_content)) '$notif_paginate' => $pager->renderMinimal(count($content))
]); ]);
} }

View File

@ -18,16 +18,16 @@ class Introductions extends BaseNotifications
/** /**
* @inheritDoc * @inheritDoc
*/ */
public static function getNotifies() public static function getNotifications()
{ {
$id = (int)DI::args()->get(2, 0); $id = (int)DI::args()->get(2, 0);
$all = DI::args()->get(2) == 'all'; $all = DI::args()->get(2) == 'all';
$notifs = DI::notify()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id); $notifications = DI::notification()->getIntroList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id);
return [ return [
'header' => DI::l10n()->t('Notifications'), 'header' => DI::l10n()->t('Notifications'),
'notifs' => $notifs, 'notifications' => $notifications,
]; ];
} }
@ -37,52 +37,52 @@ class Introductions extends BaseNotifications
$all = DI::args()->get(2) == 'all'; $all = DI::args()->get(2) == 'all';
$notif_content = []; $notificationContent = [];
$notif_nocontent = ''; $notificationNoContent = '';
$notif_result = self::getNotifies(); $notificationResult = self::getNotifications();
$notifs = $notif_result['notifs'] ?? []; $notifications = $notificationResult['notifications'] ?? [];
$notif_header = $notif_result['header'] ?? ''; $notificationHeader = $notificationResult['header'] ?? '';
$sugg = Renderer::getMarkupTemplate('notifications/suggestions.tpl'); $notificationSuggestions = Renderer::getMarkupTemplate('notifications/suggestions.tpl');
$tpl = Renderer::getMarkupTemplate('notifications/intros.tpl'); $notificationTemplate = Renderer::getMarkupTemplate('notifications/intros.tpl');
// The link to switch between ignored and normal connection requests // The link to switch between ignored and normal connection requests
$notif_show_lnk = [ $notificationShowLink = [
'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'), 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'),
'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')) 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests'))
]; ];
// Loop through all introduction notifications.This creates an array with the output html for each // Loop through all introduction notifications.This creates an array with the output html for each
// introduction // introduction
foreach ($notifs['notifications'] as $notif) { foreach ($notifications['notifications'] as $notification) {
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. // 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. // We have to distinguish between these two because they use different data.
switch ($notif['label']) { switch ($notification['label']) {
case 'friend_suggestion': case 'friend_suggestion':
$notif_content[] = Renderer::replaceMacros($sugg, [ $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
'$type' => $notif['label'], '$type' => $notification['label'],
'$str_notifytype' => DI::l10n()->t('Notification type:'), '$str_notifytype' => DI::l10n()->t('Notification type:'),
'$notify_type' => $notif['notify_type'], '$notify_type' => $notification['notify_type'],
'$intro_id' => $notif['intro_id'], '$intro_id' => $notification['intro_id'],
'$lbl_madeby' => DI::l10n()->t('Suggested by:'), '$lbl_madeby' => DI::l10n()->t('Suggested by:'),
'$madeby' => $notif['madeby'], '$madeby' => $notification['madeby'],
'$madeby_url' => $notif['madeby_url'], '$madeby_url' => $notification['madeby_url'],
'$madeby_zrl' => $notif['madeby_zrl'], '$madeby_zrl' => $notification['madeby_zrl'],
'$madeby_addr' => $notif['madeby_addr'], '$madeby_addr' => $notification['madeby_addr'],
'$contact_id' => $notif['contact_id'], '$contact_id' => $notification['contact_id'],
'$photo' => $notif['photo'], '$photo' => $notification['photo'],
'$fullname' => $notif['name'], '$fullname' => $notification['name'],
'$url' => $notif['url'], '$url' => $notification['url'],
'$zrl' => $notif['zrl'], '$zrl' => $notification['zrl'],
'$lbl_url' => DI::l10n()->t('Profile URL'), '$lbl_url' => DI::l10n()->t('Profile URL'),
'$addr' => $notif['addr'], '$addr' => $notification['addr'],
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''],
'$knowyou' => $notif['knowyou'], '$knowyou' => $notification['knowyou'],
'$approve' => DI::l10n()->t('Approve'), '$approve' => DI::l10n()->t('Approve'),
'$note' => $notif['note'], '$note' => $notification['note'],
'$request' => $notif['request'], '$request' => $notification['request'],
'$ignore' => DI::l10n()->t('Ignore'), '$ignore' => DI::l10n()->t('Ignore'),
'$discard' => DI::l10n()->t('Discard'), '$discard' => DI::l10n()->t('Discard'),
]); ]);
@ -90,8 +90,8 @@ class Introductions extends BaseNotifications
// Normal connection requests // Normal connection requests
default: default:
$friend_selected = (($notif['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled '); $friend_selected = (($notification['network'] !== Protocol::OSTATUS) ? ' checked="checked" ' : ' disabled ');
$fan_selected = (($notif['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : ''); $fan_selected = (($notification['network'] === Protocol::OSTATUS) ? ' checked="checked" disabled ' : '');
$lbl_knowyou = ''; $lbl_knowyou = '';
$knowyou = ''; $knowyou = '';
@ -99,31 +99,31 @@ class Introductions extends BaseNotifications
$helptext2 = ''; $helptext2 = '';
$helptext3 = ''; $helptext3 = '';
if ($notif['network'] === Protocol::DFRN) { if ($notification['network'] === Protocol::DFRN) {
$lbl_knowyou = DI::l10n()->t('Claims to be known to you: '); $lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
$knowyou = (($notif['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no')); $knowyou = (($notification['knowyou']) ? DI::l10n()->t('yes') : DI::l10n()->t('no'));
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
$helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']);
$helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']);
} elseif ($notif['network'] === Protocol::DIASPORA) { } elseif ($notification['network'] === Protocol::DIASPORA) {
$helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?');
$helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notif['name'], $notif['name']); $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification['name'], $notification['name']);
$helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notif['name']); $helptext3 = DI::l10n()->t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification['name']);
} }
$dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl'); $dfrn_tpl = Renderer::getMarkupTemplate('notifications/netfriend.tpl');
$dfrn_text = Renderer::replaceMacros($dfrn_tpl, [ $dfrn_text = Renderer::replaceMacros($dfrn_tpl, [
'$intro_id' => $notif['intro_id'], '$intro_id' => $notification['intro_id'],
'$friend_selected' => $friend_selected, '$friend_selected' => $friend_selected,
'$fan_selected' => $fan_selected, '$fan_selected' => $fan_selected,
'$approve_as1' => $helptext, '$approve_as1' => $helptext,
'$approve_as2' => $helptext2, '$approve_as2' => $helptext2,
'$approve_as3' => $helptext3, '$approve_as3' => $helptext3,
'$as_friend' => DI::l10n()->t('Friend'), '$as_friend' => DI::l10n()->t('Friend'),
'$as_fan' => (($notif['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber')) '$as_fan' => (($notification['network'] == Protocol::DIASPORA) ? DI::l10n()->t('Sharer') : DI::l10n()->t('Subscriber'))
]); ]);
$contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notif['contact_id']]); $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notification['contact_id']]);
if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) { if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) {
$action = 'follow_confirm'; $action = 'follow_confirm';
@ -131,51 +131,51 @@ class Introductions extends BaseNotifications
$action = 'dfrn_confirm'; $action = 'dfrn_confirm';
} }
$header = $notif['name']; $header = $notification['name'];
if ($notif['addr'] != '') { if ($notification['addr'] != '') {
$header .= ' <' . $notif['addr'] . '>'; $header .= ' <' . $notification['addr'] . '>';
} }
$header .= ' (' . ContactSelector::networkToName($notif['network'], $notif['url']) . ')'; $header .= ' (' . ContactSelector::networkToName($notification['network'], $notification['url']) . ')';
if ($notif['network'] != Protocol::DIASPORA) { if ($notification['network'] != Protocol::DIASPORA) {
$discard = DI::l10n()->t('Discard'); $discard = DI::l10n()->t('Discard');
} else { } else {
$discard = ''; $discard = '';
} }
$notif_content[] = Renderer::replaceMacros($tpl, [ $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
'$type' => $notif['label'], '$type' => $notification['label'],
'$header' => $header, '$header' => $header,
'$str_notifytype' => DI::l10n()->t('Notification type:'), '$str_notifytype' => DI::l10n()->t('Notification type:'),
'$notify_type' => $notif['notify_type'], '$notify_type' => $notification['notify_type'],
'$dfrn_text' => $dfrn_text, '$dfrn_text' => $dfrn_text,
'$dfrn_id' => $notif['dfrn_id'], '$dfrn_id' => $notification['dfrn_id'],
'$uid' => $notif['uid'], '$uid' => $notification['uid'],
'$intro_id' => $notif['intro_id'], '$intro_id' => $notification['intro_id'],
'$contact_id' => $notif['contact_id'], '$contact_id' => $notification['contact_id'],
'$photo' => $notif['photo'], '$photo' => $notification['photo'],
'$fullname' => $notif['name'], '$fullname' => $notification['name'],
'$location' => $notif['location'], '$location' => $notification['location'],
'$lbl_location' => DI::l10n()->t('Location:'), '$lbl_location' => DI::l10n()->t('Location:'),
'$about' => $notif['about'], '$about' => $notification['about'],
'$lbl_about' => DI::l10n()->t('About:'), '$lbl_about' => DI::l10n()->t('About:'),
'$keywords' => $notif['keywords'], '$keywords' => $notification['keywords'],
'$lbl_keywords' => DI::l10n()->t('Tags:'), '$lbl_keywords' => DI::l10n()->t('Tags:'),
'$gender' => $notif['gender'], '$gender' => $notification['gender'],
'$lbl_gender' => DI::l10n()->t('Gender:'), '$lbl_gender' => DI::l10n()->t('Gender:'),
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notif['hidden'] == 1), ''], '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), ($notification['hidden'] == 1), ''],
'$url' => $notif['url'], '$url' => $notification['url'],
'$zrl' => $notif['zrl'], '$zrl' => $notification['zrl'],
'$lbl_url' => DI::l10n()->t('Profile URL'), '$lbl_url' => DI::l10n()->t('Profile URL'),
'$addr' => $notif['addr'], '$addr' => $notification['addr'],
'$lbl_knowyou' => $lbl_knowyou, '$lbl_knowyou' => $lbl_knowyou,
'$lbl_network' => DI::l10n()->t('Network:'), '$lbl_network' => DI::l10n()->t('Network:'),
'$network' => ContactSelector::networkToName($notif['network'], $notif['url']), '$network' => ContactSelector::networkToName($notification['network'], $notification['url']),
'$knowyou' => $knowyou, '$knowyou' => $knowyou,
'$approve' => DI::l10n()->t('Approve'), '$approve' => DI::l10n()->t('Approve'),
'$note' => $notif['note'], '$note' => $notification['note'],
'$ignore' => DI::l10n()->t('Ignore'), '$ignore' => DI::l10n()->t('Ignore'),
'$discard' => $discard, '$discard' => $discard,
'$action' => $action, '$action' => $action,
@ -184,11 +184,11 @@ class Introductions extends BaseNotifications
} }
} }
if (count($notifs['notifications']) == 0) { if (count($notifications['notifications']) == 0) {
info(DI::l10n()->t('No introductions.') . EOL); info(DI::l10n()->t('No introductions.') . EOL);
$notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']); $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
} }
return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk); return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
} }
} }

View File

@ -8,9 +8,9 @@ use Friendica\DI;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
/** /**
* Interacting with the /notify command * Interacting with the /notification command
*/ */
class Notify extends BaseModule class Notification extends BaseModule
{ {
public static function init(array $parameters = []) public static function init(array $parameters = [])
{ {
@ -21,11 +21,9 @@ class Notify extends BaseModule
public static function rawContent(array $parameters = []) public static function rawContent(array $parameters = [])
{ {
$a = DI::app();
// @TODO: Replace with parameter from router // @TODO: Replace with parameter from router
if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') { if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
$success = DI::notify()->setAllSeen(); $success = DI::notification()->setAllSeen();
header('Content-type: application/json; charset=utf-8'); header('Content-type: application/json; charset=utf-8');
echo json_encode([ echo json_encode([
@ -36,22 +34,20 @@ class Notify extends BaseModule
} }
/** /**
* Redirect to the notifications main page or to the url for the chosen notify * Redirect to the notifications main page or to the url for the chosen notifications
* *
* @return string|void * @return string|void
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
*/ */
public static function content(array $parameters = []) public static function content(array $parameters = [])
{ {
$a = DI::app();
// @TODO: Replace with parameter from router // @TODO: Replace with parameter from router
if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) { if (DI::args()->getArgc() > 2 && DI::args()->get(1) === 'view' && intval(DI::args()->get(2))) {
$notificationsManager = DI::notify(); $notificationManager = DI::notification();
// @TODO: Replace with parameter from router // @TODO: Replace with parameter from router
$note = $notificationsManager->getByID($a->argv[2]); $note = $notificationManager->getByID(DI::args()->get(2));
if (!empty($note)) { if (!empty($note)) {
$notificationsManager->setSeen($note); $notificationManager->setSeen($note);
if (!empty($note['link'])) { if (!empty($note['link'])) {
System::externalRedirect($note['link']); System::externalRedirect($note['link']);
} }

View File

@ -20,31 +20,31 @@ class Notifications extends BaseNotifications
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public static function getNotifies() public static function getNotifications()
{ {
$nm = DI::notify(); $nm = DI::notification();
$notif_header = ''; $notificationHeader = '';
// Get the network notifications // Get the network notifications
if ((DI::args()->get(1) == 'network')) { if ((DI::args()->get(1) == 'network')) {
$notif_header = DI::l10n()->t('Network Notifications'); $notificationHeader = DI::l10n()->t('Network Notifications');
$notifs = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); $notifications = $nm->getNetworkList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
// Get the system notifications // Get the system notifications
} elseif ((DI::args()->get(1) == 'system')) { } elseif ((DI::args()->get(1) == 'system')) {
$notif_header = DI::l10n()->t('System Notifications'); $notificationHeader = DI::l10n()->t('System Notifications');
$notifs = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); $notifications = $nm->getSystemList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
// Get the personal notifications // Get the personal notifications
} elseif ((DI::args()->get(1) == 'personal')) { } elseif ((DI::args()->get(1) == 'personal')) {
$notif_header = DI::l10n()->t('Personal Notifications'); $notificationHeader = DI::l10n()->t('Personal Notifications');
$notifs = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); $notifications = $nm->getPersonalList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
// Get the home notifications // Get the home notifications
} elseif ((DI::args()->get(1) == 'home')) { } elseif ((DI::args()->get(1) == 'home')) {
$notif_header = DI::l10n()->t('Home Notifications'); $notificationHeader = DI::l10n()->t('Home Notifications');
$notifs = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE); $notifications = $nm->getHomeList(self::$showAll, self::$firstItemNum, self::ITEMS_PER_PAGE);
// fallback - redirect to main page // fallback - redirect to main page
} else { } else {
DI::baseUrl()->redirect('notifications'); DI::baseUrl()->redirect('notifications');
@ -54,12 +54,12 @@ class Notifications extends BaseNotifications
$pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE); $pager = new Pager(DI::args()->getQueryString(), self::ITEMS_PER_PAGE);
// Add additional informations (needed for json output) // Add additional informations (needed for json output)
$notifs['items_page'] = $pager->getItemsPerPage(); $notifications['items_page'] = $pager->getItemsPerPage();
$notifs['page'] = $pager->getPage(); $notifications['page'] = $pager->getPage();
return [ return [
'header' => $notif_header, 'header' => $notificationHeader,
'notifs' => $notifs, 'notifications' => $notifications,
]; ];
} }
@ -67,18 +67,18 @@ class Notifications extends BaseNotifications
{ {
Nav::setSelected('notifications'); Nav::setSelected('notifications');
$notif_content = []; $notificationContent = [];
$notif_nocontent = ''; $notificationNoContent = '';
$notif_result = self::getNotifies(); $notificationResult = self::getNotifications();
$notifs = $notif_result['notifs'] ?? []; $notifications = $notificationResult['notifications'] ?? [];
$notif_header = $notif_result['header'] ?? ''; $notificationHeader = $notificationResult['header'] ?? '';
if (!empty($notifs['notifications'])) { if (!empty($notifications['notifications'])) {
// Loop trough ever notification This creates an array with the output html for each // 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). // notification and apply the correct template according to the notificationtype (label).
foreach ($notifs['notifications'] as $notif) { foreach ($notifications['notifications'] as $notification) {
$notification_templates = [ $notification_templates = [
'like' => 'notifications/likes_item.tpl', 'like' => 'notifications/likes_item.tpl',
'dislike' => 'notifications/dislikes_item.tpl', 'dislike' => 'notifications/dislikes_item.tpl',
@ -88,31 +88,31 @@ class Notifications extends BaseNotifications
'friend' => 'notifications/friends_item.tpl', 'friend' => 'notifications/friends_item.tpl',
'comment' => 'notifications/comments_item.tpl', 'comment' => 'notifications/comments_item.tpl',
'post' => 'notifications/posts_item.tpl', 'post' => 'notifications/posts_item.tpl',
'notify' => 'notifications/notify.tpl', 'notification' => 'notifications/notification.tpl',
]; ];
$tpl_notif = Renderer::getMarkupTemplate($notification_templates[$notif['label']]); $notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification['label']]);
$notif_content[] = Renderer::replaceMacros($tpl_notif, [ $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
'$item_label' => $notif['label'], '$item_label' => $notification['label'],
'$item_link' => $notif['link'], '$item_link' => $notification['link'],
'$item_image' => $notif['image'], '$item_image' => $notification['image'],
'$item_url' => $notif['url'], '$item_url' => $notification['url'],
'$item_text' => $notif['text'], '$item_text' => $notification['text'],
'$item_when' => $notif['when'], '$item_when' => $notification['when'],
'$item_ago' => $notif['ago'], '$item_ago' => $notification['ago'],
'$item_seen' => $notif['seen'], '$item_seen' => $notification['seen'],
]); ]);
} }
} else { } else {
$notif_nocontent = DI::l10n()->t('No more %s notifications.', $notifs['ident']); $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']);
} }
$notif_show_lnk = [ $notificationShowLink = [
'href' => (self::$showAll ? 'notifications/' . $notifs['ident'] : 'notifications/' . $notifs['ident'] . '?show=all'), 'href' => (self::$showAll ? 'notifications/' . $notifications['ident'] : 'notifications/' . $notifications['ident'] . '?show=all'),
'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')), 'text' => (self::$showAll ? DI::l10n()->t('Show unread') : DI::l10n()->t('Show all')),
]; ];
return self::printContent($notif_header, $notif_content, $notif_nocontent, $notif_show_lnk); return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink);
} }
} }

View File

@ -177,10 +177,10 @@ return [
'/intros/{contact:\d+}[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]], '/intros/{contact:\d+}[/json]' => [Module\Notifications\Introductions::class, [R::GET, R::POST]],
], ],
'/notify' => [ '/notification' => [
'[/]' => [Module\Notifications\Notify::class, [R::GET]], '[/]' => [Module\Notifications\Notification::class, [R::GET]],
'/view/{id:\d+}' => [Module\Notifications\Notify::class, [R::GET]], '/view/{id:\d+}' => [Module\Notifications\Notification::class, [R::GET]],
'/mark/all' => [Module\Notifications\Notify::class, [R::GET]], '/mark/all' => [Module\Notifications\Notification::class, [R::GET]],
], ],
'/objects/{guid}' => [Module\Objects::class, [R::GET]], '/objects/{guid}' => [Module\Objects::class, [R::GET]],

View File

@ -949,7 +949,7 @@ function checkboxhighlight(box) {
} }
function notifyMarkAll() { function notifyMarkAll() {
$.get('notify/mark/all', function(data) { $.get('notification/mark/all', function(data) {
if (timer) { if (timer) {
clearTimeout(timer); clearTimeout(timer);
} }

View File

@ -1,2 +1,2 @@
{{include file="notifications/notify.tpl"}} {{include file="notifications/notification.tpl"}}

View File

@ -1,2 +1,2 @@
{{include file="notifications/notify.tpl"}} {{include file="notifications/notification.tpl"}}

View File

@ -1,2 +1,2 @@
{{include file="notifications/notify.tpl"}} {{include file="notifications/notification.tpl"}}

View File

@ -1,2 +1,2 @@
{{include file="notifications/notify.tpl"}} {{include file="notifications/notification.tpl"}}

View File

@ -1,2 +1,2 @@
{{include file="notifications/notify.tpl"}} {{include file="notifications/notification.tpl"}}

View File

@ -1,2 +1,2 @@
{{include file="notifications/notify.tpl"}} {{include file="notifications/notification.tpl"}}

View File

@ -1,2 +1,2 @@
{{include file="notifications/notify.tpl"}} {{include file="notifications/notification.tpl"}}