Hashtag stuff, fix history
FossilOrigin-Name: 508e6165907ca50a344fe543c3b466f5d1d7a5ba0424d70831694d410050e78e
This commit is contained in:
parent
dc54088dec
commit
d0149fa7b7
6 changed files with 82 additions and 4 deletions
|
@ -38,6 +38,8 @@ int _mstdnt_json_init(cJSON** root,
|
|||
int _mstdnt_key_val_ref(cJSON* v, struct _mstdnt_val_ref* refs,
|
||||
size_t refs_len);
|
||||
|
||||
void _mstdnt_val_string_int_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_string_uint_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_string_unix_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_string_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_bool_call(cJSON* v, void* _type);
|
||||
|
|
|
@ -56,5 +56,11 @@ int mastodont_timeline_direct(mastodont_t* data,
|
|||
struct mstdnt_status* statuses[],
|
||||
size_t* statuses_size);
|
||||
|
||||
int mastodont_timeline_tag(mastodont_t* data,
|
||||
char* hashtag,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size);
|
||||
|
||||
#endif /* MASTODONT_TIMELINE_H */
|
||||
|
|
|
@ -24,8 +24,8 @@ int mstdnt_history_json(struct mstdnt_history* hist, cJSON* js)
|
|||
|
||||
struct _mstdnt_val_ref refs[] = {
|
||||
{ "day", &(hist->day), _mstdnt_val_string_unix_call },
|
||||
{ "uses", &(hist->uses), _mstdnt_val_uint_call },
|
||||
{ "accounts", &(hist->accounts), _mstdnt_val_uint_call },
|
||||
{ "uses", &(hist->uses), _mstdnt_val_string_uint_call },
|
||||
{ "accounts", &(hist->accounts), _mstdnt_val_string_uint_call },
|
||||
};
|
||||
|
||||
for (cJSON* v = js; v; v = v->next)
|
||||
|
|
|
@ -61,7 +61,41 @@ void _mstdnt_val_string_unix_call(cJSON* v, void* _type)
|
|||
|
||||
// Convert string to long
|
||||
conv = strtol(v->valuestring, &endptr, 10);
|
||||
*type = v->valuestring != *endptr ? conv : 0;
|
||||
*type = v->valuestring != endptr ? conv : 0;
|
||||
}
|
||||
|
||||
// Fuck you Gargron
|
||||
void _mstdnt_val_string_uint_call(cJSON* v, void* _type)
|
||||
{
|
||||
long conv;
|
||||
unsigned* type = _type;
|
||||
char* endptr;
|
||||
if (!cJSON_IsString(v))
|
||||
{
|
||||
*type = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert string to long
|
||||
conv = strtol(v->valuestring, &endptr, 10);
|
||||
*type = v->valuestring != endptr ? conv : 0;
|
||||
}
|
||||
|
||||
// Again, fuck you Gargron
|
||||
void _mstdnt_val_string_int_call(cJSON* v, void* _type)
|
||||
{
|
||||
long conv;
|
||||
int* type = _type;
|
||||
char* endptr;
|
||||
if (!cJSON_IsString(v))
|
||||
{
|
||||
*type = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert string to long
|
||||
conv = strtol(v->valuestring, &endptr, 10);
|
||||
*type = v->valuestring != endptr ? conv : 0;
|
||||
}
|
||||
|
||||
void _mstdnt_val_string_call(cJSON* v, void* _type)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
int mstdnt_tag_json(struct mstdnt_tag* tag, cJSON* js)
|
||||
{
|
||||
struct _mstdnt_generic_args history_args = {
|
||||
.arg = tag->history,
|
||||
.arg = &(tag->history),
|
||||
.size = &(tag->history_len)
|
||||
};
|
||||
|
||||
|
|
|
@ -51,6 +51,42 @@ int mastodont_timeline_list(mastodont_t* data,
|
|||
return mastodont_request(data, &req_args);
|
||||
}
|
||||
|
||||
int mastodont_timeline_tag(mastodont_t* data,
|
||||
char* hashtag,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
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_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "local", { .i = args->local } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "remote", { .i = args->remote } },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", { .i = args->remote } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args->remote } },
|
||||
};
|
||||
|
||||
struct mastodont_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
&cb_args,
|
||||
_mstdnt_statuses_result_callback,
|
||||
};
|
||||
|
||||
return mastodont_request(data, &req_args);
|
||||
}
|
||||
|
||||
int mastodont_timeline_public(mastodont_t* data,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
|
|
Loading…
Reference in a new issue