From dd924763988741bc7ac9ad74c85a06b69a64d435 Mon Sep 17 00:00:00 2001 From: nekobit Date: Sat, 13 Aug 2022 01:38:33 +0000 Subject: [PATCH] Mark notifications as read FossilOrigin-Name: 181705589760101d4ae95b7693452a6cc3a840885f2381a88755eb11d1d6bc5e --- include/mastodont_notification.h | 4 +++- src/notification.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/mastodont_notification.h b/include/mastodont_notification.h index a1a249b..1ecc84b 100644 --- a/include/mastodont_notification.h +++ b/include/mastodont_notification.h @@ -56,6 +56,7 @@ struct _mstdnt_notifications_result_cb_args size_t* size; }; +int mstdnt_notification_json_callback(cJSON* json, void* notif); int mstdnt_notifications_json_callback(cJSON* json, void* _args); int mastodont_get_notifications(mastodont_t* data, @@ -72,7 +73,8 @@ int mastodont_notifications_clear(mastodont_t* data, int mastodont_notifications_read(mastodont_t* data, struct mstdnt_args* m_args, struct mstdnt_notifications_args* args, - struct mstdnt_storage* storage); + struct mstdnt_storage* storage, + struct mstdnt_notification* notification); int mastodont_notification_dismiss(mastodont_t* data, struct mstdnt_args* m_args, diff --git a/src/notification.c b/src/notification.c index 528a937..8d1fda8 100644 --- a/src/notification.c +++ b/src/notification.c @@ -68,9 +68,14 @@ int mstdnt_notification_json(struct mstdnt_notification* notif, cJSON* js) return 0; } +int mstdnt_notification_json_callback(cJSON* json, void* notif) +{ + return mstdnt_notification_json(notif, json->child); +} + GENERATE_JSON_ARRAY_FUNC(mstdnt_notifications_json, struct mstdnt_notification, mstdnt_notification_json) -int mstdnt_notifications_json_callback(cJSON* json, void* _args) + int mstdnt_notifications_json_callback(cJSON* json, void* _args) { struct _mstdnt_notifications_result_cb_args* args = _args; return mstdnt_notifications_json(args->notif, args->size, json); @@ -161,6 +166,31 @@ int mastodont_notifications_clear(mastodont_t* data, return mastodont_request(data, m_args, &req_args); } +int mastodont_notifications_read(mastodont_t* data, + struct mstdnt_args* m_args, + struct mstdnt_notifications_args* args, + struct mstdnt_storage* storage, + struct mstdnt_notification* notification) +{ + struct _mstdnt_query_param params[] = { + { _MSTDNT_QUERY_STRING, "id", { .s = args->id } }, + { _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } }, + }; + + struct mastodont_request_args req_args = { + storage, + "api/v1/pleroma/notifications/read", + NULL, 0, + params, _mstdnt_arr_len(params), + CURLOPT_POST, + NULL, + notification, + mstdnt_notification_json_callback, + }; + + return mastodont_request(data, m_args, &req_args); +} + void mstdnt_cleanup_notifications(struct mstdnt_notification* notifs, size_t notifs_len) {