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) {