Skip to content

Commit

Permalink
feat(rss): Add server name to the RSS feed title
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Nov 9, 2023
1 parent 2857ef3 commit 3ca958f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
7 changes: 6 additions & 1 deletion lib/Controller/FeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCA\Activity\Data;
use OCA\Activity\GroupHelper;
use OCA\Activity\UserSettings;
use OCA\Theming\ThemingDefaults;
use OCP\Activity\IManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
Expand All @@ -48,7 +49,9 @@ public function __construct(
protected IURLGenerator $urlGenerator,
protected IManager $activityManager,
protected IFactory $l10nFactory,
protected IConfig $config) {
protected IConfig $config,
protected ThemingDefaults $themingDefaults,

Check failure on line 53 in lib/Controller/FeedController.php

View workflow job for this annotation

GitHub Actions / Nextcloud

UndefinedClass

lib/Controller/FeedController.php:53:3: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)
) {
parent::__construct($appName, $request);
}

Expand Down Expand Up @@ -85,11 +88,13 @@ public function show() {
];
}

$title = $this->themingDefaults->getTitle();

Check failure on line 91 in lib/Controller/FeedController.php

View workflow job for this annotation

GitHub Actions / Nextcloud

UndefinedClass

lib/Controller/FeedController.php:91:12: UndefinedClass: Class, interface or enum named OCA\Theming\ThemingDefaults does not exist (see https://psalm.dev/019)
$response = new TemplateResponse('activity', 'rss', [
'rssLang' => $this->l->getLanguageCode(),
'rssLink' => $this->urlGenerator->linkToRouteAbsolute('activity.Feed.show'),
'rssPubDate' => date('r'),
'description' => $description,
'title' => $title !== '' ? $this->l->t('Activity feed for %1$s', [$title]) : $this->l->t('Activity feed'),
'activities' => $activities,
], '');

Expand Down
2 changes: 1 addition & 1 deletion templates/rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title><?php p($l->t('Activity feed')); ?></title>
<title><?php p($_['title']); ?></title>
<language><?php p($_['rssLang']); ?></language>
<link><?php p($_['rssLink']); ?></link>
<description><?php p($_['description']); ?></description>
Expand Down
8 changes: 7 additions & 1 deletion tests/Controller/FeedControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCA\Activity\GroupHelper;
use OCA\Activity\Tests\TestCase;
use OCA\Activity\UserSettings;
use OCA\Theming\ThemingDefaults;
use OCP\Activity\IManager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
Expand Down Expand Up @@ -64,6 +65,9 @@ class FeedControllerTest extends TestCase {
/** @var \OCP\IL10N */
protected $l10n;

/** @var ThemingDefaults|MockObject */
protected $themingDefault;

/** @var FeedController */
protected $controller;

Expand All @@ -78,6 +82,7 @@ protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->session = $this->createMock(IUserSession::class);
$this->manager = $this->createMock(IManager::class);
$this->themingDefault = $this->createMock(ThemingDefaults::class);

/** @var $urlGenerator IURLGenerator|MockObject */
$urlGenerator = $this->createMock(IURLGenerator::class);
Expand All @@ -91,7 +96,8 @@ protected function setUp(): void {
$urlGenerator,
$this->manager,
\OC::$server->getL10NFactory(),
$this->config
$this->config,
$this->themingDefault,
);
}

Expand Down
10 changes: 6 additions & 4 deletions tests/Template/RssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
class RssTest extends TestCase {
public function dataEmpty(): array {
return [
['de', 'http://localhost', 'description', 'Fri, 28 Aug 2015 11:47:14 +0000'],
['en', 'http://nextcloud.org', 'Desc', 'Fri, 28 Aug 2015 11:47:15 +0000'],
['de', 'http://localhost', 'title', 'description', 'Fri, 28 Aug 2015 11:47:14 +0000'],
['en', 'http://nextcloud.org', 'The title', 'Desc', 'Fri, 28 Aug 2015 11:47:15 +0000'],
];
}

Expand All @@ -43,20 +43,21 @@ public function dataEmpty(): array {
* @param string $description
* @param string $timeDate
*/
public function testEmpty(string $language, string $link, string $description, string $timeDate): void {
public function testEmpty(string $language, string $link, string $title, string $description, string $timeDate): void {
$template = new TemplateResponse('activity', 'rss', [
'rssLang' => $language,
'rssLink' => $link,
'rssPubDate' => $timeDate,
'description' => $description,
'title' => $title,
'activities' => [],
], '');

$this->assertSame(
'<?xml version="1.0" encoding="UTF-8"?>'
. "\n" . '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'
. "\n" . ' <channel>'
. "\n" . ' <title>Activity feed</title>'
. "\n" . ' <title>' . $title . '</title>'
. "\n" . ' <language>' . $language . '</language>'
. "\n" . ' <link>' . $link . '</link>'
. "\n" . ' <description>' . $description . '</description>'
Expand Down Expand Up @@ -118,6 +119,7 @@ public function testContent(array $activities, string $expected): void {
'rssLink' => 'http://nextcloud.org',
'rssPubDate' => 'Fri, 28 Aug 2015 11:47:15 +0000',
'description' => 'Desc',
'title' => 'Activity feed',
'activities' => $activities,
], '');
$rendered = $template->render();
Expand Down

0 comments on commit 3ca958f

Please sign in to comment.