Browse Source

Fix updated entry filters (#6334)

fix https://github.com/FreshRSS/FreshRSS/issues/6331
Alexandre Alapetite 1 year ago
parent
commit
5ca0b893b9
3 changed files with 28 additions and 2 deletions
  1. 7 0
      app/Controllers/feedController.php
  2. 13 0
      app/Models/Entry.php
  3. 8 2
      app/Models/FilterActionsTrait.php

+ 7 - 0
app/Controllers/feedController.php

@@ -573,6 +573,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 						$existingHash = $existingHashForGuids[$entry->guid()];
 						if (strcasecmp($existingHash, $entry->hash()) !== 0) {
 							//This entry already exists but has been updated
+							$entry->_isUpdated(true);
 							//Minz_Log::debug('Entry with GUID `' . $entry->guid() . '` updated in feed ' . $feed->url(false) .
 								//', old hash ' . $existingHash . ', new hash ' . $entry->hash());
 							$entry->_isFavorite(null);	// Do not change favourite state
@@ -587,6 +588,11 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 								continue;
 							}
 
+							$entry->applyFilterActions($titlesAsRead);
+							if ($readWhenSameTitleInFeed > 0) {
+								$titlesAsRead[$entry->title()] = true;
+							}
+
 							if (!$entry->isRead()) {
 								$needFeedCacheRefresh = true;	//Maybe
 								$nbMarkedUnread++;
@@ -601,6 +607,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 							$entryDAO->updateEntry($entry->toArray());
 						}
 					} else {
+						$entry->_isUpdated(false);
 						$id = uTimeString();
 						$entry->_id($id);
 

+ 13 - 0
app/Models/Entry.php

@@ -24,6 +24,7 @@ class FreshRSS_Entry extends Minz_Model {
 	private string $hash = '';
 	private ?bool $is_read;
 	private ?bool $is_favorite;
+	private bool $is_updated = false;
 	private int $feedId;
 	private ?FreshRSS_Feed $feed;
 	/** @var array<string> */
@@ -394,6 +395,18 @@ HTML;
 		return $this->is_favorite;
 	}
 
+	/**
+	 * Returns whether the entry has been modified since it was inserted in database.
+	 * @returns bool `true` if the entry already existed (and has been modified), `false` if the entry is new (or unmodified).
+	 */
+	public function isUpdated(): ?bool {
+		return $this->is_updated;
+	}
+
+	public function _isUpdated(bool $value): void {
+		$this->is_updated = $value;
+	}
+
 	public function feed(): ?FreshRSS_Feed {
 		if ($this->feed === null) {
 			$feedDAO = FreshRSS_Factory::createFeedDao();

+ 8 - 2
app/Models/FilterActionsTrait.php

@@ -135,10 +135,16 @@ trait FreshRSS_FilterActionsTrait {
 							}
 							break;
 						case 'star':
-							$entry->_isFavorite(true);
+							if (!$entry->isUpdated()) {
+								// Do not apply to updated articles, to avoid overruling a user manual action
+								$entry->_isFavorite(true);
+							}
 							break;
 						case 'label':
-							$applyLabel = true;
+							if (!$entry->isUpdated()) {
+								// Do not apply to updated articles, to avoid overruling a user manual action
+								$applyLabel = true;
+							}
 							break;
 					}
 				}