43 lines
1.9 KiB
JavaScript
43 lines
1.9 KiB
JavaScript
import { limitToInt, normalizeUrlQuery } from "./timeline.js";
|
|
import { NotificationHelpers } from "../helpers/notification.js";
|
|
import { NotificationConverter } from "../converters/notification.js";
|
|
import { auth } from "../middleware/auth.js";
|
|
import { filterContext } from "../middleware/filter-context.js";
|
|
export function setupEndpointsNotifications(router) {
|
|
router.get("/v1/notifications", auth(true, [
|
|
'read:notifications'
|
|
]), filterContext('notifications'), async (ctx)=>{
|
|
const args = normalizeUrlQuery(limitToInt(ctx.query), [
|
|
'types[]',
|
|
'exclude_types[]'
|
|
]);
|
|
const res = await NotificationHelpers.getNotifications(args.max_id, args.since_id, args.min_id, args.limit, args['types[]'], args['exclude_types[]'], args.account_id, ctx);
|
|
ctx.body = await NotificationConverter.encodeMany(res, ctx);
|
|
});
|
|
router.get("/v1/notifications/:id", auth(true, [
|
|
'read:notifications'
|
|
]), filterContext('notifications'), async (ctx)=>{
|
|
const notification = await NotificationHelpers.getNotificationOr404(ctx.params.id, ctx);
|
|
ctx.body = await NotificationConverter.encode(notification, ctx);
|
|
});
|
|
router.post("/v1/notifications/clear", auth(true, [
|
|
'write:notifications'
|
|
]), async (ctx)=>{
|
|
await NotificationHelpers.clearAllNotifications(ctx);
|
|
ctx.body = {};
|
|
});
|
|
router.post("/v1/notifications/:id/dismiss", auth(true, [
|
|
'write:notifications'
|
|
]), async (ctx)=>{
|
|
const notification = await NotificationHelpers.getNotificationOr404(ctx.params.id, ctx);
|
|
await NotificationHelpers.dismissNotification(notification.id, ctx);
|
|
ctx.body = {};
|
|
});
|
|
router.post("/v1/conversations/:id/read", auth(true, [
|
|
'write:conversations'
|
|
]), async (ctx, reply)=>{
|
|
await NotificationHelpers.markConversationAsRead(ctx.params.id, ctx);
|
|
ctx.body = {};
|
|
});
|
|
}
|