From c9c954d5e6dbef06b0ef59210f483670c9535176 Mon Sep 17 00:00:00 2001 From: nekobit Date: Thu, 11 Aug 2022 03:03:58 +0000 Subject: [PATCH] Notifications clear all and dismiss FossilOrigin-Name: 0728b716da36f28436b57c336b2244815de252c81e00fdfaff138612b042bef8 --- include/mastodont_notification.h | 9 +++++++ src/notification.c | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/mastodont_notification.h b/include/mastodont_notification.h index 78cfc0e..dd28331 100644 --- a/include/mastodont_notification.h +++ b/include/mastodont_notification.h @@ -64,6 +64,15 @@ int mastodont_get_notifications(mastodont_t* data, struct mstdnt_notification** notifs, size_t* size); +int mastodont_notifications_clear(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_storage* storage); + +int mastodont_notification_dismiss(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_storage* storage, + char* id); + int mstdnt_notification_json(struct mstdnt_notification* notif, cJSON* js); void mstdnt_cleanup_notifications(struct mstdnt_notification* notif, size_t notif_len); void mstdnt_cleanup_notification(struct mstdnt_notification* notif); diff --git a/src/notification.c b/src/notification.c index 679795e..a249fce 100644 --- a/src/notification.c +++ b/src/notification.c @@ -121,6 +121,47 @@ int mastodont_get_notifications(mastodont_t* data, return mastodont_request(data, m_args, &req_args); } +int mastodont_notification_dismiss(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_storage* storage, + char* id) +{ + char url[MSTDNT_URLSIZE]; + snprintf(url, MSTDNT_URLSIZE, "api/v1/notifications/%s/dismiss", id); + + struct mastodont_request_args req_args = { + storage, + url, + NULL, 0, + NULL, 0, + CURLOPT_POST, + NULL, + NULL, + NULL, + }; + + return mastodont_request(data, m_args, &req_args); +} + +int mastodont_notifications_clear(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_storage* storage) +{ + struct mastodont_request_args req_args = { + storage, + "api/v1/notifications/clear", + NULL, 0, + NULL, 0, + CURLOPT_POST, + NULL, + NULL, + NULL, + }; + + return mastodont_request(data, m_args, &req_args); +} + + void mstdnt_cleanup_notifications(struct mstdnt_notification* notifs, size_t notifs_len) { size_t i;