mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-25 02:09:05 +01:00
[mastodon-client] POST /notifications/:id/dismiss; POST /notifications/clear
This commit is contained in:
parent
ac6ba79a36
commit
72619198b9
@ -63,13 +63,17 @@ export function apiNotificationsMastodon(router: Router): void {
|
||||
});
|
||||
|
||||
router.post("/v1/notifications/clear", async (ctx) => {
|
||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
||||
const accessTokens = ctx.request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
const body: any = ctx.request.body;
|
||||
try {
|
||||
const data = await client.dismissNotifications();
|
||||
ctx.body = data.data;
|
||||
const auth = await authenticate(ctx.headers.authorization, null);
|
||||
const user = auth[0] ?? null;
|
||||
|
||||
if (!user) {
|
||||
ctx.status = 401;
|
||||
return;
|
||||
}
|
||||
|
||||
await NotificationHelpers.clearAllNotifications(user);
|
||||
ctx.body = {};
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
ctx.status = 401;
|
||||
@ -77,16 +81,24 @@ export function apiNotificationsMastodon(router: Router): void {
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/v1/notification/:id/dismiss", async (ctx) => {
|
||||
const BASE_URL = `${ctx.request.protocol}://${ctx.request.hostname}`;
|
||||
const accessTokens = ctx.request.headers.authorization;
|
||||
const client = getClient(BASE_URL, accessTokens);
|
||||
const body: any = ctx.request.body;
|
||||
router.post("/v1/notifications/:id/dismiss", async (ctx) => {
|
||||
try {
|
||||
const data = await client.dismissNotification(
|
||||
convertId(ctx.params.id, IdType.IceshrimpId),
|
||||
);
|
||||
ctx.body = data.data;
|
||||
const auth = await authenticate(ctx.headers.authorization, null);
|
||||
const user = auth[0] ?? null;
|
||||
|
||||
if (!user) {
|
||||
ctx.status = 401;
|
||||
return;
|
||||
}
|
||||
|
||||
const notification = await NotificationHelpers.getNotification(convertId(ctx.params.id, IdType.IceshrimpId), user);
|
||||
if (notification === null) {
|
||||
ctx.status = 404;
|
||||
return;
|
||||
}
|
||||
|
||||
await NotificationHelpers.dismissNotification(notification.id, user);
|
||||
ctx.body = {};
|
||||
} catch (e: any) {
|
||||
console.error(e);
|
||||
ctx.status = 401;
|
||||
|
@ -37,6 +37,14 @@ export class NotificationHelpers {
|
||||
return Notifications.findOneBy({id: id, notifieeId: user.id});
|
||||
}
|
||||
|
||||
public static async dismissNotification(id: string, user: ILocalUser): Promise<void> {
|
||||
const result = await Notifications.update({id: id, notifieeId: user.id}, {isRead: true});
|
||||
}
|
||||
|
||||
public static async clearAllNotifications(user: ILocalUser): Promise<void> {
|
||||
await Notifications.update({notifieeId: user.id}, {isRead: true});
|
||||
}
|
||||
|
||||
private static decodeTypes(types: string[]) {
|
||||
const result: string[] = [];
|
||||
if (types.includes('follow')) result.push('follow');
|
||||
|
Loading…
Reference in New Issue
Block a user