diff options
| -rw-r--r-- | activitypub.c | 76 | ||||
| -rw-r--r-- | snac.h | 1 |
2 files changed, 77 insertions, 0 deletions
diff --git a/activitypub.c b/activitypub.c index 34137da..31a9cb3 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -1264,6 +1264,46 @@ xs_dict *msg_collection(snac *snac, const char *id, int items) | |||
| 1264 | } | 1264 | } |
| 1265 | 1265 | ||
| 1266 | 1266 | ||
| 1267 | xs_dict *msg_replies(snac *user, const char *id, int fill) | ||
| 1268 | /* creates a CollectionPage with replies of id */ | ||
| 1269 | { | ||
| 1270 | xs *r_id = xs_replace(id, "/p/", "/r/"); | ||
| 1271 | xs *r_idp = xs_fmt("%s#page", r_id); | ||
| 1272 | xs *r_idh = xs_fmt("%s#hdr", r_id); | ||
| 1273 | |||
| 1274 | xs_dict *msg = msg_base(user, "CollectionPage", r_idp, NULL, NULL, NULL); | ||
| 1275 | |||
| 1276 | msg = xs_dict_set(msg, "partOf", r_idh); | ||
| 1277 | |||
| 1278 | xs *items = xs_list_new(); | ||
| 1279 | if (fill) { | ||
| 1280 | xs *children = object_children(id); | ||
| 1281 | const char *md5; | ||
| 1282 | |||
| 1283 | xs_list_foreach(children, md5) { | ||
| 1284 | xs *obj = NULL; | ||
| 1285 | |||
| 1286 | if (valid_status(object_get_by_md5(md5, &obj)) && is_msg_public(obj)) { | ||
| 1287 | const char *c_id = xs_dict_get(obj, "id"); | ||
| 1288 | |||
| 1289 | if (xs_is_string(c_id)) | ||
| 1290 | items = xs_list_append(items, c_id); | ||
| 1291 | } | ||
| 1292 | } | ||
| 1293 | } | ||
| 1294 | else { | ||
| 1295 | xs *r_idl = xs_fmt("%s#local", r_id); | ||
| 1296 | |||
| 1297 | msg = xs_dict_del(msg, "@context"); | ||
| 1298 | msg = xs_dict_set(msg, "id", r_idl); | ||
| 1299 | } | ||
| 1300 | |||
| 1301 | msg = xs_dict_set(msg, "items", items); | ||
| 1302 | |||
| 1303 | return msg; | ||
| 1304 | } | ||
| 1305 | |||
| 1306 | |||
| 1267 | xs_dict *msg_accept(snac *snac, const xs_val *object, const char *to) | 1307 | xs_dict *msg_accept(snac *snac, const xs_val *object, const char *to) |
| 1268 | /* creates an Accept message (as a response to a Follow) */ | 1308 | /* creates an Accept message (as a response to a Follow) */ |
| 1269 | { | 1309 | { |
| @@ -1868,6 +1908,22 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | |||
| 1868 | } | 1908 | } |
| 1869 | } | 1909 | } |
| 1870 | 1910 | ||
| 1911 | if (!priv) { | ||
| 1912 | /* create the replies object */ | ||
| 1913 | xs *replies = xs_dict_new(); | ||
| 1914 | xs *r_id = xs_replace(id, "/p/", "/r/"); | ||
| 1915 | xs *h_id = xs_fmt("%s#hdr", r_id); | ||
| 1916 | xs *n_id = xs_fmt("%s#page", r_id); | ||
| 1917 | xs *rp = msg_replies(snac, id, 0); | ||
| 1918 | |||
| 1919 | replies = xs_dict_set(replies, "id", h_id); | ||
| 1920 | replies = xs_dict_set(replies, "type", "Collection"); | ||
| 1921 | replies = xs_dict_set(replies, "next", n_id); | ||
| 1922 | replies = xs_dict_set(replies, "first", rp); | ||
| 1923 | |||
| 1924 | msg = xs_dict_set(msg, "replies", replies); | ||
| 1925 | } | ||
| 1926 | |||
| 1871 | return msg; | 1927 | return msg; |
| 1872 | } | 1928 | } |
| 1873 | 1929 | ||
| @@ -3396,6 +3452,26 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path, | |||
| 3396 | status = HTTP_STATUS_NOT_FOUND; | 3452 | status = HTTP_STATUS_NOT_FOUND; |
| 3397 | } | 3453 | } |
| 3398 | else | 3454 | else |
| 3455 | if (xs_startswith(p_path, "r/")) { | ||
| 3456 | /* replies to a post */ | ||
| 3457 | xs *s = xs_dup(p_path); | ||
| 3458 | s[0] = 'p'; | ||
| 3459 | |||
| 3460 | xs *id = xs_fmt("%s/%s", snac.actor, s); | ||
| 3461 | |||
| 3462 | xs *obj = NULL; | ||
| 3463 | status = object_get(id, &obj); | ||
| 3464 | |||
| 3465 | /* don't return non-public objects */ | ||
| 3466 | if (!valid_status(status)) | ||
| 3467 | status = HTTP_STATUS_NOT_FOUND; | ||
| 3468 | else | ||
| 3469 | if (!is_msg_public(obj)) | ||
| 3470 | status = HTTP_STATUS_NOT_FOUND; | ||
| 3471 | else | ||
| 3472 | msg = msg_replies(&snac, id, 1); | ||
| 3473 | } | ||
| 3474 | else | ||
| 3399 | status = HTTP_STATUS_NOT_FOUND; | 3475 | status = HTTP_STATUS_NOT_FOUND; |
| 3400 | 3476 | ||
| 3401 | if (status == HTTP_STATUS_OK && msg != NULL) { | 3477 | if (status == HTTP_STATUS_OK && msg != NULL) { |
| @@ -360,6 +360,7 @@ xs_dict *msg_move(snac *user, const char *new_account); | |||
| 360 | xs_dict *msg_accept(snac *snac, const xs_val *object, const char *to); | 360 | xs_dict *msg_accept(snac *snac, const xs_val *object, const char *to); |
| 361 | xs_dict *msg_question(snac *user, const char *content, xs_list *attach, | 361 | xs_dict *msg_question(snac *user, const char *content, xs_list *attach, |
| 362 | const xs_list *opts, int multiple, int end_secs); | 362 | const xs_list *opts, int multiple, int end_secs); |
| 363 | xs_dict *msg_replies(snac *user, const char *id, int fill); | ||
| 363 | 364 | ||
| 364 | int activitypub_request(snac *snac, const char *url, xs_dict **data); | 365 | int activitypub_request(snac *snac, const char *url, xs_dict **data); |
| 365 | int actor_request(snac *user, const char *actor, xs_dict **data); | 366 | int actor_request(snac *user, const char *actor, xs_dict **data); |