From a264bfafb31eabe8178fd227b9ac8500f5dea832 Mon Sep 17 00:00:00 2001 From: nekobit Date: Fri, 10 Jun 2022 05:36:04 +0000 Subject: [PATCH] Get muted, blocks, followers, following FossilOrigin-Name: 7cfafc700ed0ff149885a3cea84fd49ef3891926a0d93244db51a65fdbe26e40 --- include/mastodont_account.h | 38 ++++++++++++++++- include/mastodont_timeline.h | 2 +- src/account.c | 79 +++++++++++++++++++++++++++++++++++- src/status.c | 4 +- 4 files changed, 118 insertions(+), 5 deletions(-) diff --git a/include/mastodont_account.h b/include/mastodont_account.h index cb7fcaa..517f7bc 100644 --- a/include/mastodont_account.h +++ b/include/mastodont_account.h @@ -24,7 +24,7 @@ #define MSTDNT_LOOKUP_ACCT 0 #define MSTDNT_LOOKUP_ID 1 -struct mstdnt_account_args +struct _mstdnt_accounts_args { struct mstdnt_account** acct; size_t* size; @@ -66,6 +66,16 @@ struct mstdnt_account char* mute_expires_at; }; +struct mstdnt_account_args +{ + char* max_id; + char* min_id; + char* since_id; + int offset; + int limit; + int with_relationships; // mastodont_get_mutes +}; + int mstdnt_account_action(mastodont_t* data, char* id, struct mstdnt_storage* storage, @@ -99,6 +109,32 @@ int mastodont_get_account(mastodont_t* data, struct mstdnt_account* acct, struct mstdnt_storage* storage); +int mastodont_get_blocks(mastodont_t* data, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len); + +int mastodont_get_mutes(mastodont_t* data, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len); + +int mastodont_get_followers(mastodont_t* data, + char* id, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len); + +int mastodont_get_following(mastodont_t* data, + char* id, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len); + int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js); int mstdnt_account_json_callback(cJSON* json, void* _args); int mstdnt_accounts_json_callback(cJSON* json, void* _args); diff --git a/include/mastodont_timeline.h b/include/mastodont_timeline.h index 04a72d0..d58036f 100644 --- a/include/mastodont_timeline.h +++ b/include/mastodont_timeline.h @@ -20,7 +20,7 @@ enum mstdnt_reply_visibility { - MSTDNT_REPLY_VIS_NONE, + MSTDNT_REPLY_VIS_NONE = 0, MSTDNT_REPLY_VIS_SELF, MSTDNT_REPLY_VIS_FOLLOWING, }; diff --git a/src/account.c b/src/account.c index 8cffbe8..7de8a46 100644 --- a/src/account.c +++ b/src/account.c @@ -49,10 +49,87 @@ int mstdnt_account_json_callback(cJSON* json, void* _args) int mstdnt_accounts_json_callback(cJSON* json, void* _args) { - struct mstdnt_account_args* args = _args; + struct _mstdnt_accounts_args* args = _args; return mstdnt_accounts_json(args->acct, args->size, json); } +static int mastodont_get_accounts_query(char* url, + mastodont_t* data, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len) +{ + struct _mstdnt_accounts_args _args = { + accts, + accts_len, + }; + + struct _mstdnt_query_param params[] = { + { _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } }, + { _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } }, + { _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } }, + { _MSTDNT_QUERY_INT, "offset", { .i = args->offset } }, + { _MSTDNT_QUERY_INT, "limit", { .i = args->limit } }, + { _MSTDNT_QUERY_INT, "with_relationships", { .i = args->with_relationships } }, + }; + + struct mastodont_request_args req_args = { + storage, + url, + NULL, 0, + NULL, 0, + CURLOPT_HTTPGET, + NULL, + &_args, + mstdnt_accounts_json_callback, + }; + + return mastodont_request(data, &req_args); +} + +int mastodont_get_followers(mastodont_t* data, + char* id, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len) +{ + char url[MSTDNT_URLSIZE]; + snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/followers", id); + return mastodont_get_accounts_query(url, data, args, storage, accts, accts_len); +} + +int mastodont_get_following(mastodont_t* data, + char* id, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len) +{ + char url[MSTDNT_URLSIZE]; + snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/following", id); + return mastodont_get_accounts_query(url, data, args, storage, accts, accts_len); +} + +int mastodont_get_blocks(mastodont_t* data, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len) +{ + return mastodont_get_accounts_query("api/v1/blocks", data, args, storage, accts, accts_len); +} + +int mastodont_get_mutes(mastodont_t* data, + struct mstdnt_account_args* args, + struct mstdnt_storage* storage, + struct mstdnt_account* accts[], + size_t* accts_len) +{ + return mastodont_get_accounts_query("api/v1/mutes", data, args, storage, accts, accts_len); +} + int mastodont_get_account(mastodont_t* data, int lookup, /* TODO move into separate function for consistancy */ char* id, diff --git a/src/status.c b/src/status.c index 4c828a0..0820074 100644 --- a/src/status.c +++ b/src/status.c @@ -389,7 +389,7 @@ int mastodont_status_favourited_by(mastodont_t* data, struct mstdnt_account* accounts[], size_t* accts_len) { - struct mstdnt_account_args args = { + struct _mstdnt_accounts_args args = { accounts, accts_len, }; @@ -416,7 +416,7 @@ int mastodont_status_reblogged_by(mastodont_t* data, struct mstdnt_account* accounts[], size_t* accts_len) { - struct mstdnt_account_args args = { + struct _mstdnt_accounts_args args = { accounts, accts_len, };