mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
add a "insertedBefore" field to mark as read requests to make sure the user does not mark entries that were fetched but never seen before (fixes a regression from #1007)
This commit is contained in:
@@ -113,6 +113,7 @@ export interface MarkRequest {
|
|||||||
id: string
|
id: string
|
||||||
read: boolean
|
read: boolean
|
||||||
olderThan?: number
|
olderThan?: number
|
||||||
|
insertedBefore?: number
|
||||||
keywords?: string
|
keywords?: string
|
||||||
excludedSubscriptions?: number[]
|
excludedSubscriptions?: number[]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,7 +279,8 @@ export function FeedEntries() {
|
|||||||
req: {
|
req: {
|
||||||
id: source.id,
|
id: source.id,
|
||||||
read: true,
|
read: true,
|
||||||
olderThan: entriesTimestamp,
|
olderThan: Date.now(),
|
||||||
|
insertedBefore: entriesTimestamp,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ export function MarkAllAsReadButton(props: { iconSize: number }) {
|
|||||||
req: {
|
req: {
|
||||||
id: source.id,
|
id: source.id,
|
||||||
read: true,
|
read: true,
|
||||||
olderThan: entriesTimestamp,
|
olderThan: Date.now(),
|
||||||
|
insertedBefore: entriesTimestamp,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@@ -78,7 +79,8 @@ export function MarkAllAsReadButton(props: { iconSize: number }) {
|
|||||||
req: {
|
req: {
|
||||||
id: source.id,
|
id: source.id,
|
||||||
read: true,
|
read: true,
|
||||||
olderThan: entriesTimestamp - threshold * 24 * 60 * 60 * 1000,
|
olderThan: Date.now() - threshold * 24 * 60 * 60 * 1000,
|
||||||
|
insertedBefore: entriesTimestamp,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.commafeed.backend.service;
|
package com.commafeed.backend.service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -108,30 +107,30 @@ public class FeedEntryService {
|
|||||||
feedEntryStatusDAO.saveOrUpdate(status);
|
feedEntryStatusDAO.saveOrUpdate(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markSubscriptionEntries(User user, List<FeedSubscription> subscriptions, Date olderThan, List<FeedEntryKeyword> keywords) {
|
public void markSubscriptionEntries(User user, List<FeedSubscription> subscriptions, Date olderThan, Date insertedBefore,
|
||||||
|
List<FeedEntryKeyword> keywords) {
|
||||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, true, keywords, null, -1, -1, null,
|
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findBySubscriptions(user, subscriptions, true, keywords, null, -1, -1, null,
|
||||||
false, false, null, null, null);
|
false, false, null, null, null);
|
||||||
markList(statuses, olderThan);
|
markList(statuses, olderThan, insertedBefore);
|
||||||
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
|
cache.invalidateUnreadCount(subscriptions.toArray(new FeedSubscription[0]));
|
||||||
cache.invalidateUserRootCategory(user);
|
cache.invalidateUserRootCategory(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markStarredEntries(User user, Date olderThan) {
|
public void markStarredEntries(User user, Date olderThan, Date insertedBefore) {
|
||||||
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findStarred(user, null, -1, -1, null, false);
|
List<FeedEntryStatus> statuses = feedEntryStatusDAO.findStarred(user, null, -1, -1, null, false);
|
||||||
markList(statuses, olderThan);
|
markList(statuses, olderThan, insertedBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markList(List<FeedEntryStatus> statuses, Date olderThan) {
|
private void markList(List<FeedEntryStatus> statuses, Date olderThan, Date insertedBefore) {
|
||||||
List<FeedEntryStatus> list = new ArrayList<>();
|
List<FeedEntryStatus> statusesToMark = statuses.stream().filter(s -> {
|
||||||
for (FeedEntryStatus status : statuses) {
|
Date entryDate = s.getEntry().getUpdated();
|
||||||
if (!status.isRead()) {
|
return olderThan == null || entryDate == null || entryDate.before(olderThan);
|
||||||
Date entryDate = status.getEntry().getUpdated();
|
}).filter(s -> {
|
||||||
if (olderThan == null || entryDate == null || olderThan.after(entryDate)) {
|
Date insertedDate = s.getEntry().getInserted();
|
||||||
status.setRead(true);
|
return insertedBefore == null || insertedDate == null || insertedDate.before(insertedBefore);
|
||||||
list.add(status);
|
}).toList();
|
||||||
}
|
|
||||||
}
|
statusesToMark.forEach(s -> s.setRead(true));
|
||||||
}
|
feedEntryStatusDAO.saveOrUpdate(statusesToMark);
|
||||||
feedEntryStatusDAO.saveOrUpdate(list);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,14 @@ public class MarkRequest implements Serializable {
|
|||||||
@Schema(description = "mark as read or unread", requiredMode = RequiredMode.REQUIRED)
|
@Schema(description = "mark as read or unread", requiredMode = RequiredMode.REQUIRED)
|
||||||
private boolean read;
|
private boolean read;
|
||||||
|
|
||||||
@Schema(
|
@Schema(description = "mark only entries older than this", requiredMode = RequiredMode.NOT_REQUIRED)
|
||||||
description = "only entries older than this, pass the timestamp you got from the entry list to prevent marking an entry that was not retrieved",
|
|
||||||
requiredMode = RequiredMode.NOT_REQUIRED)
|
|
||||||
private Long olderThan;
|
private Long olderThan;
|
||||||
|
|
||||||
|
@Schema(
|
||||||
|
description = "pass the timestamp you got from the entry list to avoid marking entries that may have been fetched in the mean time and never displayed",
|
||||||
|
requiredMode = RequiredMode.NOT_REQUIRED)
|
||||||
|
private Long insertedBefore;
|
||||||
|
|
||||||
@Schema(
|
@Schema(
|
||||||
description = "only mark read if a feed has these keywords in the title or rss content",
|
description = "only mark read if a feed has these keywords in the title or rss content",
|
||||||
requiredMode = RequiredMode.NOT_REQUIRED)
|
requiredMode = RequiredMode.NOT_REQUIRED)
|
||||||
|
|||||||
@@ -243,21 +243,22 @@ public class CategoryREST {
|
|||||||
Preconditions.checkNotNull(req.getId());
|
Preconditions.checkNotNull(req.getId());
|
||||||
|
|
||||||
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
|
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
|
||||||
|
Date insertedBefore = req.getInsertedBefore() == null ? null : new Date(req.getInsertedBefore());
|
||||||
String keywords = req.getKeywords();
|
String keywords = req.getKeywords();
|
||||||
List<FeedEntryKeyword> entryKeywords = FeedEntryKeyword.fromQueryString(keywords);
|
List<FeedEntryKeyword> entryKeywords = FeedEntryKeyword.fromQueryString(keywords);
|
||||||
|
|
||||||
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, entryKeywords);
|
feedEntryService.markSubscriptionEntries(user, subs, olderThan, insertedBefore, entryKeywords);
|
||||||
} else if (STARRED.equals(req.getId())) {
|
} else if (STARRED.equals(req.getId())) {
|
||||||
feedEntryService.markStarredEntries(user, olderThan);
|
feedEntryService.markStarredEntries(user, olderThan, insertedBefore);
|
||||||
} else {
|
} else {
|
||||||
FeedCategory parent = feedCategoryDAO.findById(user, Long.valueOf(req.getId()));
|
FeedCategory parent = feedCategoryDAO.findById(user, Long.valueOf(req.getId()));
|
||||||
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, entryKeywords);
|
feedEntryService.markSubscriptionEntries(user, subs, olderThan, insertedBefore, entryKeywords);
|
||||||
}
|
}
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -322,12 +322,14 @@ public class FeedREST {
|
|||||||
Preconditions.checkNotNull(req.getId());
|
Preconditions.checkNotNull(req.getId());
|
||||||
|
|
||||||
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
|
Date olderThan = req.getOlderThan() == null ? null : new Date(req.getOlderThan());
|
||||||
|
Date insertedBefore = req.getInsertedBefore() == null ? null : new Date(req.getInsertedBefore());
|
||||||
String keywords = req.getKeywords();
|
String keywords = req.getKeywords();
|
||||||
List<FeedEntryKeyword> entryKeywords = FeedEntryKeyword.fromQueryString(keywords);
|
List<FeedEntryKeyword> entryKeywords = FeedEntryKeyword.fromQueryString(keywords);
|
||||||
|
|
||||||
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(user, Collections.singletonList(subscription), olderThan, entryKeywords);
|
feedEntryService.markSubscriptionEntries(user, Collections.singletonList(subscription), olderThan, insertedBefore,
|
||||||
|
entryKeywords);
|
||||||
}
|
}
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,8 +189,8 @@ public class FeverREST {
|
|||||||
if (params.containsKey("mark") && params.containsKey("id") && params.containsKey("as")) {
|
if (params.containsKey("mark") && params.containsKey("id") && params.containsKey("as")) {
|
||||||
long id = Long.parseLong(params.get("id"));
|
long id = Long.parseLong(params.get("id"));
|
||||||
String before = params.get("before");
|
String before = params.get("before");
|
||||||
Date olderThan = before == null ? null : Date.from(Instant.ofEpochSecond(Long.parseLong(before)));
|
Date insertedBefore = before == null ? null : Date.from(Instant.ofEpochSecond(Long.parseLong(before)));
|
||||||
mark(user, params.get("mark"), id, params.get("as"), olderThan);
|
mark(user, params.get("mark"), id, params.get("as"), insertedBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp;
|
return resp;
|
||||||
@@ -306,7 +306,7 @@ public class FeverREST {
|
|||||||
}).toList();
|
}).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mark(User user, String source, long id, String action, Date olderThan) {
|
private void mark(User user, String source, long id, String action, Date insertedBefore) {
|
||||||
if ("item".equals(source)) {
|
if ("item".equals(source)) {
|
||||||
if ("read".equals(action) || "unread".equals(action)) {
|
if ("read".equals(action) || "unread".equals(action)) {
|
||||||
feedEntryService.markEntry(user, id, "read".equals(action));
|
feedEntryService.markEntry(user, id, "read".equals(action));
|
||||||
@@ -317,12 +317,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(user, Collections.singletonList(subscription), olderThan, null);
|
feedEntryService.markSubscriptionEntries(user, Collections.singletonList(subscription), null, insertedBefore, 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, olderThan, null);
|
feedEntryService.markSubscriptionEntries(user, subscriptions, null, insertedBefore, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user