Просмотр исходного кода

fix(fever): honor the before timestamp when marking all items as read

Marking group 0 as read ignored the before parameter and marked every
unread entry as read, including entries that arrived after the
client's last sync.

Only entries published before the given timestamp are now marked as
read. Requests without a before timestamp keep marking all entries as
read.
Frédéric Guillot 22 часов назад
Родитель
Сommit
d57da7c752
1 измененных файлов с 11 добавлено и 3 удалено
  1. 11 3
      internal/fever/handler.go

+ 11 - 3
internal/fever/handler.go

@@ -525,14 +525,22 @@ func (h *feverHandler) handleWriteGroups(w http.ResponseWriter, r *http.Request)
 	}
 	}
 
 
 	var err error
 	var err error
+	beforeTimestamp := request.FormInt64Value(r, "before")
+	before := time.Unix(beforeTimestamp, 0)
 
 
-	if groupID == 0 {
+	switch {
+	case groupID == 0 && beforeTimestamp <= 0:
 		err = h.store.MarkAllAsRead(userID)
 		err = h.store.MarkAllAsRead(userID)
 		slog.Debug("[Fever] Mark all items as read",
 		slog.Debug("[Fever] Mark all items as read",
 			slog.Int64("user_id", userID),
 			slog.Int64("user_id", userID),
 		)
 		)
-	} else {
-		before := time.Unix(request.FormInt64Value(r, "before"), 0)
+	case groupID == 0:
+		err = h.store.MarkAllAsReadBeforeDate(userID, before)
+		slog.Debug("[Fever] Mark all items as read before a given date",
+			slog.Int64("user_id", userID),
+			slog.Time("before_ts", before),
+		)
+	default:
 		err = h.store.MarkCategoryAsRead(userID, groupID, before)
 		err = h.store.MarkCategoryAsRead(userID, groupID, before)
 		slog.Debug("[Fever] Mark group as read before a given date",
 		slog.Debug("[Fever] Mark group as read before a given date",
 			slog.Int64("user_id", userID),
 			slog.Int64("user_id", userID),