Status interact api

FossilOrigin-Name: d0f0c287d9436739cba685f11178e9e48b373adde668fabf0b5be3c59653b982
This commit is contained in:
nekobit 2022-06-02 05:40:01 +00:00
parent f34889cde1
commit cebd17dad9
4 changed files with 27 additions and 16 deletions

View file

@ -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",

View file

@ -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)

View file

@ -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);
}

View file

@ -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);