Status deletion

FossilOrigin-Name: 042d89e21c4edb44adda75de5557cc5bd05c5a88e8b65f1b013da0f73746fa4a
This commit is contained in:
nekobit 2022-05-25 07:32:40 +00:00
parent 9cd440f305
commit 316778687b
17 changed files with 66 additions and 7 deletions

View file

@ -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 */

View file

@ -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*);
};

View file

@ -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,

View file

@ -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
};

View file

@ -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
};

View file

@ -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,
};

View file

@ -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;

View file

@ -71,6 +71,7 @@ int mastodont_get_lists(mastodont_t* data,
NULL, 0,
NULL, 0,
CURLOPT_HTTPGET,
NULL,
&args,
mstdnt_lists_json_callback
};

View file

@ -108,6 +108,7 @@ int mastodont_get_nodeinfo(mastodont_t* api,
NULL, 0,
NULL, 0,
CURLOPT_HTTPGET,
NULL,
nodeinfo,
mstdnt_nodeinfo_json_callback
};

View file

@ -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,
};

View file

@ -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
};

View file

@ -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);

View file

@ -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
};

View file

@ -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
};

View file

@ -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);
}

View file

@ -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
};

View file

@ -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,
};