Skip to content

Commit

Permalink
If items of feed do not provide an author fallback to feed author (#1803
Browse files Browse the repository at this point in the history
)

Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
  • Loading branch information
Grotax committed May 31, 2022
1 parent dbb6419 commit 1c91928
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
# Unreleased
## [18.x.x]
### Changed
- If items of feed do not provide an author fallback to feed author (#1803)

### Fixed

Expand Down
16 changes: 12 additions & 4 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function fetch(
$items = [];
$RTL = $this->determineRtl($parsedFeed);
$feedName = $parsedFeed->getTitle();
$feedAuthor = $parsedFeed->getAuthor();
$this->logger->debug(
'Feed {url} was modified since last fetch. #{count} items',
[
Expand All @@ -155,7 +156,7 @@ public function fetch(
}
}

$builtItem = $this->buildItem($item, $body, $currRTL);
$builtItem = $this->buildItem($item, $body, $currRTL, $feedAuthor);
$this->logger->debug(
'Added item {title} for feed {feed} lastmodified: {datetime}',
[
Expand Down Expand Up @@ -226,11 +227,16 @@ protected function determineRtl(FeedInterface $parsedFeed): bool
* @param ItemInterface $parsedItem The item to use
* @param string|null $body Text of the item, if not provided use description from $parsedItem
* @param bool $RTL True if the feed is RTL (Right-to-left)
* @param string|null $feedAuthor Author of the feed as fallback when the item has no Author
*
* @return Item
*/
protected function buildItem(ItemInterface $parsedItem, ?string $body = null, bool $RTL = false): Item
{
protected function buildItem(
ItemInterface $parsedItem,
?string $body = null,
bool $RTL = false,
$feedAuthor = null
): Item {
$item = new Item();
$item->setUnread(true);
$itemLink = $parsedItem->getLink();
Expand Down Expand Up @@ -272,7 +278,9 @@ protected function buildItem(ItemInterface $parsedItem, ?string $body = null, bo
if ($itemTitle !== null) {
$item->setTitle($this->decodeTwice($itemTitle));
}
$author = $parsedItem->getAuthor();

$author = $parsedItem->getAuthor() ?? $feedAuthor;

if ($author !== null && $author->getName() !== null) {
$item->setAuthor($this->decodeTwice($author->getName()));
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/command/helpers/settings.bash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
user=admin
NC_FEED="https://nextcloud.com/blog/static-feed/"
HEISE_FEED="https://www.heise.de/rss/heise-atom.xml"
NO_GUID_FEED="https://raw.githubusercontent.com/nextcloud/news/master/tests/integration/feeds/no_guid_feed.xml"
NO_GUID_FEED="https://raw.githubusercontent.com/nextcloud/news/master/tests/command/feeds/no_guid_feed.xml"
14 changes: 14 additions & 0 deletions tests/command/items.bats
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,17 @@ teardown() {
return $ret_status
fi
}

@test "[$TESTSUITE] Test author fallback" {
./occ news:feed:add "$user" $HEISE_FEED --title "Something-${BATS_SUITE_TEST_NUMBER}"
ID=$(./occ news:feed:list 'admin' | grep 'heise\.de' -1 | head -1 | grep -oE '[0-9]*')

run ./occ news:item:list-feed "$user" "$ID" --limit 200
[ "$status" -eq 0 ]

if ! echo "$output" | grep '"author": "heise online",'; then
ret_status=$?
echo "Author fallback did not work"
return $ret_status
fi
}

0 comments on commit 1c91928

Please sign in to comment.