From 316778687be2e2c6283454148a37579d765be303 Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 25 May 2022 07:32:40 +0000 Subject: [PATCH] Status deletion FossilOrigin-Name: 042d89e21c4edb44adda75de5557cc5bd05c5a88e8b65f1b013da0f73746fa4a --- include/mastodont_fetch.h | 3 ++- include/mastodont_request.h | 1 + include/mastodont_status.h | 1 + src/account.c | 3 +++ src/application.c | 2 ++ src/attachment.c | 1 + src/fetch.c | 14 +++++++++++--- src/list.c | 1 + src/nodeinfo.c | 1 + src/notification.c | 1 + src/relationship.c | 1 + src/request.c | 3 ++- src/scrobbles.c | 1 + src/search.c | 1 + src/static.c | 4 ++-- src/status.c | 30 ++++++++++++++++++++++++++++++ src/timeline.c | 5 +++++ 17 files changed, 66 insertions(+), 7 deletions(-) diff --git a/include/mastodont_fetch.h b/include/mastodont_fetch.h index 1b6b900..7a3f97f 100644 --- a/include/mastodont_fetch.h +++ b/include/mastodont_fetch.h @@ -30,6 +30,7 @@ void mastodont_fetch_results_cleanup(struct mstdnt_fetch_results* res); int mastodont_fetch_curl(mastodont_t* mstdnt, char* url, struct mstdnt_fetch_results* results, - CURLoption request_t); + CURLoption request_t, + char* request_t_custom); #endif /* MASTODONT_FETCH_H */ diff --git a/include/mastodont_request.h b/include/mastodont_request.h index 443fd2f..f6efa37 100644 --- a/include/mastodont_request.h +++ b/include/mastodont_request.h @@ -29,6 +29,7 @@ struct mastodont_request_args struct _mstdnt_query_param* params_post; size_t params_post_len; CURLoption request_type; + char* request_type_custom; void* args; int (*callback)(cJSON*, void*); }; diff --git a/include/mastodont_status.h b/include/mastodont_status.h index dd3dda0..18709c7 100644 --- a/include/mastodont_status.h +++ b/include/mastodont_status.h @@ -163,6 +163,7 @@ MSTDNT_STATUS_ACTION_DECL(pin); MSTDNT_STATUS_ACTION_DECL(unpin); MSTDNT_STATUS_ACTION_DECL(bookmark); MSTDNT_STATUS_ACTION_DECL(unbookmark); +MSTDNT_STATUS_ACTION_DECL(delete); int mastodont_mute_conversation(mastodont_t* data, char* id, diff --git a/src/account.c b/src/account.c index c6f6771..8cffbe8 100644 --- a/src/account.c +++ b/src/account.c @@ -71,6 +71,7 @@ int mastodont_get_account(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, acct, /* args */ mstdnt_account_json_callback, /* callback */ }; @@ -88,6 +89,7 @@ int mastodont_verify_credentials(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, acct, /* args */ mstdnt_account_json_callback, /* callback */ }; @@ -153,6 +155,7 @@ int mstdnt_account_action(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_POST, + NULL, rel, mstdnt_relationship_json_callback }; diff --git a/src/application.c b/src/application.c index 02dd53a..f34f226 100644 --- a/src/application.c +++ b/src/application.c @@ -87,6 +87,7 @@ int mastodont_register_app(mastodont_t* data, NULL, 0, params, _mstdnt_arr_len(params), CURLOPT_POST, + NULL, app, mstdnt_app_json_callback }; @@ -119,6 +120,7 @@ int mastodont_obtain_oauth_token(mastodont_t* data, params, _mstdnt_arr_len(params), CURLOPT_POST, + NULL, token, mstdnt_token_json_callback }; diff --git a/src/attachment.c b/src/attachment.c index 3487e94..b535d39 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -114,6 +114,7 @@ int mastodont_upload_media(mastodont_t* api, NULL, 0, params, _mstdnt_arr_len(params), CURLOPT_MIMEPOST, + NULL, attachment, mstdnt_attachment_json_callback, }; diff --git a/src/fetch.c b/src/fetch.c index 3434c5a..5e7e35c 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -47,8 +47,10 @@ void mastodont_fetch_results_cleanup(struct mstdnt_fetch_results* res) int mastodont_fetch_curl(mastodont_t* mstdnt, char* _url, struct mstdnt_fetch_results* results, - CURLoption request_t) + CURLoption request_t, + char* request_t_custom) { +#define is_custom request_t_custom && request_t == CURLOPT_CUSTOMREQUEST int res = 3; char token[TOKEN_STR_SIZE] = { 0 }; struct curl_slist* list = NULL; @@ -76,13 +78,19 @@ int mastodont_fetch_curl(mastodont_t* mstdnt, !MSTDNT_T_FLAG_ISSET(mstdnt, MSTDNT_FLAG_SSL_UNVERIFIED)); curl_easy_setopt(mstdnt->curl, CURLOPT_SSL_VERIFYHOST, !MSTDNT_T_FLAG_ISSET(mstdnt, MSTDNT_FLAG_SSL_UNVERIFIED)); - /* PUT, POST, GET */ + /* PUT, POST, GET, Custom */ /* Mimes are expected to be set beforehand manually */ - if (request_t != CURLOPT_MIMEPOST) + if (is_custom) + curl_easy_setopt(mstdnt->curl, request_t, request_t_custom); + else if (request_t != CURLOPT_MIMEPOST) curl_easy_setopt(mstdnt->curl, request_t, 1); res = curl_easy_perform(mstdnt->curl); + // Reset if custom + if (is_custom) + curl_easy_setopt(mstdnt->curl, request_t, NULL); + if (list) curl_slist_free_all(list); return res; diff --git a/src/list.c b/src/list.c index f8aa771..e5cdc67 100644 --- a/src/list.c +++ b/src/list.c @@ -71,6 +71,7 @@ int mastodont_get_lists(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, &args, mstdnt_lists_json_callback }; diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 10e9c82..a234a42 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -108,6 +108,7 @@ int mastodont_get_nodeinfo(mastodont_t* api, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, nodeinfo, mstdnt_nodeinfo_json_callback }; diff --git a/src/notification.c b/src/notification.c index 73d44c1..169b568 100644 --- a/src/notification.c +++ b/src/notification.c @@ -111,6 +111,7 @@ int mastodont_get_notifications(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_notifications_json_callback, }; diff --git a/src/relationship.c b/src/relationship.c index 7a20e1f..a0d7b29 100644 --- a/src/relationship.c +++ b/src/relationship.c @@ -119,6 +119,7 @@ int mastodont_get_relationships(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_relationships_json_callback }; diff --git a/src/request.c b/src/request.c index 9f91091..15e6483 100644 --- a/src/request.c +++ b/src/request.c @@ -106,7 +106,8 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args) else if (args->request_type == CURLOPT_POST) curl_easy_setopt(data->curl, CURLOPT_POSTFIELDS, ""); - curlerror = mastodont_fetch_curl(data, url_query, &results, args->request_type); + curlerror = mastodont_fetch_curl(data, url_query, &results, args->request_type, + args->request_type_custom); if (mime) curl_mime_free(mime); diff --git a/src/scrobbles.c b/src/scrobbles.c index e6f96e6..58def49 100644 --- a/src/scrobbles.c +++ b/src/scrobbles.c @@ -77,6 +77,7 @@ int mastodont_get_scrobbles(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_scrobbles_json_callback }; diff --git a/src/search.c b/src/search.c index 047ac85..2cf3689 100644 --- a/src/search.c +++ b/src/search.c @@ -87,6 +87,7 @@ int mastodont_search(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, results, mstdnt_search_json_callback }; diff --git a/src/static.c b/src/static.c index 1836f35..52d6b76 100644 --- a/src/static.c +++ b/src/static.c @@ -19,11 +19,11 @@ int mastodont_instance_panel(mastodont_t* api, struct mstdnt_fetch_results* html) { - return mastodont_fetch_curl(api, "instance/panel.html", html, CURLOPT_HTTPGET); + return mastodont_fetch_curl(api, "instance/panel.html", html, CURLOPT_HTTPGET, NULL); } int mastodont_terms_of_service(mastodont_t* api, struct mstdnt_fetch_results* html) { - return mastodont_fetch_curl(api, "static/terms-of-service.html", html, CURLOPT_HTTPGET); + return mastodont_fetch_curl(api, "static/terms-of-service.html", html, CURLOPT_HTTPGET, NULL); } diff --git a/src/status.c b/src/status.c index e5720d1..4c828a0 100644 --- a/src/status.c +++ b/src/status.c @@ -145,6 +145,7 @@ int mastodont_get_account_statuses(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback }; @@ -177,6 +178,7 @@ int mastodont_create_status(mastodont_t* data, params, _mstdnt_arr_len(params), CURLOPT_POST, NULL, + NULL, NULL, /* TODO populate the status back? * (not sure if the api returns it or not) */ }; @@ -199,6 +201,7 @@ static int mstdnt_status_action(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_POST, + NULL, status, mstdnt_status_json_callback }; @@ -231,6 +234,26 @@ MSTDNT_STATUS_ACTION_DECL(favourite) MSTDNT_STATUS_ACTION_DECL(unbookmark) MSTDNT_STATUS_ACTION_FUNC_URL("unbookmark") +// Delete's use a delete method +MSTDNT_STATUS_ACTION_DECL(delete) +{ + char url[MSTDNT_URLSIZE]; + snprintf(url, MSTDNT_URLSIZE, "api/v1/statuses/%s", id); + + struct mastodont_request_args req_args = { + storage, + url, + NULL, 0, + NULL, 0, + CURLOPT_CUSTOMREQUEST, + "DELETE", + status, + mstdnt_status_json_callback + }; + + return mastodont_request(data, &req_args); +} + /* TODO Mutes can be timed */ int mastodont_mute_conversation(mastodont_t* data, char* id, @@ -262,6 +285,7 @@ int mastodont_get_status(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, status, mstdnt_status_json_callback, }; @@ -351,6 +375,7 @@ int mastodont_get_status_context(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, &args, mstdnt_status_context_json_callback, }; @@ -377,6 +402,7 @@ int mastodont_status_favourited_by(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, &args, mstdnt_accounts_json_callback, }; @@ -403,6 +429,7 @@ int mastodont_status_reblogged_by(mastodont_t* data, NULL, 0, NULL, 0, CURLOPT_HTTPGET, + NULL, &args, mstdnt_accounts_json_callback, }; @@ -432,6 +459,7 @@ int mastodont_get_bookmarks(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback, }; @@ -459,6 +487,7 @@ int mastodont_get_favourites(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback, }; @@ -478,6 +507,7 @@ int mastodont_status_emoji_react(mastodont_t* api, char* id, char* emoji, NULL, 0, NULL, 0, CURLOPT_PUT, + NULL, status, mstdnt_status_json_callback }; diff --git a/src/timeline.c b/src/timeline.c index dc654f2..9fd86ba 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -44,6 +44,7 @@ int mastodont_timeline_list(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback, }; @@ -80,6 +81,7 @@ int mastodont_timeline_tag(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback, }; @@ -110,6 +112,7 @@ int mastodont_timeline_public(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback, }; @@ -142,6 +145,7 @@ int mastodont_timeline_direct(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback, }; @@ -172,6 +176,7 @@ int mastodont_timeline_home(mastodont_t* data, params, _mstdnt_arr_len(params), NULL, 0, CURLOPT_HTTPGET, + NULL, &cb_args, mstdnt_statuses_json_callback, };