Skip to content

Commit

Permalink
A few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkarex committed May 5, 2023
1 parent 4471d92 commit fef7939
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
30 changes: 9 additions & 21 deletions app/Controllers/feedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force
continue; //When PubSubHubbub is used, do not pull refresh so often
}

$mtime = 0;
if ($feed->mute()) {
continue; //Feed refresh is disabled
}
Expand All @@ -383,7 +384,7 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force
($feed->lastUpdate() + 10 >= time() - (
$ttl === FreshRSS_Feed::TTL_DEFAULT ? FreshRSS_Context::$user_conf->ttl_default : $ttl))) {
//Too early to refresh from source, but check whether the feed was updated by another user
$mtime = (int)$feed->cacheModifiedTime();
$mtime = $feed->cacheModifiedTime() ?: 0;
if ($feed->lastUpdate() + 10 >= $mtime) {
continue; //Nothing newer from other users
}
Expand Down Expand Up @@ -439,6 +440,7 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force
$readWhenSameTitleInFeed = FreshRSS_Context::$user_conf->mark_when['same_title_in_feed'];
}
if ($readWhenSameTitleInFeed > 0) {
/** @var array<string,bool> $titlesAsRead*/
$titlesAsRead = array_flip($feedDAO->listTitles($feed->id(), (int)$readWhenSameTitleInFeed));
}

Expand All @@ -447,8 +449,7 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force
) : FreshRSS_Context::$user_conf->mark_updated_article_unread;

// For this feed, check existing GUIDs already in database.
/** @var array<string,string> $existingHashForGuids */
$existingHashForGuids = $entryDAO->listHashForFeedGuids($feed->id(), $newGuids);
$existingHashForGuids = $entryDAO->listHashForFeedGuids($feed->id(), $newGuids) ?: [];
/** @var array<string,bool> $newGuids */
$newGuids = [];

Expand All @@ -469,9 +470,8 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force
$entry->_isRead($mark_updated_article_unread ? false : null); //Change is_read according to policy.
$entry->_isFavorite(null); // Do not change favourite state

/** @var FreshRSS_Entry|null $entry*/
$entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
if ($entry === null) {
if (!($entry instanceof FreshRSS_Entry)) {
// An extension has returned a null value, there is nothing to insert.
continue;
}
Expand All @@ -492,15 +492,13 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force
} else {
$id = uTimeString();
$entry->_id($id);
/** @var array<string,int> $titlesAsRead*/
$entry->applyFilterActions($titlesAsRead);
if ($readWhenSameTitleInFeed > 0) {
$titlesAsRead[$entry->title()] = true;
}

/** @var FreshRSS_Entry|null $entry */
$entry = Minz_ExtensionManager::callHook('entry_before_insert', $entry);
if ($entry === null) {
if (!($entry instanceof FreshRSS_Entry)) {
// An extension has returned a null value, there is nothing to insert.
continue;
}
Expand Down Expand Up @@ -541,10 +539,10 @@ public static function actualizeFeed(int $feed_id, string $feed_url, bool $force
}

$feedDAO->updateLastUpdate($feed->id(), false, $mtime);
$needFeedCacheRefresh |= ($feed->keepMaxUnread() !== false);
$needFeedCacheRefresh |= ($feed->keepMaxUnread() != false);
if (!$simplePiePush) {
// Do not call for WebSub events, as we do not know the list of articles still on the upstream feed.
$needFeedCacheRefresh |= ($feed->markAsReadUponGone() !== false);
$needFeedCacheRefresh |= ($feed->markAsReadUponGone() != false);
}
if ($needFeedCacheRefresh) {
$feedDAO->updateCachedValues($feed->id());
Expand Down Expand Up @@ -783,10 +781,6 @@ public static function deleteFeed(int $feed_id): bool {
*
* Parameters are:
* - id (default: false)
* - r (default: false)
* r permits to redirect to a given page at the end of this action.
*
* @todo handle "r" redirection in Minz_Request::forward()?
*/
public function deleteAction(): void {
$from = Minz_Request::paramString('from');
Expand All @@ -805,13 +799,7 @@ public function deleteAction(): void {
}
break;
default:
$redirect_url = Minz_Request::paramString('r', true);
if ($redirect_url === '') {
$redirect_url = ['c' => 'subscription', 'a' => 'index'];
}
if (!is_array($redirect_url)) {
$redirect_url = ['c' => 'subscription', 'a' => 'index'];
}
$redirect_url = ['c' => 'subscription', 'a' => 'index'];
if (!Minz_Request::isPost()) {
Minz_Request::forward($redirect_url, true);
}
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,14 @@ public function matches(FreshRSS_BooleanSearch $booleanSearch): bool {
return (bool)$ok;
}

/** @param array<string,int> $titlesAsRead */
/** @param array<string,bool> $titlesAsRead */
public function applyFilterActions(array $titlesAsRead = []): void {
if ($this->feed != null) {
if ($this->feed->attributes('read_upon_reception') ||
($this->feed->attributes('read_upon_reception') === null && FreshRSS_Context::$user_conf->mark_when['reception'])) {
$this->_isRead(true);
}
if (isset($titlesAsRead[$this->title()])) {
if (!empty($titlesAsRead[$this->title()])) {
Minz_Log::debug('Mark title as read: ' . $this->title());
$this->_isRead(true);
}
Expand Down

0 comments on commit fef7939

Please sign in to comment.