From 20573275ec8f7cc7f5744a3280590040a6f14203 Mon Sep 17 00:00:00 2001 From: default Date: Sat, 22 Mar 2025 08:32:59 +0100 Subject: mastoapi: Added support for /api/v1/instance/peers. --- mastoapi.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 8d61681..14dd251 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2256,6 +2256,15 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, status = HTTP_STATUS_OK; } else + if (strcmp(cmd, "/v1/instance/peers") == 0) { /** **/ + /* get the collected inbox list as the instances "this domain is aware of" */ + xs *list = inbox_list(); + + *body = xs_json_dumps(list, 4); + *ctype = "application/json"; + status = HTTP_STATUS_OK; + } + else if (xs_startswith(cmd, "/v1/statuses/")) { /** **/ /* information about a status */ if (logged_in) { -- cgit v1.2.3 From 0b4e8cac069d31de736137de08543ace912b728a Mon Sep 17 00:00:00 2001 From: default Date: Sat, 22 Mar 2025 08:39:04 +0100 Subject: mastoapi: fixed instance peers to return only the domains. --- mastoapi.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 14dd251..7b1e0ad 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2259,8 +2259,18 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (strcmp(cmd, "/v1/instance/peers") == 0) { /** **/ /* get the collected inbox list as the instances "this domain is aware of" */ xs *list = inbox_list(); + xs *peers = xs_list_new(); + const char *inbox; - *body = xs_json_dumps(list, 4); + xs_list_foreach(list, inbox) { + xs *l = xs_split(inbox, "/"); + const char *domain = xs_list_get(l, 2); + + if (xs_is_string(domain)) + peers = xs_list_append(peers, domain); + } + + *body = xs_json_dumps(peers, 4); *ctype = "application/json"; status = HTTP_STATUS_OK; } -- cgit v1.2.3 From 877434218ffca350eb918fd47dfe81f29f2605ae Mon Sep 17 00:00:00 2001 From: default Date: Wed, 2 Apr 2025 09:01:31 +0200 Subject: mastoapi: added support for scheduled posts. --- mastoapi.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 7b1e0ad..d93afc5 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -2726,14 +2726,24 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, msg = xs_dict_set(msg, "summary", summary); } - /* store */ - timeline_add(&snac, xs_dict_get(msg, "id"), msg); + /* scheduled? */ + const char *scheduled_at = xs_dict_get(args, "scheduled_at"); - /* 'Create' message */ - xs *c_msg = msg_create(&snac, msg); - enqueue_message(&snac, c_msg); + if (xs_is_string(scheduled_at) && *scheduled_at) { + msg = xs_dict_set(msg, "published", scheduled_at); - timeline_touch(&snac); + schedule_add(&snac, xs_dict_get(msg, "id"), msg); + } + else { + /* store */ + timeline_add(&snac, xs_dict_get(msg, "id"), msg); + + /* 'Create' message */ + xs *c_msg = msg_create(&snac, msg); + enqueue_message(&snac, c_msg); + + timeline_touch(&snac); + } /* convert to a mastodon status as a response code */ xs *st = mastoapi_status(&snac, msg); -- cgit v1.2.3