1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2025-06-20 00:25:17 +00:00

Can mark related notifications as seen

This commit is contained in:
2020-03-25 08:23:09 +01:00
parent 890e49a4ae
commit c67112d926
4 changed files with 77 additions and 3 deletions

View File

@ -53,6 +53,59 @@ export class NotificationsController {
h.send(list.map(this.NotifToAPI));
}
/**
* Mark a notification as seen
*
* @param h Request handler
*/
public static async MarkSeen(h: RequestHandler) {
const notifID = await this.PostNotifyID(h, "notifID")
const deleteSimilar = h.postBool("delete_similar", false)
// Check if we are targetting a precise notification or
// an unfinite number of similar notifications
if(!deleteSimilar) {
await NotificationsHelper.Delete(new Notif({
id: notifID
}))
}
else {
// Get information about the notification
const notif = await NotificationsHelper.GetSingle(notifID);
await NotificationsHelper.Delete(new Notif({
onElemType: notif.onElemType,
onElemID: notif.onElemID,
destUserID: h.getUserId()
}));
}
h.success()
}
/**
* The the ID of a notification included in a request
*
* @param h Request handler
* @param name The name of the post field
*/
private static async PostNotifyID(h: RequestHandler, name: string) {
const notifID = h.postInt(name);
// Check if the notification exists and targets the current user
const n = new Notif({
id: notifID,
destUserID: h.getUserId()
});
if(!await NotificationsHelper.SimilarExists(n))
h.error(404, "Specified notification not found!");
return notifID;
}
/**
* Transform a notification into an API entry
*

View File

@ -262,6 +262,8 @@ export const Routes : Route[] = [
{path: "/notifications/get_list_unread", cb: (h) => NotificationsController.GetListUnread(h)},
{path: "/notifications/mark_seen", cb: (h) => NotificationsController.MarkSeen(h)},
// Movies controller