From c633d81f1071c65fc992589a1a12d1f667a1e6ee Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Fri, 18 Feb 2022 20:27:39 +0000 Subject: [PATCH] Try interact status FossilOrigin-Name: 93df0b275019b31e976f67ca127abf4c96f433cdf638a055fc75e4f7ef97da45 --- src/index.c | 1 + src/query.c | 1 + src/status.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/status.h | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/index.c b/src/index.c index 5c2cf4e..53caf75 100644 --- a/src/index.c +++ b/src/index.c @@ -50,6 +50,7 @@ void content_index(mastodont_t* api) } try_post_status(api); + try_interact_status(api); easprintf(&output, "%s %s", data_post_html, status_format); diff --git a/src/query.c b/src/query.c index ec229e5..d7aa022 100644 --- a/src/query.c +++ b/src/query.c @@ -63,6 +63,7 @@ char* try_handle_post(void (*call)(struct http_query_info*, void*), void* arg) } read(STDIN_FILENO, post_query, content_length); post_query[content_length] = '\0'; + // For parse_query to shift through, so we can still free the original p_query_read = post_query; diff --git a/src/status.c b/src/status.c index fa1099b..ea3b3ac 100644 --- a/src/status.c +++ b/src/status.c @@ -24,13 +24,53 @@ #include "cookie.h" #include "../static/status.chtml" +enum post_interact_type +{ + POST_INTERACT_NONE, + POST_INTERACT_LIKE, + POST_INTERACT_REBLOG +}; + +struct interact_args +{ + mastodont_t* api; + enum post_interact_type type; +}; + +static void status_interact(struct http_query_info* info, void* _arg) +{ + struct interact_args* arg = _arg; + + if (strcmp(info->key, "itype") == 0) + { + if (strcmp(info->val, "like") == 0) + { + arg->type = POST_INTERACT_LIKE; + } + } + else if (strcmp(info->key, "id") == 0) + { + struct mstdnt_storage storage; + switch (arg->type) + { + case POST_INTERACT_LIKE: + mastodont_favourite_status(arg->api, + info->val, + &storage); +// mastodont_storage_cleanup(&storage); + return; + default: + return; + } + } +} + static void status_post(struct http_query_info* info, void* arg) { mastodont_t* api = arg; if (strcmp(info->key, "content") == 0) { - struct http_cookie_info ck; struct mstdnt_storage storage; // Cookie copy and read @@ -61,6 +101,15 @@ int try_post_status(mastodont_t* api) return 0; } +int try_interact_status(mastodont_t* api) +{ + struct interact_args args; + args.api = api; + + char* post_query = try_handle_post(status_interact, &args); + return 0; +} + char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size) { char* stat_html, *result = NULL; diff --git a/src/status.h b/src/status.h index 9a12b21..7d93200 100644 --- a/src/status.h +++ b/src/status.h @@ -21,6 +21,7 @@ #include int try_post_status(mastodont_t* api); +int try_interact_status(mastodont_t* api); char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size); #endif // STATUS_H