diff options
| author | 2023-12-15 23:04:29 +0100 | |
|---|---|---|
| committer | 2023-12-15 23:04:29 +0100 | |
| commit | 6bb45a87268157aab961a6a4a728d9a9bbe043b0 (patch) | |
| tree | d1c36638d5ee61e2e663d214d724a71f07a89354 /app/Models/Entry.php | |
| parent | a3ed8269132303eebc03d3e6df822f1f101fa95b (diff) | |
Add filter actions (auto mark read) at category and global levels (#5942)
* Add filter actions (auto mark read) at category level
fix https://github.com/FreshRSS/FreshRSS/issues/3497
* Add filter actions (auto mark read) at global level
fix https://github.com/FreshRSS/FreshRSS/issues/2788
* Fix feed category ID
* Minor comment
Diffstat (limited to 'app/Models/Entry.php')
| -rw-r--r-- | app/Models/Entry.php | 80 |
1 files changed, 19 insertions, 61 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 476c5a8cf..186b1f166 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -2,6 +2,8 @@ declare(strict_types=1); class FreshRSS_Entry extends Minz_Model { + use FreshRSS_AttributesTrait; + public const STATE_READ = 1; public const STATE_NOT_READ = 2; public const STATE_ALL = 3; @@ -26,8 +28,6 @@ class FreshRSS_Entry extends Minz_Model { private ?FreshRSS_Feed $feed; /** @var array<string> */ private array $tags = []; - /** @var array<string,mixed> */ - private array $attributes = []; /** * @param int|string $pubdate @@ -396,34 +396,6 @@ HTML; } } - /** - * @phpstan-return ($key is non-empty-string ? mixed : array<string,mixed>) - * @return array<string,mixed>|mixed|null - */ - public function attributes(string $key = '') { - if ($key === '') { - return $this->attributes; - } else { - return $this->attributes[$key] ?? null; - } - } - - /** @param string|array<mixed>|bool|int|null $value Value, not HTML-encoded */ - public function _attributes(string $key, $value): void { - if ($key == '') { - if (is_string($value)) { - $value = json_decode($value, true); - } - if (is_array($value)) { - $this->attributes = $value; - } - } elseif ($value === null) { - unset($this->attributes[$key]); - } else { - $this->attributes[$key] = $value; - } - } - public function hash(): string { if ($this->hash == '') { //Do not include $this->date because it may be automatically generated when lacking @@ -660,40 +632,26 @@ HTML; /** @param array<string,bool> $titlesAsRead */ public function applyFilterActions(array $titlesAsRead = []): void { - if ($this->feed != null) { - if (!$this->isRead()) { - if ($this->feed->attributes('read_upon_reception') || - ($this->feed->attributes('read_upon_reception') === null && FreshRSS_Context::$user_conf->mark_when['reception'])) { - $this->_isRead(true); - Minz_ExtensionManager::callHook('entry_auto_read', $this, 'upon_reception'); - } - if (!empty($titlesAsRead[$this->title()])) { - Minz_Log::debug('Mark title as read: ' . $this->title()); - $this->_isRead(true); - Minz_ExtensionManager::callHook('entry_auto_read', $this, 'same_title_in_feed'); - } + if ($this->feed === null) { + return; + } + if (!$this->isRead()) { + if ($this->feed->attributes('read_upon_reception') || + ($this->feed->attributes('read_upon_reception') === null && FreshRSS_Context::$user_conf->mark_when['reception'])) { + $this->_isRead(true); + Minz_ExtensionManager::callHook('entry_auto_read', $this, 'upon_reception'); } - foreach ($this->feed->filterActions() as $filterAction) { - if ($this->matches($filterAction->booleanSearch())) { - foreach ($filterAction->actions() as $action) { - switch ($action) { - case 'read': - if (!$this->isRead()) { - $this->_isRead(true); - Minz_ExtensionManager::callHook('entry_auto_read', $this, 'filter'); - } - break; - case 'star': - $this->_isFavorite(true); - break; - case 'label': - //TODO: Implement more actions - break; - } - } - } + if (!empty($titlesAsRead[$this->title()])) { + Minz_Log::debug('Mark title as read: ' . $this->title()); + $this->_isRead(true); + Minz_ExtensionManager::callHook('entry_auto_read', $this, 'same_title_in_feed'); } } + FreshRSS_Context::$user_conf->applyFilterActions($this); + if ($this->feed->category() !== null) { + $this->feed->category()->applyFilterActions($this); + } + $this->feed->applyFilterActions($this); } public function isDay(int $day, int $today): bool { |
