fix: add markAllRead function and route
Restore the "Mark all as read" button functionality in channel view. The button form posts to /api/mark-read but the route and controller function were missing from the standalone repo. - Add markAllRead function to reader controller - Add /api/mark-read route to index.js - Import markItemsRead from storage/items.js Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,6 +96,7 @@ export default class MicrosubEndpoint {
|
|||||||
readerRouter.get("/search", readerController.searchPage);
|
readerRouter.get("/search", readerController.searchPage);
|
||||||
readerRouter.post("/search", readerController.searchFeeds);
|
readerRouter.post("/search", readerController.searchFeeds);
|
||||||
readerRouter.post("/subscribe", readerController.subscribe);
|
readerRouter.post("/subscribe", readerController.subscribe);
|
||||||
|
readerRouter.post("/api/mark-read", readerController.markAllRead);
|
||||||
router.use("/reader", readerRouter);
|
router.use("/reader", readerRouter);
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ import {
|
|||||||
createFeed,
|
createFeed,
|
||||||
deleteFeed,
|
deleteFeed,
|
||||||
} from "../storage/feeds.js";
|
} from "../storage/feeds.js";
|
||||||
import { getTimelineItems, getItemById } from "../storage/items.js";
|
import {
|
||||||
|
getTimelineItems,
|
||||||
|
getItemById,
|
||||||
|
markItemsRead,
|
||||||
|
} from "../storage/items.js";
|
||||||
import { getUserId } from "../utils/auth.js";
|
import { getUserId } from "../utils/auth.js";
|
||||||
import {
|
import {
|
||||||
validateChannelName,
|
validateChannelName,
|
||||||
@@ -622,6 +626,33 @@ export async function subscribe(request, response) {
|
|||||||
response.redirect(`${request.baseUrl}/channels/${channelUid}/feeds`);
|
response.redirect(`${request.baseUrl}/channels/${channelUid}/feeds`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark all items in channel as read
|
||||||
|
* @param {object} request - Express request
|
||||||
|
* @param {object} response - Express response
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
export async function markAllRead(request, response) {
|
||||||
|
const { application } = request.app.locals;
|
||||||
|
const userId = getUserId(request);
|
||||||
|
const { channel: channelUid } = request.body;
|
||||||
|
|
||||||
|
const channelDocument = await getChannel(application, channelUid, userId);
|
||||||
|
if (!channelDocument) {
|
||||||
|
return response.status(404).render("404");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark all items as read using the special "last-read-entry" value
|
||||||
|
await markItemsRead(
|
||||||
|
application,
|
||||||
|
channelDocument._id,
|
||||||
|
["last-read-entry"],
|
||||||
|
userId,
|
||||||
|
);
|
||||||
|
|
||||||
|
response.redirect(`${request.baseUrl}/channels/${channelUid}`);
|
||||||
|
}
|
||||||
|
|
||||||
export const readerController = {
|
export const readerController = {
|
||||||
index,
|
index,
|
||||||
channels,
|
channels,
|
||||||
@@ -630,6 +661,7 @@ export const readerController = {
|
|||||||
channel,
|
channel,
|
||||||
settings,
|
settings,
|
||||||
updateSettings,
|
updateSettings,
|
||||||
|
markAllRead,
|
||||||
deleteChannel: deleteChannelAction,
|
deleteChannel: deleteChannelAction,
|
||||||
feeds,
|
feeds,
|
||||||
addFeed,
|
addFeed,
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rmdes/indiekit-endpoint-microsub",
|
"name": "@rmdes/indiekit-endpoint-microsub",
|
||||||
"version": "1.0.15",
|
"version": "1.0.16",
|
||||||
"description": "Microsub endpoint for Indiekit. Enables subscribing to feeds and reading content using the Microsub protocol.",
|
"description": "Microsub endpoint for Indiekit. Enables subscribing to feeds and reading content using the Microsub protocol.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"indiekit",
|
"indiekit",
|
||||||
|
|||||||
Reference in New Issue
Block a user