From ea503975d5967dd9605f8e8df8a77fc1e5bc2e3a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 16 May 2023 12:09:39 +0200 Subject: Fix again updateLastSeenUnchanged (#5404) * Fix again updateLastSeenUnchanged https://github.com/FreshRSS/FreshRSS/pull/5382 was not good enough to fix markAsReadUponGone and introduced a regression in `entry.lastSeen`. New approach. Follow-up of https://github.com/FreshRSS/FreshRSS/pull/5315 * Minor change of mind * Fix handling of lastSeen entry.lastSeen was not always correctly initialised, and sometimes overriden --- app/Models/Entry.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 3c95570a1..70b2fa5f0 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -21,6 +21,8 @@ class FreshRSS_Entry extends Minz_Model { private $link; /** @var int */ private $date; + /** @var int */ + private $lastSeen = 0; /** @var string In microseconds */ private $date_added = '0'; /** @var string */ @@ -58,7 +60,7 @@ class FreshRSS_Entry extends Minz_Model { $this->_guid($guid); } - /** @param array{'id'?:string,'id_feed'?:int,'guid'?:string,'title'?:string,'author'?:string,'content'?:string,'link'?:string,'date'?:int|string, + /** @param array{'id'?:string,'id_feed'?:int,'guid'?:string,'title'?:string,'author'?:string,'content'?:string,'link'?:string,'date'?:int|string,'lastSeen'?:int, * 'is_read'?:bool|int,'is_favorite'?:bool|int,'tags'?:string|array,'attributes'?:string,'thumbnail'?:string,'timestamp'?:string} $dao */ public static function fromArray(array $dao): FreshRSS_Entry { if (empty($dao['content'])) { @@ -93,6 +95,9 @@ class FreshRSS_Entry extends Minz_Model { if (!empty($dao['timestamp'])) { $entry->_date(strtotime($dao['timestamp']) ?: 0); } + if (isset($dao['lastSeen'])) { + $entry->_lastSeen($dao['lastSeen']); + } if (!empty($dao['attributes'])) { $entry->_attributes('', $dao['attributes']); } @@ -325,6 +330,10 @@ HTML; return @date (DATE_ATOM, $this->date); } + public function lastSeen(): int { + return $this->lastSeen; + } + /** * @phpstan-return ($raw is false ? string : ($microsecond is true ? string : int)) * @return int|string @@ -467,6 +476,11 @@ HTML; $value = intval($value); $this->date = $value > 1 ? $value : time(); } + + public function _lastSeen(int $value): void { + $this->lastSeen = $value > 0 ? $value : 0; + } + /** @param int|string $value */ public function _dateAdded($value, bool $microsecond = false): void { if ($microsecond) { @@ -774,7 +788,7 @@ HTML; } /** - * @return array{'id':string,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int, + * @return array{'id':string,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int,'lastSeen':int, * 'hash':string,'is_read':?bool,'is_favorite':?bool,'id_feed':int,'tags':string,'attributes':array} */ public function toArray(): array { @@ -786,6 +800,7 @@ HTML; 'content' => $this->content(false), 'link' => $this->link(), 'date' => $this->date(true), + 'lastSeen' => $this->lastSeen(), 'hash' => $this->hash(), 'is_read' => $this->isRead(), 'is_favorite' => $this->isFavorite(), -- cgit v1.2.3