Use new implementation for notification feed page
authorMarcel Werk <burntime@woltlab.com>
Sun, 4 Feb 2024 14:19:36 +0000 (15:19 +0100)
committerMarcel Werk <burntime@woltlab.com>
Sun, 4 Feb 2024 14:19:36 +0000 (15:19 +0100)
com.woltlab.wcf/templates/notificationList.tpl
wcfsetup/install/files/lib/page/NotificationFeedPage.class.php
wcfsetup/install/files/lib/page/NotificationRssFeedPage.class.php [new file with mode: 0644]

index e5e849ec070b97e23c8a49960b168080af9e5b6a..02660820d03a20c29ea66ab02559a0e9c8ad5351 100644 (file)
@@ -1,7 +1,7 @@
 {capture assign='contentTitleBadge'}<span class="badge jsNotificationsBadge">{#$__wcf->getUserNotificationHandler()->countAllNotifications()}</span>{/capture}
 
 {capture assign='headContent'}
-       <link rel="alternate" type="application/rss+xml" title="{lang}wcf.global.button.rss{/lang}" href="{link controller='NotificationFeed'}at={@$__wcf->getUser()->userID}-{@$__wcf->getUser()->accessToken}{/link}">
+       <link rel="alternate" type="application/rss+xml" title="{lang}wcf.global.button.rss{/lang}" href="{link controller='NotificationRssFeed'}at={@$__wcf->getUser()->userID}-{@$__wcf->getUser()->accessToken}{/link}">
 {/capture}
 
 {capture assign='contentInteractionPagination'}
@@ -15,7 +15,7 @@
 {/capture}
 
 {capture assign='contentInteractionDropdownItems'}
-       <li><a rel="alternate" href="{link controller='NotificationFeed'}at={@$__wcf->getUser()->userID}-{@$__wcf->getUser()->accessToken}{/link}">{lang}wcf.global.button.rss{/lang}</a></li>
+       <li><a rel="alternate" href="{link controller='NotificationRssFeed'}at={@$__wcf->getUser()->userID}-{@$__wcf->getUser()->accessToken}{/link}">{lang}wcf.global.button.rss{/lang}</a></li>
 {/capture}
 
 {include file='header'}
index 1a52b1ad1b26e64095e19c6366068f07a4bb553b..e4c25a79e0813cd4ca38eb54776e8c1a2cb1fbeb 100644 (file)
@@ -13,6 +13,7 @@ use wcf\system\WCF;
  * @copyright   2001-2019 WoltLab GmbH
  * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @since   3.0
+ * @deprecated 6.1 use `NotificationRssFeedPage` instead
  */
 class NotificationFeedPage extends AbstractFeedPage
 {
@@ -28,6 +29,8 @@ class NotificationFeedPage extends AbstractFeedPage
         }
 
         $this->title = WCF::getLanguage()->get('wcf.user.menu.community.notification');
+
+        $this->redirectToNewPage(NotificationRssFeedPage::class);
     }
 
     /**
diff --git a/wcfsetup/install/files/lib/page/NotificationRssFeedPage.class.php b/wcfsetup/install/files/lib/page/NotificationRssFeedPage.class.php
new file mode 100644 (file)
index 0000000..f2ff35b
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+
+namespace wcf\page;
+
+use wcf\system\exception\IllegalLinkException;
+use wcf\system\rssFeed\RssFeed;
+use wcf\system\rssFeed\RssFeedItem;
+use wcf\system\user\notification\event\AbstractUserNotificationEvent;
+use wcf\system\user\notification\UserNotificationHandler;
+use wcf\system\WCF;
+
+/**
+ * Shows a list of own user notifications in feed.
+ *
+ * @author      Joshua Ruesweg, Marcel Werk
+ * @copyright   2001-2024 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since       6.1
+ */
+class NotificationRssFeedPage extends AbstractRssFeedPage
+{
+    #[\Override]
+    public function readParameters()
+    {
+        parent::readParameters();
+
+        if (!WCF::getUser()->userID) {
+            throw new IllegalLinkException();
+        }
+    }
+
+    #[\Override]
+    protected function getRssFeed(): RssFeed
+    {
+        $feed = new RssFeed();
+        $channel = $this->getDefaultChannel();
+        $channel->title(WCF::getLanguage()->get('wcf.user.menu.community.notification'));
+        $feed->channel($channel);
+
+        $notifications = UserNotificationHandler::getInstance()->getNotifications(20);
+        if ($notifications['notifications'] !== []) {
+            $channel->lastBuildDateFromTimestamp($notifications['notifications'][0]['time']);
+        }
+
+        foreach ($notifications['notifications'] as $notification) {
+            $event = $notification['event'];
+            \assert($event instanceof AbstractUserNotificationEvent);
+
+            $item = new RssFeedItem();
+            $item
+                ->title($event->getTitle())
+                ->link($event->getLink())
+                ->description($event->getExcerpt())
+                ->pubDateFromTimestamp($event->getTime())
+                ->creator($event->getAuthor()->username)
+                ->guid($event->getLink())
+                ->contentEncoded($event->getFormattedMessage());
+            $channel->item($item);
+        }
+
+        return $feed;
+    }
+}