mirror of
https://github.com/friendica/friendica
synced 2025-04-23 09:10:10 +00:00
Merge pull request #10722 from MrPetovan/task/refactor-notifications
Move notify, notifications and introduction notifications to new paradigm
This commit is contained in:
commit
3d97149007
57 changed files with 2452 additions and 1948 deletions
|
@ -28,6 +28,8 @@ use Friendica\Model\Contact;
|
|||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Verb;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Navigation\Notifications\Entity;
|
||||
use Friendica\Object\Api\Mastodon\Notification;
|
||||
use Friendica\Protocol\Activity;
|
||||
|
||||
/**
|
||||
|
@ -46,10 +48,12 @@ class Notifications extends BaseApi
|
|||
|
||||
if (!empty($parameters['id'])) {
|
||||
$id = $parameters['id'];
|
||||
if (!DBA::exists('notification', ['id' => $id, 'uid' => $uid])) {
|
||||
try {
|
||||
$notification = DI::notification()->selectOneForUser($uid, ['id' => $id]);
|
||||
System::jsonExit(DI::mstdnNotification()->createFromNotification($notification));
|
||||
} catch (\Exception $e) {
|
||||
DI::mstdnError()->RecordNotFound();
|
||||
}
|
||||
System::jsonExit(DI::mstdnNotification()->createFromNotificationId($id));
|
||||
}
|
||||
|
||||
$request = self::getRequest([
|
||||
|
@ -63,7 +67,7 @@ class Notifications extends BaseApi
|
|||
'count' => 0, // Unknown parameter
|
||||
]);
|
||||
|
||||
$params = ['order' => ['id' => true], 'limit' => $request['limit']];
|
||||
$params = ['order' => ['id' => true]];
|
||||
|
||||
$condition = ['uid' => $uid, 'seen' => false];
|
||||
|
||||
|
@ -74,72 +78,67 @@ class Notifications extends BaseApi
|
|||
}
|
||||
}
|
||||
|
||||
if (in_array('follow_request', $request['exclude_types'])) {
|
||||
if (in_array(Notification::TYPE_INTRODUCTION, $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
["(`vid` != ? OR `type` != ? OR NOT EXISTS (SELECT `id` FROM `contact` WHERE `id` = `actor-id` AND `pending`))",
|
||||
Verb::getID(Activity::FOLLOW), Post\UserNotification::NOTIF_NONE]);
|
||||
Verb::getID(Activity::FOLLOW), Post\UserNotification::TYPE_NONE]);
|
||||
}
|
||||
|
||||
if (in_array('follow', $request['exclude_types'])) {
|
||||
if (in_array(Notification::TYPE_FOLLOW, $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
["(`vid` != ? OR `type` != ? OR NOT EXISTS (SELECT `id` FROM `contact` WHERE `id` = `actor-id` AND NOT `pending`))",
|
||||
Verb::getID(Activity::FOLLOW), Post\UserNotification::NOTIF_NONE]);
|
||||
Verb::getID(Activity::FOLLOW), Post\UserNotification::TYPE_NONE]);
|
||||
}
|
||||
|
||||
if (in_array('favourite', $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?, ?) OR NOT `type` IN (?, ?))",
|
||||
if (in_array(Notification::TYPE_LIKE, $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition, [
|
||||
"(NOT `vid` IN (?, ?) OR NOT `type` IN (?, ?))",
|
||||
Verb::getID(Activity::LIKE), Verb::getID(Activity::DISLIKE),
|
||||
Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT]);
|
||||
Post\UserNotification::TYPE_DIRECT_COMMENT, Post\UserNotification::TYPE_THREAD_COMMENT
|
||||
]);
|
||||
}
|
||||
|
||||
if (in_array('reblog', $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?) OR NOT `type` IN (?, ?))",
|
||||
if (in_array(Notification::TYPE_RESHARE, $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition, [
|
||||
"(NOT `vid` IN (?) OR NOT `type` IN (?, ?))",
|
||||
Verb::getID(Activity::ANNOUNCE),
|
||||
Post\UserNotification::NOTIF_DIRECT_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT]);
|
||||
Post\UserNotification::TYPE_DIRECT_COMMENT, Post\UserNotification::TYPE_THREAD_COMMENT
|
||||
]);
|
||||
}
|
||||
|
||||
if (in_array('mention', $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?) OR NOT `type` IN (?, ?, ?, ?, ?))",
|
||||
Verb::getID(Activity::POST), Post\UserNotification::NOTIF_EXPLICIT_TAGGED,
|
||||
Post\UserNotification::NOTIF_IMPLICIT_TAGGED, Post\UserNotification::NOTIF_DIRECT_COMMENT,
|
||||
Post\UserNotification::NOTIF_DIRECT_THREAD_COMMENT, Post\UserNotification::NOTIF_THREAD_COMMENT]);
|
||||
if (in_array(Notification::TYPE_MENTION, $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition, [
|
||||
"(NOT `vid` IN (?) OR NOT `type` IN (?, ?, ?, ?, ?))",
|
||||
Verb::getID(Activity::POST), Post\UserNotification::TYPE_EXPLICIT_TAGGED,
|
||||
Post\UserNotification::TYPE_IMPLICIT_TAGGED, Post\UserNotification::TYPE_DIRECT_COMMENT,
|
||||
Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT, Post\UserNotification::TYPE_THREAD_COMMENT]);
|
||||
}
|
||||
|
||||
if (in_array('status', $request['exclude_types'])) {
|
||||
if (in_array(Notification::TYPE_POST, $request['exclude_types'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["(NOT `vid` IN (?) OR NOT `type` IN (?))",
|
||||
Verb::getID(Activity::POST), Post\UserNotification::NOTIF_SHARED]);
|
||||
Verb::getID(Activity::POST), Post\UserNotification::TYPE_SHARED]);
|
||||
}
|
||||
|
||||
if (!empty($request['max_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` < ?", $request['max_id']]);
|
||||
}
|
||||
$mstdnNotifications = [];
|
||||
|
||||
if (!empty($request['since_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` > ?", $request['since_id']]);
|
||||
}
|
||||
$Notifications = DI::notification()->selectByBoundaries(
|
||||
$condition,
|
||||
$params,
|
||||
$request['min_id'] ?? null,
|
||||
$request['min_id'] ?? $request['since_id'] ?? null,
|
||||
$request['limit']
|
||||
);
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
$condition = DBA::mergeConditions($condition, ["`id` > ?", $request['min_id']]);
|
||||
|
||||
$params['order'] = ['id'];
|
||||
}
|
||||
|
||||
$notifications = [];
|
||||
|
||||
$notify = DBA::select('notification', ['id'], $condition, $params);
|
||||
while ($notification = DBA::fetch($notify)) {
|
||||
self::setBoundaries($notification['id']);
|
||||
$entry = DI::mstdnNotification()->createFromNotificationId($notification['id']);
|
||||
if (!empty($entry)) {
|
||||
$notifications[] = $entry;
|
||||
foreach($Notifications as $Notification) {
|
||||
try {
|
||||
$mstdnNotifications[] = DI::mstdnNotification()->createFromNotification($Notification);
|
||||
self::setBoundaries($Notification->id);
|
||||
} catch (\Exception $e) {
|
||||
// Skip this notification
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($request['min_id'])) {
|
||||
array_reverse($notifications);
|
||||
}
|
||||
|
||||
self::setLinkHeader();
|
||||
System::jsonExit($notifications);
|
||||
System::jsonExit($mstdnNotifications);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
namespace Friendica\Module\Api\Mastodon\Notifications;
|
||||
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +35,7 @@ class Clear extends BaseApi
|
|||
self::checkAllowedScope(self::SCOPE_WRITE);
|
||||
$uid = self::getCurrentUserID();
|
||||
|
||||
DBA::update('notification', ['seen' => true], ['uid' => $uid]);
|
||||
DI::notification()->setAllSeenForUser($uid);
|
||||
|
||||
System::jsonExit([]);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ use Friendica\Core\System;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException\ForbiddenException;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/notifications/
|
||||
|
@ -40,7 +41,9 @@ class Dismiss extends BaseApi
|
|||
DI::mstdnError()->UnprocessableEntity();
|
||||
}
|
||||
|
||||
DBA::update('notification', ['seen' => true], ['uid' => $uid, 'id' => $parameters['id']]);
|
||||
$Notification = DI::notification()->selectOneForUser($uid, $parameters['id']);
|
||||
$Notification->setSeen();
|
||||
DI::notification()->save($Notification);
|
||||
|
||||
System::jsonExit([]);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ use Friendica\Core\System;
|
|||
use Friendica\DI;
|
||||
use Friendica\Model\Subscription;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Object\Api\Mastodon\Notification;
|
||||
|
||||
/**
|
||||
* @see https://docs.joinmastodon.org/methods/notifications/push/
|
||||
|
@ -44,18 +45,18 @@ class PushSubscription extends BaseApi
|
|||
]);
|
||||
|
||||
$subscription = [
|
||||
'application-id' => $application['id'],
|
||||
'uid' => $uid,
|
||||
'endpoint' => $request['subscription']['endpoint'] ?? '',
|
||||
'pubkey' => $request['subscription']['keys']['p256dh'] ?? '',
|
||||
'secret' => $request['subscription']['keys']['auth'] ?? '',
|
||||
'follow' => $request['data']['alerts']['follow'] ?? false,
|
||||
'favourite' => $request['data']['alerts']['favourite'] ?? false,
|
||||
'reblog' => $request['data']['alerts']['reblog'] ?? false,
|
||||
'mention' => $request['data']['alerts']['mention'] ?? false,
|
||||
'poll' => $request['data']['alerts']['poll'] ?? false,
|
||||
'follow_request' => $request['data']['alerts']['follow_request'] ?? false,
|
||||
'status' => $request['data']['alerts']['status'] ?? false,
|
||||
'application-id' => $application['id'],
|
||||
'uid' => $uid,
|
||||
'endpoint' => $request['subscription']['endpoint'] ?? '',
|
||||
'pubkey' => $request['subscription']['keys']['p256dh'] ?? '',
|
||||
'secret' => $request['subscription']['keys']['auth'] ?? '',
|
||||
Notification::TYPE_FOLLOW => $request['data']['alerts'][Notification::TYPE_FOLLOW] ?? false,
|
||||
Notification::TYPE_LIKE => $request['data']['alerts'][Notification::TYPE_LIKE] ?? false,
|
||||
Notification::TYPE_RESHARE => $request['data']['alerts'][Notification::TYPE_RESHARE] ?? false,
|
||||
Notification::TYPE_MENTION => $request['data']['alerts'][Notification::TYPE_MENTION] ?? false,
|
||||
Notification::TYPE_POLL => $request['data']['alerts'][Notification::TYPE_POLL] ?? false,
|
||||
Notification::TYPE_INTRODUCTION => $request['data']['alerts'][Notification::TYPE_INTRODUCTION] ?? false,
|
||||
Notification::TYPE_POST => $request['data']['alerts'][Notification::TYPE_POST] ?? false,
|
||||
];
|
||||
|
||||
$ret = Subscription::replace($subscription);
|
||||
|
@ -82,13 +83,13 @@ class PushSubscription extends BaseApi
|
|||
}
|
||||
|
||||
$fields = [
|
||||
'follow' => $request['data']['alerts']['follow'] ?? false,
|
||||
'favourite' => $request['data']['alerts']['favourite'] ?? false,
|
||||
'reblog' => $request['data']['alerts']['reblog'] ?? false,
|
||||
'mention' => $request['data']['alerts']['mention'] ?? false,
|
||||
'poll' => $request['data']['alerts']['poll'] ?? false,
|
||||
'follow_request' => $request['data']['alerts']['follow_request'] ?? false,
|
||||
'status' => $request['data']['alerts']['status'] ?? false,
|
||||
Notification::TYPE_FOLLOW => $request['data']['alerts'][Notification::TYPE_FOLLOW] ?? false,
|
||||
Notification::TYPE_LIKE => $request['data']['alerts'][Notification::TYPE_LIKE] ?? false,
|
||||
Notification::TYPE_RESHARE => $request['data']['alerts'][Notification::TYPE_RESHARE] ?? false,
|
||||
Notification::TYPE_MENTION => $request['data']['alerts'][Notification::TYPE_MENTION] ?? false,
|
||||
Notification::TYPE_POLL => $request['data']['alerts'][Notification::TYPE_POLL] ?? false,
|
||||
Notification::TYPE_INTRODUCTION => $request['data']['alerts'][Notification::TYPE_INTRODUCTION] ?? false,
|
||||
Notification::TYPE_POST => $request['data']['alerts'][Notification::TYPE_POST] ?? false,
|
||||
];
|
||||
|
||||
$ret = Subscription::update($application['id'], $uid, $fields);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -26,11 +26,10 @@ use Friendica\Content\Nav;
|
|||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseNotifications;
|
||||
use Friendica\Object\Notification\Introduction;
|
||||
use Friendica\Navigation\Notifications\ValueObject\Introduction;
|
||||
|
||||
/**
|
||||
* Prints notifications about introduction
|
||||
|
@ -82,34 +81,34 @@ class Introductions extends BaseNotifications
|
|||
|
||||
// Loop through all introduction notifications.This creates an array with the output html for each
|
||||
// introduction
|
||||
/** @var Introduction $notification */
|
||||
foreach ($notifications['notifications'] as $notification) {
|
||||
/** @var Introduction $Introduction */
|
||||
foreach ($notifications['notifications'] as $Introduction) {
|
||||
|
||||
// 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.
|
||||
switch ($notification->getLabel()) {
|
||||
switch ($Introduction->getLabel()) {
|
||||
case 'friend_suggestion':
|
||||
$notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [
|
||||
'$type' => $notification->getLabel(),
|
||||
'$type' => $Introduction->getLabel(),
|
||||
'$str_notification_type' => DI::l10n()->t('Notification type:'),
|
||||
'$str_type' => $notification->getType(),
|
||||
'$intro_id' => $notification->getIntroId(),
|
||||
'$str_type' => $Introduction->getType(),
|
||||
'$intro_id' => $Introduction->getIntroId(),
|
||||
'$lbl_madeby' => DI::l10n()->t('Suggested by:'),
|
||||
'$madeby' => $notification->getMadeBy(),
|
||||
'$madeby_url' => $notification->getMadeByUrl(),
|
||||
'$madeby_zrl' => $notification->getMadeByZrl(),
|
||||
'$madeby_addr' => $notification->getMadeByAddr(),
|
||||
'$contact_id' => $notification->getContactId(),
|
||||
'$photo' => $notification->getPhoto(),
|
||||
'$fullname' => $notification->getName(),
|
||||
'$madeby' => $Introduction->getMadeBy(),
|
||||
'$madeby_url' => $Introduction->getMadeByUrl(),
|
||||
'$madeby_zrl' => $Introduction->getMadeByZrl(),
|
||||
'$madeby_addr' => $Introduction->getMadeByAddr(),
|
||||
'$contact_id' => $Introduction->getContactId(),
|
||||
'$photo' => $Introduction->getPhoto(),
|
||||
'$fullname' => $Introduction->getName(),
|
||||
'$dfrn_url' => $owner['url'],
|
||||
'$url' => $notification->getUrl(),
|
||||
'$zrl' => $notification->getZrl(),
|
||||
'$url' => $Introduction->getUrl(),
|
||||
'$zrl' => $Introduction->getZrl(),
|
||||
'$lbl_url' => DI::l10n()->t('Profile URL'),
|
||||
'$addr' => $notification->getAddr(),
|
||||
'$addr' => $Introduction->getAddr(),
|
||||
'$action' => 'follow',
|
||||
'$approve' => DI::l10n()->t('Approve'),
|
||||
'$note' => $notification->getNote(),
|
||||
'$note' => $Introduction->getNote(),
|
||||
'$ignore' => DI::l10n()->t('Ignore'),
|
||||
'$discard' => DI::l10n()->t('Discard'),
|
||||
'$is_mobile' => DI::mode()->isMobile(),
|
||||
|
@ -118,15 +117,15 @@ class Introductions extends BaseNotifications
|
|||
|
||||
// Normal connection requests
|
||||
default:
|
||||
if ($notification->getNetwork() === Protocol::DFRN) {
|
||||
if ($Introduction->getNetwork() === Protocol::DFRN) {
|
||||
$lbl_knowyou = DI::l10n()->t('Claims to be known to you: ');
|
||||
$knowyou = ($notification->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No'));
|
||||
$knowyou = ($Introduction->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No'));
|
||||
} else {
|
||||
$lbl_knowyou = '';
|
||||
$knowyou = '';
|
||||
}
|
||||
|
||||
$convertedName = BBCode::convert($notification->getName());
|
||||
$convertedName = BBCode::convert($Introduction->getName());
|
||||
|
||||
$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.', $convertedName, $convertedName);
|
||||
|
@ -137,51 +136,51 @@ class Introductions extends BaseNotifications
|
|||
|
||||
$action = 'follow_confirm';
|
||||
|
||||
$header = $notification->getName();
|
||||
$header = $Introduction->getName();
|
||||
|
||||
if ($notification->getAddr() != '') {
|
||||
$header .= ' <' . $notification->getAddr() . '>';
|
||||
if ($Introduction->getAddr() != '') {
|
||||
$header .= ' <' . $Introduction->getAddr() . '>';
|
||||
}
|
||||
|
||||
$header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')';
|
||||
$header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')';
|
||||
|
||||
if ($notification->getNetwork() != Protocol::DIASPORA) {
|
||||
if ($Introduction->getNetwork() != Protocol::DIASPORA) {
|
||||
$discard = DI::l10n()->t('Discard');
|
||||
} else {
|
||||
$discard = '';
|
||||
}
|
||||
|
||||
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
|
||||
'$type' => $notification->getLabel(),
|
||||
'$type' => $Introduction->getLabel(),
|
||||
'$header' => $header,
|
||||
'$str_notification_type' => DI::l10n()->t('Notification type:'),
|
||||
'$str_type' => $notification->getType(),
|
||||
'$dfrn_id' => $notification->getDfrnId(),
|
||||
'$uid' => $notification->getUid(),
|
||||
'$intro_id' => $notification->getIntroId(),
|
||||
'$contact_id' => $notification->getContactId(),
|
||||
'$photo' => $notification->getPhoto(),
|
||||
'$fullname' => $notification->getName(),
|
||||
'$location' => $notification->getLocation(),
|
||||
'$str_type' => $Introduction->getType(),
|
||||
'$dfrn_id' => $Introduction->getDfrnId(),
|
||||
'$uid' => $Introduction->getUid(),
|
||||
'$intro_id' => $Introduction->getIntroId(),
|
||||
'$contact_id' => $Introduction->getContactId(),
|
||||
'$photo' => $Introduction->getPhoto(),
|
||||
'$fullname' => $Introduction->getName(),
|
||||
'$location' => $Introduction->getLocation(),
|
||||
'$lbl_location' => DI::l10n()->t('Location:'),
|
||||
'$about' => $notification->getAbout(),
|
||||
'$about' => $Introduction->getAbout(),
|
||||
'$lbl_about' => DI::l10n()->t('About:'),
|
||||
'$keywords' => $notification->getKeywords(),
|
||||
'$keywords' => $Introduction->getKeywords(),
|
||||
'$lbl_keywords' => DI::l10n()->t('Tags:'),
|
||||
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''],
|
||||
'$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $Introduction->isHidden(), ''],
|
||||
'$lbl_connection_type' => $helptext,
|
||||
'$friend' => $friend,
|
||||
'$follower' => $follower,
|
||||
'$url' => $notification->getUrl(),
|
||||
'$zrl' => $notification->getZrl(),
|
||||
'$url' => $Introduction->getUrl(),
|
||||
'$zrl' => $Introduction->getZrl(),
|
||||
'$lbl_url' => DI::l10n()->t('Profile URL'),
|
||||
'$addr' => $notification->getAddr(),
|
||||
'$addr' => $Introduction->getAddr(),
|
||||
'$lbl_knowyou' => $lbl_knowyou,
|
||||
'$lbl_network' => DI::l10n()->t('Network:'),
|
||||
'$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()),
|
||||
'$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()),
|
||||
'$knowyou' => $knowyou,
|
||||
'$approve' => DI::l10n()->t('Approve'),
|
||||
'$note' => $notification->getNote(),
|
||||
'$note' => $Introduction->getNote(),
|
||||
'$ignore' => DI::l10n()->t('Ignore'),
|
||||
'$discard' => $discard,
|
||||
'$action' => $action,
|
||||
|
|
|
@ -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::notification()->setAllSeenForUser(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::notification()->setAllSeenForUser($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 '';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,34 @@ class Notifications extends BaseNotifications
|
|||
public static function getNotifications()
|
||||
{
|
||||
$notificationHeader = '';
|
||||
/** @var Notification[] $notifications */
|
||||
$notifications = [];
|
||||
|
||||
// Get the network notifications
|
||||
$factory = DI::formattedNotificationFactory();
|
||||
|
||||
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,39 +93,32 @@ class Notifications extends BaseNotifications
|
|||
$notifications = $notificationResult['notifications'] ?? [];
|
||||
$notificationHeader = $notificationResult['header'] ?? '';
|
||||
|
||||
|
||||
if (!empty($notifications['notifications'])) {
|
||||
$notificationTemplates = [
|
||||
'like' => 'notifications/likes_item.tpl',
|
||||
'dislike' => 'notifications/dislikes_item.tpl',
|
||||
'attend' => 'notifications/attend_item.tpl',
|
||||
'attendno' => 'notifications/attend_item.tpl',
|
||||
'attendmaybe' => 'notifications/attend_item.tpl',
|
||||
'friend' => 'notifications/friends_item.tpl',
|
||||
'comment' => 'notifications/comments_item.tpl',
|
||||
'post' => 'notifications/posts_item.tpl',
|
||||
'notification' => 'notifications/notification.tpl',
|
||||
];
|
||||
// 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 */
|
||||
foreach ($notifications['notifications'] as $notification) {
|
||||
$notification_templates = [
|
||||
'like' => 'notifications/likes_item.tpl',
|
||||
'dislike' => 'notifications/dislikes_item.tpl',
|
||||
'attend' => 'notifications/attend_item.tpl',
|
||||
'attendno' => 'notifications/attend_item.tpl',
|
||||
'attendmaybe' => 'notifications/attend_item.tpl',
|
||||
'friend' => 'notifications/friends_item.tpl',
|
||||
'comment' => 'notifications/comments_item.tpl',
|
||||
'post' => 'notifications/posts_item.tpl',
|
||||
'notification' => 'notifications/notification.tpl',
|
||||
];
|
||||
/** @var FormattedNotification $Notification */
|
||||
foreach ($notifications['notifications'] as $Notification) {
|
||||
$notificationArray = $Notification->toArray();
|
||||
|
||||
$notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notification->getLabel()]);
|
||||
$notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$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 = [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue