Move notification to the new paradigm

This commit is contained in:
Hypolite Petovan 2021-09-18 00:03:32 -04:00
parent bc0734e0f1
commit 7a2d5f6a8e
16 changed files with 175 additions and 420 deletions

View file

@ -78,7 +78,7 @@ class Notification extends BaseModule
if (DI::args()->get(1) === 'mark' && DI::args()->get(2) === 'all') {
try {
DI::dba()->update('notification', ['seen' => true], ['uid' => local_user()]);
DI::notification()->setAllSeenForUser(local_user());
$success = DI::notify()->setAllSeenForUser(local_user());
} catch (\Exception $e) {
DI::logger()->warning('set all seen failed.', ['exception' => $e]);
@ -118,7 +118,7 @@ class Notification extends BaseModule
DI::notify()->save($Notify);
} else {
if ($Notify->uriId) {
DI::dba()->update('notification', ['seen' => true], ['uid' => $Notify->uid, 'target-uri-id' => $Notify->uriId]);
DI::notification()->setAllSeenForUser($Notify->uid, ['target-uri-id' => $Notify->uriId]);
}
DI::notify()->setAllSeenForRelatedNotify($Notify);

View file

@ -95,25 +95,24 @@ class Notifications extends BaseNotifications
$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 FormattedNotification $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();
$notificationArray = $notification->toArray();
$notificationTemplate = Renderer::getMarkupTemplate($notification_templates[$notificationArray['label']]);
$notificationTemplate = Renderer::getMarkupTemplate($notificationTemplates[$notificationArray['label']]);
$notificationContent[] = Renderer::replaceMacros($notificationTemplate, [
'$notification' => $notificationArray