fix "mark all as read" in tag views marking the wrong entries (#2374)

This commit is contained in:
Athou
2026-11-09 06:08:40 +01:00
parent f6e30a77da
commit eb8626f0e1
9 changed files with 60 additions and 12 deletions

View File

@@ -126,8 +126,13 @@ export const markAllEntries = createAppAsyncThunk(
}, },
thunkApi thunkApi
) => { ) => {
const endpoint = arg.sourceType === "category" ? client.category.markEntries : client.feed.markEntries if (arg.sourceType === "tag") {
await endpoint(arg.req) await client.category.markEntries({ ...arg.req, id: Constants.categories.all.id, tag: arg.req.id })
} else if (arg.sourceType === "category") {
await client.category.markEntries(arg.req)
} else {
await client.feed.markEntries(arg.req)
}
thunkApi.dispatch(reloadEntries()) thunkApi.dispatch(reloadEntries())
thunkApi.dispatch(reloadTree()) thunkApi.dispatch(reloadTree())
} }

View File

@@ -147,6 +147,7 @@ export interface MarkRequest {
insertedBefore?: number insertedBefore?: number
keywords?: string keywords?: string
excludedSubscriptions?: number[] excludedSubscriptions?: number[]
tag?: string
} }
export interface MetricCounter { export interface MetricCounter {

View File

@@ -116,10 +116,11 @@ public class FeedEntryService {
List<FeedSubscription> subscriptions, List<FeedSubscription> subscriptions,
Instant olderThan, Instant olderThan,
Instant insertedBefore, Instant insertedBefore,
List<FeedEntryKeyword> keywords) { List<FeedEntryKeyword> keywords,
String tag) {
List<FeedEntryStatus> statuses = List<FeedEntryStatus> statuses =
feedEntryStatusDAO.findBySubscriptions( feedEntryStatusDAO.findBySubscriptions(
user, subscriptions, true, keywords, null, -1, -1, null, false, null, null, null); user, subscriptions, true, keywords, null, -1, -1, null, false, tag, null, null);
markList(statuses, olderThan, insertedBefore); markList(statuses, olderThan, insertedBefore);
} }

View File

@@ -37,4 +37,8 @@ public class MarkRequest implements Serializable {
@Schema(description = "if marking a category or 'all', exclude those subscriptions from the marking") @Schema(description = "if marking a category or 'all', exclude those subscriptions from the marking")
private List<Long> excludedSubscriptions; private List<Long> excludedSubscriptions;
@Schema(description = "if marking a category or 'all', only mark entries tagged with this tag")
@Size(max = 40)
private String tag;
} }

View File

@@ -299,7 +299,8 @@ public class CategoryREST {
if (ALL.equals(req.getId())) { if (ALL.equals(req.getId())) {
List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user); List<FeedSubscription> subs = feedSubscriptionDAO.findAll(user);
removeExcludedSubscriptions(subs, req.getExcludedSubscriptions()); removeExcludedSubscriptions(subs, req.getExcludedSubscriptions());
feedEntryService.markSubscriptionEntries(user, subs, olderThan, insertedBefore, entryKeywords); feedEntryService.markSubscriptionEntries(
user, subs, olderThan, insertedBefore, entryKeywords, req.getTag());
} else if (STARRED.equals(req.getId())) { } else if (STARRED.equals(req.getId())) {
feedEntryService.markStarredEntries(user, olderThan, insertedBefore); feedEntryService.markStarredEntries(user, olderThan, insertedBefore);
} else { } else {
@@ -307,7 +308,8 @@ public class CategoryREST {
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(user, parent); List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(user, parent);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(user, categories); List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(user, categories);
removeExcludedSubscriptions(subs, req.getExcludedSubscriptions()); removeExcludedSubscriptions(subs, req.getExcludedSubscriptions());
feedEntryService.markSubscriptionEntries(user, subs, olderThan, insertedBefore, entryKeywords); feedEntryService.markSubscriptionEntries(
user, subs, olderThan, insertedBefore, entryKeywords, req.getTag());
} }
return Response.ok().build(); return Response.ok().build();
} }

View File

@@ -334,7 +334,7 @@ public class FeedREST {
FeedSubscription subscription = feedSubscriptionDAO.findById(user, Long.valueOf(req.getId())); FeedSubscription subscription = feedSubscriptionDAO.findById(user, Long.valueOf(req.getId()));
if (subscription != null) { if (subscription != null) {
feedEntryService.markSubscriptionEntries( feedEntryService.markSubscriptionEntries(
user, Collections.singletonList(subscription), olderThan, insertedBefore, entryKeywords); user, Collections.singletonList(subscription), olderThan, insertedBefore, entryKeywords, null);
} }
return Response.ok().build(); return Response.ok().build();
} }

View File

@@ -369,12 +369,12 @@ public class FeverREST {
} else if ("feed".equals(source)) { } else if ("feed".equals(source)) {
FeedSubscription subscription = feedSubscriptionDAO.findById(user, id); FeedSubscription subscription = feedSubscriptionDAO.findById(user, id);
feedEntryService.markSubscriptionEntries( feedEntryService.markSubscriptionEntries(
user, Collections.singletonList(subscription), null, insertedBefore, null); user, Collections.singletonList(subscription), null, insertedBefore, null, null);
} else if ("group".equals(source)) { } else if ("group".equals(source)) {
FeedCategory parent = feedCategoryDAO.findById(user, id); FeedCategory parent = feedCategoryDAO.findById(user, id);
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(user, parent); List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(user, parent);
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user, categories); List<FeedSubscription> subscriptions = feedSubscriptionDAO.findByCategories(user, categories);
feedEntryService.markSubscriptionEntries(user, subscriptions, null, insertedBefore, null); feedEntryService.markSubscriptionEntries(user, subscriptions, null, insertedBefore, null, null);
} }
} }
} }

View File

@@ -421,7 +421,7 @@ public class GoogleReaderREST {
Long subId = parsed.feedSubscriptionId(); Long subId = parsed.feedSubscriptionId();
FeedSubscription sub = subId == null ? null : feedSubscriptionDAO.findById(user, subId); FeedSubscription sub = subId == null ? null : feedSubscriptionDAO.findById(user, subId);
if (sub != null) { if (sub != null) {
feedEntryService.markSubscriptionEntries(user, List.of(sub), olderThan, null, null); feedEntryService.markSubscriptionEntries(user, List.of(sub), olderThan, null, null, null);
} }
} }
case LABEL -> { case LABEL -> {
@@ -429,12 +429,12 @@ public class GoogleReaderREST {
if (category != null) { if (category != null) {
List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(user, category); List<FeedCategory> categories = feedCategoryDAO.findAllChildrenCategories(user, category);
List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(user, categories); List<FeedSubscription> subs = feedSubscriptionDAO.findByCategories(user, categories);
feedEntryService.markSubscriptionEntries(user, subs, olderThan, null, null); feedEntryService.markSubscriptionEntries(user, subs, olderThan, null, null, null);
} }
} }
default -> default ->
feedEntryService.markSubscriptionEntries( feedEntryService.markSubscriptionEntries(
user, feedSubscriptionDAO.findAll(user), olderThan, null, null); user, feedSubscriptionDAO.findAll(user), olderThan, null, null, null);
} }
return Response.ok("OK").build(); return Response.ok("OK").build();

View File

@@ -28,10 +28,14 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import java.io.StringReader; import java.io.StringReader;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@QuarkusTest @QuarkusTest
class CategoryIT extends BaseIT { class CategoryIT extends BaseIT {
@@ -268,6 +272,37 @@ class CategoryIT extends BaseIT {
.statusCode(200); .statusCode(200);
Assertions.assertTrue(getCategoryEntries(categoryId).getEntries().stream().allMatch(Entry::isRead)); Assertions.assertTrue(getCategoryEntries(categoryId).getEntries().stream().allMatch(Entry::isRead));
} }
@ParameterizedTest
@ValueSource(strings = {"my-tag", "1"})
void tagged(String tag) {
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
List<Entry> entries = getFeedEntries(subscriptionId).getEntries();
Entry taggedEntry = entries.getFirst();
Entry untaggedEntry = entries.getLast();
TagRequest tagRequest = new TagRequest();
tagRequest.setEntryId(Long.valueOf(taggedEntry.getId()));
tagRequest.setTags(List.of(tag));
RestAssured.given().body(tagRequest).contentType(ContentType.JSON).post("rest/entry/tag");
MarkRequest request = new MarkRequest();
request.setId(CategoryREST.ALL);
request.setTag(tag);
request.setRead(true);
RestAssured.given()
.body(request)
.contentType(ContentType.JSON)
.post("rest/category/mark")
.then()
.statusCode(200);
Map<String, Boolean> readById =
getCategoryEntries(CategoryREST.ALL).getEntries().stream()
.collect(Collectors.toMap(Entry::getId, Entry::isRead));
Assertions.assertTrue(readById.get(taggedEntry.getId()));
Assertions.assertFalse(readById.get(untaggedEntry.getId()));
}
} }
@Nested @Nested