Переглянути джерело

fix(storage): respect category hide_globally when marking all as read

The "Mark all as read" button on the Unread page calls
MarkGloballyVisibleFeedsAsRead, which only filtered on feeds.hide_globally
and ignored the feed's category. Entries belonging to a category marked as
hidden from the global unread list were therefore marked as read even though
they are not shown on that page.

Join the categories table and exclude both feeds and categories that are
hidden globally, matching the visibility rules already used by the unread
query builder, the pagination builder and the navigation unread counter.

Fixes #4444
Saleh 2 місяців тому
батько
коміт
070bc9ef3d
1 змінених файлів з 7 додано та 3 видалено
  1. 7 3
      internal/storage/entry.go

+ 7 - 3
internal/storage/entry.go

@@ -543,7 +543,9 @@ func (s *Storage) MarkAllAsReadBeforeDate(userID int64, before time.Time) error
 	return nil
 }
 
-// MarkGloballyVisibleFeedsAsRead updates all user entries to the read status.
+// MarkGloballyVisibleFeedsAsRead marks as read the unread entries that are
+// visible in the global unread view, i.e. those belonging to a feed and a
+// category that are both not hidden globally.
 func (s *Storage) MarkGloballyVisibleFeedsAsRead(userID int64) error {
 	query := `
 		UPDATE
@@ -553,13 +555,15 @@ func (s *Storage) MarkGloballyVisibleFeedsAsRead(userID int64) error {
 			changed_at=now()
 		FROM
 			feeds
+			JOIN categories ON (categories.id = feeds.category_id)
 		WHERE
 			entries.feed_id = feeds.id
 			AND entries.user_id=$2
 			AND entries.status=$3
-			AND feeds.hide_globally=$4
+			AND feeds.hide_globally IS FALSE
+			AND categories.hide_globally IS FALSE
 	`
-	result, err := s.db.Exec(query, model.EntryStatusRead, userID, model.EntryStatusUnread, false)
+	result, err := s.db.Exec(query, model.EntryStatusRead, userID, model.EntryStatusUnread)
 	if err != nil {
 		return fmt.Errorf(`store: unable to mark globally visible feeds as read: %v`, err)
 	}