From b8fef4973745a8ccd44fccaccf174a2f4fbb63c9 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Tue, 5 Apr 2022 14:43:38 +0000 Subject: [PATCH] Account actions FossilOrigin-Name: d61c06882f8e3e4eb00c062d465b90edc14cad7fbf9d888acc8f307f6152cbcc --- include/mastodont_account.h | 14 +++++++++++ src/account.c | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/include/mastodont_account.h b/include/mastodont_account.h index d30a3bb..5898fed 100644 --- a/include/mastodont_account.h +++ b/include/mastodont_account.h @@ -55,6 +55,20 @@ struct mstdnt_account char* mute_expires_at; }; +#define MSTDNT_ACCOUNT_ACTION_DECL(type) int mastodont_##type##_account(mastodont_t* data, char* id, struct mstdnt_storage* storage, struct mstdnt_account* acct) +#define MSTDNT_ACCOUNT_ACTION_FUNC_URL(action) { \ + return mstdnt_account_action(data, id, storage, acct, "api/v1/accounts/%s/" action);\ + } + +MSTDNT_ACCOUNT_ACTION_DECL(follow); +MSTDNT_ACCOUNT_ACTION_DECL(unfollow); +MSTDNT_ACCOUNT_ACTION_DECL(mute); +MSTDNT_ACCOUNT_ACTION_DECL(unmute); +MSTDNT_ACCOUNT_ACTION_DECL(block); +MSTDNT_ACCOUNT_ACTION_DECL(unblock); +MSTDNT_ACCOUNT_ACTION_DECL(subscribe); +MSTDNT_ACCOUNT_ACTION_DECL(unsubscribe); + int mstdnt_account_from_result(struct mstdnt_fetch_results* results, struct mstdnt_storage* storage, struct mstdnt_account* acct, diff --git a/src/account.c b/src/account.c index d491f50..dde9ddd 100644 --- a/src/account.c +++ b/src/account.c @@ -133,3 +133,52 @@ int mstdnt_account_from_json(struct mstdnt_account* acct, cJSON* js) _mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs)); } } + + +static int mstdnt_account_action(mastodont_t* data, + char* id, + struct mstdnt_storage* storage, + struct mstdnt_account* acct, + char* url_str) +{ + char url[MSTDNT_URLSIZE]; + snprintf(url, MSTDNT_URLSIZE, url_str, id); + + struct mastodont_request_args req_args = { + storage, + url, + NULL, 0, + NULL, 0, + CURLOPT_POST, + acct, + mstdnt_account_callback + }; + + return mastodont_request(data, &req_args); +} + + +/* These are all the same */ +MSTDNT_ACCOUNT_ACTION_DECL(follow) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("follow") + +MSTDNT_ACCOUNT_ACTION_DECL(unfollow) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("unfollow") + +MSTDNT_ACCOUNT_ACTION_DECL(mute) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("mute") + +MSTDNT_ACCOUNT_ACTION_DECL(unmute) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("unmute") + +MSTDNT_ACCOUNT_ACTION_DECL(block) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("block") + +MSTDNT_ACCOUNT_ACTION_DECL(unblock) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("unblock") + +MSTDNT_ACCOUNT_ACTION_DECL(subscribe) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("subscribe") + +MSTDNT_ACCOUNT_ACTION_DECL(unsubscribe) +MSTDNT_ACCOUNT_ACTION_FUNC_URL("unsubscribe")