From 9c72241040d529431fe19d6d392c0f9b96801d1a Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 9 Nov 2022 00:57:05 +0000 Subject: [PATCH] Timeline updates FossilOrigin-Name: a4cc696b0189b720b7c92323fcc3420d160420a16a843b91a0659e0093f475f3 --- include/mastodont_timeline.h | 59 ++++++------ src/timeline.c | 176 ++++++++++++++++------------------- 2 files changed, 113 insertions(+), 122 deletions(-) diff --git a/include/mastodont_timeline.h b/include/mastodont_timeline.h index 38b53ac..54c98c9 100644 --- a/include/mastodont_timeline.h +++ b/include/mastodont_timeline.h @@ -40,36 +40,41 @@ struct mstdnt_timeline_args int with_muted; }; -int mstdnt_timeline_home(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - struct mstdnt_timeline_args* args); +int +mstdnt_timeline_home(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + struct mstdnt_timeline_args args); -int mstdnt_timeline_list(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - char* list_id, - struct mstdnt_timeline_args* args); +int +mstdnt_timeline_list(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + char* list_id, + struct mstdnt_timeline_args args); -int mstdnt_timeline_public(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - struct mstdnt_timeline_args* args); +int +mstdnt_timeline_public(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + struct mstdnt_timeline_args args); -int mstdnt_timeline_direct(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - struct mstdnt_timeline_args* args); +int +mstdnt_timeline_direct(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + struct mstdnt_timeline_args args); -int mstdnt_timeline_tag(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - char* hashtag, - struct mstdnt_timeline_args* args); +int +mstdnt_timeline_tag(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + char* hashtag, + struct mstdnt_timeline_args args); #endif /* MASTODONT_TIMELINE_H */ diff --git a/src/timeline.c b/src/timeline.c index 4ea3386..9c2591b 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -20,86 +20,81 @@ #include #include -int mstdnt_timeline_list(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - char* list_id, - struct mstdnt_timeline_args* args) +int +mstdnt_timeline_list(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + char* list_id, + struct mstdnt_timeline_args args) { char url[MSTDNT_URLSIZE]; snprintf(url, MSTDNT_URLSIZE, "api/v1/timelines/list/%s", list_id); struct _mstdnt_query_param params[] = { - { _MSTDNT_QUERY_BOOL, "local", { .b = args->local } }, - { _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } }, - { _MSTDNT_QUERY_BOOL, "only_media", { .b = args->only_media } }, - { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } }, - /* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args->only_media } }, */ - { _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } }, - { _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } }, - { _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } }, - { _MSTDNT_QUERY_INT, "limit", { .i = args->limit } }, - { _MSTDNT_QUERY_INT, "offset", { .i = args->offset } }, + { _MSTDNT_QUERY_BOOL, "local", { .b = args.local } }, + { _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } }, + { _MSTDNT_QUERY_BOOL, "only_media", { .b = args.only_media } }, + { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } }, + /* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args.only_media } }, */ + { _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } }, + { _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } }, + { _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } }, + { _MSTDNT_QUERY_INT, "limit", { .i = args.limit } }, + { _MSTDNT_QUERY_INT, "offset", { .i = args.offset } }, }; struct mstdnt_request_args req_args = { .url = url, .params_query = params, .params_query_len = _mstdnt_arr_len(params), - .params_post = NULL, - .params_post_len = 0, .request_type = CURLOPT_HTTPGET, - .request_type_custom = NULL, - .args = NULL, .callback = mstdnt_statuses_json_callback, }; return mstdnt_request(data, m_args, cb_request, cb_args, &req_args); } -int mstdnt_timeline_tag(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - char* hashtag, - struct mstdnt_timeline_args* args) +int +mstdnt_timeline_tag(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + char* hashtag, + struct mstdnt_timeline_args args) { char url[MSTDNT_URLSIZE]; snprintf(url, MSTDNT_URLSIZE, "api/v1/timelines/tag/%s", hashtag); struct _mstdnt_query_param params[] = { - { _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } }, - { _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } }, - { _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } }, + { _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } }, + { _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } }, + { _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } }, // TODO ANY // TODO ALL // TODO NONE // TODO exclude_visibilities - { _MSTDNT_QUERY_INT, "limit", { .i = args->limit } }, - { _MSTDNT_QUERY_INT, "offset", { .i = args->offset } }, - { _MSTDNT_QUERY_BOOL, "local", { .b = args->local } }, - { _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } }, - { _MSTDNT_QUERY_BOOL, "only_media", { .b = args->only_media } }, - { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } }, + { _MSTDNT_QUERY_INT, "limit", { .i = args.limit } }, + { _MSTDNT_QUERY_INT, "offset", { .i = args.offset } }, + { _MSTDNT_QUERY_BOOL, "local", { .b = args.local } }, + { _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } }, + { _MSTDNT_QUERY_BOOL, "only_media", { .b = args.only_media } }, + { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } }, }; struct mstdnt_request_args req_args = { .url = url, .params_query = params, .params_query_len = _mstdnt_arr_len(params), - .params_post = NULL, - .params_post_len = 0, .request_type = CURLOPT_HTTPGET, - .request_type_custom = NULL, - .args = NULL, .callback = mstdnt_statuses_json_callback, }; return mstdnt_request(data, m_args, cb_request, cb_args, &req_args); } -static const char* reply_visibility_str(enum mstdnt_reply_visibility vis) +static const char* +reply_visibility_str(enum mstdnt_reply_visibility vis) { switch (vis) { @@ -113,35 +108,32 @@ static const char* reply_visibility_str(enum mstdnt_reply_visibility vis) } } -int mstdnt_timeline_public(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - struct mstdnt_timeline_args* args) +int +mstdnt_timeline_public(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + struct mstdnt_timeline_args args) { struct _mstdnt_query_param params[] = { - { _MSTDNT_QUERY_BOOL, "local", { .b = args->local } }, - { _MSTDNT_QUERY_STRING, "instance", { .s = args->instance } }, - { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } }, - { _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args->reply_visibility) } }, - { _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } }, - { _MSTDNT_QUERY_BOOL, "only_media", { .b = args->only_media } }, - { _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } }, - { _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } }, - { _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } }, - { _MSTDNT_QUERY_INT, "offset", { .i = args->offset } }, - { _MSTDNT_QUERY_INT, "limit", { .i = args->limit } }, + { _MSTDNT_QUERY_BOOL, "local", { .b = args.local } }, + { _MSTDNT_QUERY_STRING, "instance", { .s = args.instance } }, + { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } }, + { _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args.reply_visibility) } }, + { _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } }, + { _MSTDNT_QUERY_BOOL, "only_media", { .b = args.only_media } }, + { _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } }, + { _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } }, + { _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } }, + { _MSTDNT_QUERY_INT, "offset", { .i = args.offset } }, + { _MSTDNT_QUERY_INT, "limit", { .i = args.limit } }, }; struct mstdnt_request_args req_args = { .url = "api/v1/timelines/public", .params_query = params, .params_query_len = _mstdnt_arr_len(params), - .params_post = NULL, - .params_post_len = 0, .request_type = CURLOPT_HTTPGET, - .request_type_custom = NULL, - .args = NULL, .callback = mstdnt_statuses_json_callback, }; @@ -149,30 +141,27 @@ int mstdnt_timeline_public(mastodont_t* data, } -int mstdnt_timeline_direct(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - struct mstdnt_timeline_args* args) +int +mstdnt_timeline_direct(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + struct mstdnt_timeline_args args) { struct _mstdnt_query_param params[] = { - { _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } }, - { _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } }, - { _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } }, - { _MSTDNT_QUERY_INT, "limit", { .i = args->limit } }, - { _MSTDNT_QUERY_INT, "offset", { .i = args->offset } }, - { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } }, + { _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } }, + { _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } }, + { _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } }, + { _MSTDNT_QUERY_INT, "limit", { .i = args.limit } }, + { _MSTDNT_QUERY_INT, "offset", { .i = args.offset } }, + { _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } }, }; struct mstdnt_request_args req_args = { .url = "api/v1/timelines/direct", .params_query = params, .params_query_len = _mstdnt_arr_len(params), - .params_post = NULL, - .params_post_len = 0, .request_type = CURLOPT_HTTPGET, - .request_type_custom = NULL, - .args = NULL, .callback = mstdnt_statuses_json_callback, }; @@ -180,35 +169,32 @@ int mstdnt_timeline_direct(mastodont_t* data, } -int mstdnt_timeline_home(mastodont_t* data, - struct mstdnt_args* m_args, - mstdnt_request_cb_t cb_request, - void* cb_args, - struct mstdnt_timeline_args* args) +int +mstdnt_timeline_home(mastodont_t* data, + struct mstdnt_args* m_args, + mstdnt_request_cb_t cb_request, + void* cb_args, + struct mstdnt_timeline_args args) { struct _mstdnt_query_param params[] = { - { _MSTDNT_QUERY_BOOL, "local", { .b = args->local } }, - { _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } }, - { _MSTDNT_QUERY_INT, "only_media", { .i = args->only_media } }, - { _MSTDNT_QUERY_INT, "with_muted", { .i = args->with_muted } }, - /* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args->with_muted } }, */ - { _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args->reply_visibility) } }, - { _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } }, - { _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } }, - { _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } }, - { _MSTDNT_QUERY_INT, "limit", { .i = args->limit } }, - { _MSTDNT_QUERY_INT, "offset", { .i = args->offset } }, + { _MSTDNT_QUERY_BOOL, "local", { .b = args.local } }, + { _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } }, + { _MSTDNT_QUERY_INT, "only_media", { .i = args.only_media } }, + { _MSTDNT_QUERY_INT, "with_muted", { .i = args.with_muted } }, + /* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args.with_muted } }, */ + { _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args.reply_visibility) } }, + { _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } }, + { _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } }, + { _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } }, + { _MSTDNT_QUERY_INT, "limit", { .i = args.limit } }, + { _MSTDNT_QUERY_INT, "offset", { .i = args.offset } }, }; struct mstdnt_request_args req_args = { .url = "api/v1/timelines/home", .params_query = params, .params_query_len = _mstdnt_arr_len(params), - .params_post = NULL, - .params_post_len = 0, .request_type = CURLOPT_HTTPGET, - .request_type_custom = NULL, - .args = NULL, .callback = mstdnt_statuses_json_callback, };