From 65d28653ae1a1d2a7680ccfa694dbb7e2d4d750f Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 6 Apr 2016 23:43:27 +0200 Subject: try marking same items as read if they contain the same content --- db/itemmapper.php | 24 ++++++++++++++++++++++++ db/mysql/itemmapper.php | 17 +++++++++++++++++ 2 files changed, 41 insertions(+) (limited to 'db') diff --git a/db/itemmapper.php b/db/itemmapper.php index 895b0f7ae..a2ad70a67 100644 --- a/db/itemmapper.php +++ b/db/itemmapper.php @@ -379,5 +379,29 @@ class ItemMapper extends NewsMapper { } } + public function readItem($itemId, $isRead, $lastModified, $userId) { + $item = $this->find($itemId, $userId); + + // reading an item should set all of the same items as read, whereas + // marking an item as unread should only mark the selected instance + // as unread + if ($isRead) { + $sql = 'UPDATE `*PREFIX*news_items` + SET `status` = `status` & ? + AND `last_modified` = ? + WHERE `fingerprint` = ? + AND feed_id IN ( + SELECT `f`.`id` FROM `*PREFIX*news_feeds` `f` + WHERE `f`.`user_id` = ? + )'; + $params = [~StatusFlag::UNREAD, $lastModified, + $item->getFingerprint(), $userId]; + $this->execute($sql, $params); + } else { + $item->setLastModified($lastModified); + $item->setUnread(); + $this->update($item); + } + } } diff --git a/db/mysql/itemmapper.php b/db/mysql/itemmapper.php index 5fb28880b..720f03744 100644 --- a/db/mysql/itemmapper.php +++ b/db/mysql/itemmapper.php @@ -63,5 +63,22 @@ class ItemMapper extends \OCA\News\Db\ItemMapper { } + public function readItem($itemId, $isRead, $lastModified, $userId) { + if ($isRead) { + $sql = 'UPDATE `*PREFIX*news_items` `items` + JOIN `*PREFIX*news_feeds` `feeds` + ON `feeds`.`id` = `items`.`feed_id` + SET `items`.`status` = `items`.`status` & ? + AND `items`.`last_modified` = ? + WHERE `items`.`fingerprint` = ? + AND `feeds`.`user_id` = ?'; + $params = [~StatusFlag::UNREAD, $lastModified, + $item->getFingerprint(), $userId]; + $this->execute($sql, $params); + } else { + // no other behavior for mysql if should be marked unread + parent::readItem($itemId, $isRead, $lastModified, $userId); + } + } } -- cgit v1.2.3