diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 41 |
1 files changed, 35 insertions, 6 deletions
| @@ -2256,6 +2256,25 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 2256 | status = HTTP_STATUS_OK; | 2256 | status = HTTP_STATUS_OK; |
| 2257 | } | 2257 | } |
| 2258 | else | 2258 | else |
| 2259 | if (strcmp(cmd, "/v1/instance/peers") == 0) { /** **/ | ||
| 2260 | /* get the collected inbox list as the instances "this domain is aware of" */ | ||
| 2261 | xs *list = inbox_list(); | ||
| 2262 | xs *peers = xs_list_new(); | ||
| 2263 | const char *inbox; | ||
| 2264 | |||
| 2265 | xs_list_foreach(list, inbox) { | ||
| 2266 | xs *l = xs_split(inbox, "/"); | ||
| 2267 | const char *domain = xs_list_get(l, 2); | ||
| 2268 | |||
| 2269 | if (xs_is_string(domain)) | ||
| 2270 | peers = xs_list_append(peers, domain); | ||
| 2271 | } | ||
| 2272 | |||
| 2273 | *body = xs_json_dumps(peers, 4); | ||
| 2274 | *ctype = "application/json"; | ||
| 2275 | status = HTTP_STATUS_OK; | ||
| 2276 | } | ||
| 2277 | else | ||
| 2259 | if (xs_startswith(cmd, "/v1/statuses/")) { /** **/ | 2278 | if (xs_startswith(cmd, "/v1/statuses/")) { /** **/ |
| 2260 | /* information about a status */ | 2279 | /* information about a status */ |
| 2261 | if (logged_in) { | 2280 | if (logged_in) { |
| @@ -2707,14 +2726,24 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 2707 | msg = xs_dict_set(msg, "summary", summary); | 2726 | msg = xs_dict_set(msg, "summary", summary); |
| 2708 | } | 2727 | } |
| 2709 | 2728 | ||
| 2710 | /* store */ | 2729 | /* scheduled? */ |
| 2711 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | 2730 | const char *scheduled_at = xs_dict_get(args, "scheduled_at"); |
| 2712 | 2731 | ||
| 2713 | /* 'Create' message */ | 2732 | if (xs_is_string(scheduled_at) && *scheduled_at) { |
| 2714 | xs *c_msg = msg_create(&snac, msg); | 2733 | msg = xs_dict_set(msg, "published", scheduled_at); |
| 2715 | enqueue_message(&snac, c_msg); | ||
| 2716 | 2734 | ||
| 2717 | timeline_touch(&snac); | 2735 | schedule_add(&snac, xs_dict_get(msg, "id"), msg); |
| 2736 | } | ||
| 2737 | else { | ||
| 2738 | /* store */ | ||
| 2739 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 2740 | |||
| 2741 | /* 'Create' message */ | ||
| 2742 | xs *c_msg = msg_create(&snac, msg); | ||
| 2743 | enqueue_message(&snac, c_msg); | ||
| 2744 | |||
| 2745 | timeline_touch(&snac); | ||
| 2746 | } | ||
| 2718 | 2747 | ||
| 2719 | /* convert to a mastodon status as a response code */ | 2748 | /* convert to a mastodon status as a response code */ |
| 2720 | xs *st = mastoapi_status(&snac, msg); | 2749 | xs *st = mastoapi_status(&snac, msg); |