aboutsummaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorgrunfink <grunfink@comam.es>2025-08-31 14:07:27 +0200
committergrunfink <grunfink@comam.es>2025-08-31 14:07:27 +0200
commit074e19d9492733dba62f87d2b8f823440cb80288 (patch)
tree7eb652ceb8de834666571a1f515c44c7fa32d328 /activitypub.c
parent5cda2f709c03222f02f088f3b9047b5ca7aba42a (diff)
Added a 'replies' object to Notes.
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c76
1 files changed, 76 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)
}
+xs_dict *msg_replies(snac *user, const char *id, int fill)
+/* creates a CollectionPage with replies of id */
+{
+ xs *r_id = xs_replace(id, "/p/", "/r/");
+ xs *r_idp = xs_fmt("%s#page", r_id);
+ xs *r_idh = xs_fmt("%s#hdr", r_id);
+
+ xs_dict *msg = msg_base(user, "CollectionPage", r_idp, NULL, NULL, NULL);
+
+ msg = xs_dict_set(msg, "partOf", r_idh);
+
+ xs *items = xs_list_new();
+ if (fill) {
+ xs *children = object_children(id);
+ const char *md5;
+
+ xs_list_foreach(children, md5) {
+ xs *obj = NULL;
+
+ if (valid_status(object_get_by_md5(md5, &obj)) && is_msg_public(obj)) {
+ const char *c_id = xs_dict_get(obj, "id");
+
+ if (xs_is_string(c_id))
+ items = xs_list_append(items, c_id);
+ }
+ }
+ }
+ else {
+ xs *r_idl = xs_fmt("%s#local", r_id);
+
+ msg = xs_dict_del(msg, "@context");
+ msg = xs_dict_set(msg, "id", r_idl);
+ }
+
+ msg = xs_dict_set(msg, "items", items);
+
+ return msg;
+}
+
+
xs_dict *msg_accept(snac *snac, const xs_val *object, const char *to)
/* creates an Accept message (as a response to a Follow) */
{
@@ -1868,6 +1908,22 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
}
}
+ if (!priv) {
+ /* create the replies object */
+ xs *replies = xs_dict_new();
+ xs *r_id = xs_replace(id, "/p/", "/r/");
+ xs *h_id = xs_fmt("%s#hdr", r_id);
+ xs *n_id = xs_fmt("%s#page", r_id);
+ xs *rp = msg_replies(snac, id, 0);
+
+ replies = xs_dict_set(replies, "id", h_id);
+ replies = xs_dict_set(replies, "type", "Collection");
+ replies = xs_dict_set(replies, "next", n_id);
+ replies = xs_dict_set(replies, "first", rp);
+
+ msg = xs_dict_set(msg, "replies", replies);
+ }
+
return msg;
}
@@ -3396,6 +3452,26 @@ int activitypub_get_handler(const xs_dict *req, const char *q_path,
status = HTTP_STATUS_NOT_FOUND;
}
else
+ if (xs_startswith(p_path, "r/")) {
+ /* replies to a post */
+ xs *s = xs_dup(p_path);
+ s[0] = 'p';
+
+ xs *id = xs_fmt("%s/%s", snac.actor, s);
+
+ xs *obj = NULL;
+ status = object_get(id, &obj);
+
+ /* don't return non-public objects */
+ if (!valid_status(status))
+ status = HTTP_STATUS_NOT_FOUND;
+ else
+ if (!is_msg_public(obj))
+ status = HTTP_STATUS_NOT_FOUND;
+ else
+ msg = msg_replies(&snac, id, 1);
+ }
+ else
status = HTTP_STATUS_NOT_FOUND;
if (status == HTTP_STATUS_OK && msg != NULL) {