From cebd17dad9894cf1587bcd06c0bd471df0037680 Mon Sep 17 00:00:00 2001 From: nekobit Date: Thu, 2 Jun 2022 05:40:01 +0000 Subject: [PATCH] Status interact api FossilOrigin-Name: d0f0c287d9436739cba685f11178e9e48b373adde668fabf0b5be3c59653b982 --- src/base_page.c | 2 +- src/main.c | 3 ++- src/notifications.c | 2 +- src/status.c | 36 +++++++++++++++++++++++------------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/base_page.c b/src/base_page.c index b525520..ac594f4 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -172,7 +172,7 @@ cleanup: void render_html(char* content_type, char* data, size_t data_len) { - if (data_len == 0) data_len = strlen(data_len); + if (data_len == 0) data_len = strlen(data); printf("Content-type: %s\r\n" "Content-Length: %d\r\n\r\n", content_type ? content_type : "text/html", diff --git a/src/main.c b/src/main.c index 5d87521..929ada5 100644 --- a/src/main.c +++ b/src/main.c @@ -95,7 +95,8 @@ int main(void) { "/notifications", content_notifications }, { "/tag/:", content_tl_tag }, // API - { "/treebird_api/v1/notifications", api_notifications } + { "/treebird_api/v1/notifications", api_notifications }, + { "/treebird_api/v1/interact", api_status_interact } }; while (FCGI_Accept() >= 0) diff --git a/src/notifications.c b/src/notifications.c index b3f2358..5d408fe 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -282,5 +282,5 @@ void content_notifications_compact(struct session* ssn, mastodont_t* api, char** void api_notifications(struct session* ssn, mastodont_t* api, char** data) { - render_html("application/json", "{\"error\":0}", 0); + render_html("application/json", "{\"status\":0}", 0); } diff --git a/src/status.c b/src/status.c index dea7c9d..c14798e 100644 --- a/src/status.c +++ b/src/status.c @@ -133,39 +133,39 @@ void content_status_react(struct session* ssn, mastodont_t* api, char** data) int try_interact_status(struct session* ssn, mastodont_t* api, char* id) { + int res = 0; struct mstdnt_storage storage = { 0 }; if (!(keystr(ssn->post.itype) && id)) return 1; // Pretty up the type if (strcmp(keystr(ssn->post.itype), "like") == 0 || strcmp(keystr(ssn->post.itype), "likeboost") == 0) - mastodont_favourite_status(api, id, &storage, NULL); + res = mastodont_favourite_status(api, id, &storage, NULL); // Not else if because possibly a like-boost if (strcmp(keystr(ssn->post.itype), "repeat") == 0 || strcmp(keystr(ssn->post.itype), "likeboost") == 0) - mastodont_reblog_status(api, id, &storage, NULL); + res = mastodont_reblog_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "bookmark") == 0) - mastodont_bookmark_status(api, id, &storage, NULL); + res = mastodont_bookmark_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "pin") == 0) - mastodont_pin_status(api, id, &storage, NULL); + res = mastodont_pin_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "mute") == 0) - mastodont_mute_conversation(api, id, &storage, NULL); + res = mastodont_mute_conversation(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "delete") == 0) - mastodont_delete_status(api, id, &storage, NULL); + res = mastodont_delete_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "unlike") == 0) - mastodont_unfavourite_status(api, id, &storage, NULL); + res = mastodont_unfavourite_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "unrepeat") == 0) - mastodont_unreblog_status(api, id, &storage, NULL); + res = mastodont_unreblog_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "unbookmark") == 0) - mastodont_unbookmark_status(api, id, &storage, NULL); + res = mastodont_unbookmark_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "unpin") == 0) - mastodont_unpin_status(api, id, &storage, NULL); + res = mastodont_unpin_status(api, id, &storage, NULL); else if (strcmp(keystr(ssn->post.itype), "unmute") == 0) - mastodont_unmute_conversation(api, id, &storage, NULL); + res = mastodont_unmute_conversation(api, id, &storage, NULL); mastodont_storage_cleanup(&storage); - - return 0; + return ret; } char* construct_status_interactions_label(char* header, int val, size_t* size) @@ -670,6 +670,16 @@ void status_interact(struct session* ssn, mastodont_t* api, char** data) data[0]); } +void api_status_interact(struct session* ssn, mastodont_t* api, char** data) +{ + if (try_interact_status(ssn, api, ssn->post.id)) + { + render_html("application/json", "{\"status\":\"Success\"}", 0); + } + else + render_html("application/json", "{\"status\":\"Couldn't load status\"}", 0); +} + void status_view(struct session* ssn, mastodont_t* api, char** data) { content_status(ssn, api, data, STATUS_FOCUSED);