Bookmarks and favorites

FossilOrigin-Name: 442bade4de54b8236d59ab8b90b0e1f7f3ead95247075f9e6ef0bf2c8aa19241
This commit is contained in:
me@ow.nekobit.net 2022-04-27 15:42:22 +00:00
parent e3763457e5
commit 813418a403
3 changed files with 97 additions and 1 deletions

View file

@ -183,6 +183,33 @@ struct _mstdnt_status_context_result_cb_args
size_t* size_after;
};
struct mstdnt_bookmarks_args
{
char* max_id;
char* since_id;
char* min_id;
int limit;
};
struct mstdnt_favourites_args
{
char* max_id;
char* min_id;
int limit;
};
int mastodont_get_bookmarks(mastodont_t* data,
struct mstdnt_bookmarks_args* args,
struct mstdnt_storage* storage,
struct mstdnt_status* statuses[],
size_t* size);
int mastodont_get_favourites(mastodont_t* data,
struct mstdnt_favourites_args* args,
struct mstdnt_storage* storage,
struct mstdnt_status* statuses[],
size_t* size);
int _mstdnt_statuses_result_callback(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
void* _args);

View file

@ -161,6 +161,8 @@ int mstdnt_account_from_json(struct mstdnt_account* acct, cJSON* js)
{
_mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs));
}
return 0;
}
@ -186,7 +188,6 @@ int mstdnt_account_action(mastodont_t* data,
return mastodont_request(data, &req_args);
}
/* These are all the same */
MSTDNT_ACCOUNT_ACTION_DECL(follow)
MSTDNT_ACCOUNT_ACTION_FUNC_URL("follow")

View file

@ -485,6 +485,74 @@ int mastodont_status_reblogged_by(mastodont_t* data,
return mastodont_request(data, &req_args);
}
int mastodont_get_bookmarks(mastodont_t* data,
struct mstdnt_bookmarks_args* args,
struct mstdnt_storage* storage,
struct mstdnt_status* statuses[],
size_t* size)
{
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
union param_value u_max_id, u_since_id, u_min_id, u_limit;
u_max_id.s = args->max_id;
u_since_id.s = args->since_id;
u_min_id.s = args->min_id;
u_limit.i = args->limit;
struct _mstdnt_query_param params[] = {
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
{ _MSTDNT_QUERY_INT, "limit", u_limit },
};
struct mastodont_request_args req_args = {
storage,
"api/v1/bookmarks",
params, _mstdnt_arr_len(params),
NULL, 0,
CURLOPT_HTTPGET,
&cb_args,
_mstdnt_statuses_result_callback,
};
return mastodont_request(data, &req_args);
}
int mastodont_get_favourites(mastodont_t* data,
struct mstdnt_favourites_args* args,
struct mstdnt_storage* storage,
struct mstdnt_status* statuses[],
size_t* size)
{
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
union param_value u_max_id, u_min_id, u_limit;
u_max_id.s = args->max_id;
u_min_id.s = args->min_id;
u_limit.i = args->limit;
struct _mstdnt_query_param params[] = {
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
{ _MSTDNT_QUERY_INT, "limit", u_limit },
};
struct mastodont_request_args req_args = {
storage,
"api/v1/favourites",
params, _mstdnt_arr_len(params),
NULL, 0,
CURLOPT_HTTPGET,
&cb_args,
_mstdnt_statuses_result_callback,
};
return mastodont_request(data, &req_args);
}
void mstdnt_cleanup_status(struct mstdnt_status* status)
{
cleanup_attachments(status->media_attachments);