summaryrefslogtreecommitdiff
path: root/mastoapi.c
diff options
context:
space:
mode:
authorGravatar grunfink2025-05-18 09:11:40 +0200
committerGravatar grunfink2025-05-18 09:11:40 +0200
commit31b0f750a8af530ac61a38938e453740996ba9d5 (patch)
tree46ce795a8b81a0feed83c493e06be9b9161f8aee /mastoapi.c
parentmastoapi: added endpoint /v1/follow_requests. (diff)
downloadsnac2-31b0f750a8af530ac61a38938e453740996ba9d5.tar.gz
snac2-31b0f750a8af530ac61a38938e453740996ba9d5.tar.xz
snac2-31b0f750a8af530ac61a38938e453740996ba9d5.zip
mastoapi: added post endpoints for 'authorize' and 'reject' follow requests.
Diffstat (limited to 'mastoapi.c')
-rw-r--r--mastoapi.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/mastoapi.c b/mastoapi.c
index c216a0b..7fa0078 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -3245,6 +3245,57 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
3245 status = HTTP_STATUS_OK; 3245 status = HTTP_STATUS_OK;
3246 } 3246 }
3247 else 3247 else
3248 if (xs_startswith(cmd, "/v1/follow_requests")) { /** **/
3249 if (logged_in) {
3250 /* "authorize" or "reject" */
3251 xs *rel = NULL;
3252 xs *l = xs_split(cmd, "/");
3253 const char *md5 = xs_list_get(l, -2);
3254 const char *s_cmd = xs_list_get(l, -1);
3255
3256 if (xs_is_string(md5) && xs_is_string(s_cmd)) {
3257 xs *actor = NULL;
3258
3259 if (valid_status(object_get_by_md5(md5, &actor))) {
3260 const char *actor_id = xs_dict_get(actor, "id");
3261
3262 if (strcmp(s_cmd, "authorize") == 0) {
3263 xs *fwreq = pending_get(&snac, actor_id);
3264
3265 if (fwreq != NULL) {
3266 xs *reply = msg_accept(&snac, fwreq, actor_id);
3267
3268 enqueue_message(&snac, reply);
3269
3270 if (xs_is_null(xs_dict_get(fwreq, "published"))) {
3271 xs *date = xs_str_utctime(0, ISO_DATE_SPEC);
3272 fwreq = xs_dict_set(fwreq, "published", date);
3273 }
3274
3275 timeline_add(&snac, xs_dict_get(fwreq, "id"), fwreq);
3276
3277 follower_add(&snac, actor_id);
3278
3279 pending_del(&snac, actor_id);
3280 rel = mastoapi_relationship(&snac, md5);
3281 }
3282 }
3283 else
3284 if (strcmp(s_cmd, "reject") == 0) {
3285 pending_del(&snac, actor_id);
3286 rel = mastoapi_relationship(&snac, md5);
3287 }
3288 }
3289 }
3290
3291 if (rel != NULL) {
3292 *body = xs_json_dumps(rel, 4);
3293 *ctype = "application/json";
3294 status = HTTP_STATUS_OK;
3295 }
3296 }
3297 }
3298 else
3248 status = HTTP_STATUS_UNPROCESSABLE_CONTENT; 3299 status = HTTP_STATUS_UNPROCESSABLE_CONTENT;
3249 3300
3250 /* user cleanup */ 3301 /* user cleanup */