@rmdes/indiekit-endpoint-microsub 1.0.8 → 1.0.9
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,
|
|
@@ -173,6 +177,33 @@ export async function updateSettings(request, response) {
|
|
|
173
177
|
response.redirect(`${request.baseUrl}/channels/${uid}`);
|
|
174
178
|
}
|
|
175
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Mark all items in channel as read
|
|
182
|
+
* @param {object} request - Express request
|
|
183
|
+
* @param {object} response - Express response
|
|
184
|
+
* @returns {Promise<void>}
|
|
185
|
+
*/
|
|
186
|
+
export async function markAllRead(request, response) {
|
|
187
|
+
const { application } = request.app.locals;
|
|
188
|
+
const userId = getUserId(request);
|
|
189
|
+
const { channel: channelUid } = request.body;
|
|
190
|
+
|
|
191
|
+
const channelDocument = await getChannel(application, channelUid, userId);
|
|
192
|
+
if (!channelDocument) {
|
|
193
|
+
return response.status(404).render("404");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Mark all items as read using the special "last-read-entry" value
|
|
197
|
+
await markItemsRead(
|
|
198
|
+
application,
|
|
199
|
+
channelDocument._id,
|
|
200
|
+
["last-read-entry"],
|
|
201
|
+
userId,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
response.redirect(`${request.baseUrl}/channels/${channelUid}`);
|
|
205
|
+
}
|
|
206
|
+
|
|
176
207
|
/**
|
|
177
208
|
* Delete channel
|
|
178
209
|
* @param {object} request - Express request
|
|
@@ -573,6 +604,7 @@ export const readerController = {
|
|
|
573
604
|
channel,
|
|
574
605
|
settings,
|
|
575
606
|
updateSettings,
|
|
607
|
+
markAllRead,
|
|
576
608
|
deleteChannel: deleteChannelAction,
|
|
577
609
|
feeds,
|
|
578
610
|
addFeed,
|
package/package.json
CHANGED