@rmdes/indiekit-endpoint-microsub 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -0
- package/lib/controllers/reader.js +33 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -96,6 +96,7 @@ export default class MicrosubEndpoint {
|
|
|
96
96
|
readerRouter.get("/search", readerController.searchPage);
|
|
97
97
|
readerRouter.post("/search", readerController.searchFeeds);
|
|
98
98
|
readerRouter.post("/subscribe", readerController.subscribe);
|
|
99
|
+
readerRouter.post("/api/mark-read", readerController.markAllRead);
|
|
99
100
|
router.use("/reader", readerRouter);
|
|
100
101
|
|
|
101
102
|
return router;
|
|
@@ -17,7 +17,11 @@ import {
|
|
|
17
17
|
createFeed,
|
|
18
18
|
deleteFeed,
|
|
19
19
|
} from "../storage/feeds.js";
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
getTimelineItems,
|
|
22
|
+
getItemById,
|
|
23
|
+
markItemsRead,
|
|
24
|
+
} from "../storage/items.js";
|
|
21
25
|
import { getUserId } from "../utils/auth.js";
|
|
22
26
|
import {
|
|
23
27
|
validateChannelName,
|
|
@@ -622,6 +626,33 @@ export async function subscribe(request, response) {
|
|
|
622
626
|
response.redirect(`${request.baseUrl}/channels/${channelUid}/feeds`);
|
|
623
627
|
}
|
|
624
628
|
|
|
629
|
+
/**
|
|
630
|
+
* Mark all items in channel as read
|
|
631
|
+
* @param {object} request - Express request
|
|
632
|
+
* @param {object} response - Express response
|
|
633
|
+
* @returns {Promise<void>}
|
|
634
|
+
*/
|
|
635
|
+
export async function markAllRead(request, response) {
|
|
636
|
+
const { application } = request.app.locals;
|
|
637
|
+
const userId = getUserId(request);
|
|
638
|
+
const { channel: channelUid } = request.body;
|
|
639
|
+
|
|
640
|
+
const channelDocument = await getChannel(application, channelUid, userId);
|
|
641
|
+
if (!channelDocument) {
|
|
642
|
+
return response.status(404).render("404");
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// Mark all items as read using the special "last-read-entry" value
|
|
646
|
+
await markItemsRead(
|
|
647
|
+
application,
|
|
648
|
+
channelDocument._id,
|
|
649
|
+
["last-read-entry"],
|
|
650
|
+
userId,
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
response.redirect(`${request.baseUrl}/channels/${channelUid}`);
|
|
654
|
+
}
|
|
655
|
+
|
|
625
656
|
export const readerController = {
|
|
626
657
|
index,
|
|
627
658
|
channels,
|
|
@@ -630,6 +661,7 @@ export const readerController = {
|
|
|
630
661
|
channel,
|
|
631
662
|
settings,
|
|
632
663
|
updateSettings,
|
|
664
|
+
markAllRead,
|
|
633
665
|
deleteChannel: deleteChannelAction,
|
|
634
666
|
feeds,
|
|
635
667
|
addFeed,
|
package/package.json
CHANGED