From 074e19d9492733dba62f87d2b8f823440cb80288 Mon Sep 17 00:00:00 2001 From: grunfink Date: Sun, 31 Aug 2025 14:07:27 +0200 Subject: Added a 'replies' object to Notes. --- snac.h | 1 + 1 file changed, 1 insertion(+) (limited to 'snac.h') diff --git a/snac.h b/snac.h index 363855f..58ccd0b 100644 --- a/snac.h +++ b/snac.h @@ -360,6 +360,7 @@ xs_dict *msg_move(snac *user, const char *new_account); xs_dict *msg_accept(snac *snac, const xs_val *object, const char *to); xs_dict *msg_question(snac *user, const char *content, xs_list *attach, const xs_list *opts, int multiple, int end_secs); +xs_dict *msg_replies(snac *user, const char *id, int fill); int activitypub_request(snac *snac, const char *url, xs_dict **data); int actor_request(snac *user, const char *actor, xs_dict **data); -- cgit From d23fc31ba9c58e81d872d283ccdd1228865378b2 Mon Sep 17 00:00:00 2001 From: grunfink Date: Tue, 2 Sep 2025 10:01:49 +0200 Subject: Version 2.82 RELEASED. --- snac.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'snac.h') diff --git a/snac.h b/snac.h index 58ccd0b..403bba0 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2025 grunfink et al. / MIT license */ -#define VERSION "2.82-dev" +#define VERSION "2.82" #define USER_AGENT "snac/" VERSION -- cgit From 59f3b5465ecca02cb90310fd1dbc46456d6a4908 Mon Sep 17 00:00:00 2001 From: grunfink Date: Wed, 3 Sep 2025 06:08:13 +0200 Subject: New function collect_outbox(). --- activitypub.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 5 +++ snac.h | 1 + 3 files changed, 107 insertions(+) (limited to 'snac.h') diff --git a/activitypub.c b/activitypub.c index 09da229..b9ef86b 100644 --- a/activitypub.c +++ b/activitypub.c @@ -1021,6 +1021,107 @@ void collect_replies(snac *user, const char *id) } +void collect_outbox(snac *user, const char *actor_id) +/* gets an actor's outbox and inserts a bunch of posts in a user's timeline */ +{ + int status; + xs *actor = NULL; + + if (!valid_status(status = actor_request(user, actor_id, &actor))) { + snac_debug(user, 1, xs_fmt("collect_outbox: cannot get actor object '%s' %d", actor_id, status)); + return; + } + + xs *outbox = NULL; + const char *outbox_url = xs_dict_get(actor, "outbox"); + + if (!xs_is_string(outbox_url)) + return; + + if (!valid_status(status = activitypub_request(user, outbox_url, &outbox))) { + snac_debug(user, 1, xs_fmt("collect_outbox: cannot get actor outbox '%s' %d", outbox_url, status)); + return; + } + + const xs_list *ordered_items = xs_dict_get(outbox, "orderedItems"); + + if (!xs_is_list(ordered_items)) { + /* the list is not here; does it have a 'first'? */ + const char *first = xs_dict_get(outbox, "first"); + + if (xs_is_string(first)) { + /* download this instead */ + xs *first2 = xs_dup(first); + xs_free(outbox); + + if (!valid_status(status = activitypub_request(user, first2, &outbox))) { + snac_debug(user, 1, xs_fmt("collect_outbox: cannot get first page of outbox '%s' %d", first2, status)); + return; + } + + /* last chance */ + ordered_items = xs_dict_get(outbox, "orderedItems"); + } + } + + if (!xs_is_list(ordered_items)) { + snac_debug(user, 1, xs_fmt("collect_outbox: cannot get list of posts for actor '%s' outbox", actor_id)); + return; + } + + /* well, ok, then */ + int max = 4; + const xs_val *v; + + xs_list_foreach(ordered_items, v) { + if (max == 0) + break; + + xs *post = NULL; + + if (xs_is_string(v)) { + /* it's probably the post url */ + if (!valid_status(activitypub_request(user, v, &post))) + continue; + } + else + if (xs_is_dict(v)) + post = xs_dup(v); + + if (post == NULL) + continue; + + const char *type = xs_dict_get(post, "type"); + + if (!xs_is_string(type) || strcmp(type, "Create")) { + /* not a post */ + continue; + } + + const xs_dict *object = xs_dict_get(post, "object"); + + if (!xs_is_dict(object)) + continue; + + type = xs_dict_get(object, "type"); + const char *id = xs_dict_get(object, "id"); + const char *attr_to = get_atto(object); + + if (!xs_is_string(type) || !xs_is_string(id) || !xs_is_string(attr_to)) + continue; + + if (!timeline_here(user, id)) { + timeline_add(user, id, object); + snac_log(user, xs_fmt("new '%s' (collect_outbox) %s %s", type, attr_to, id)); + } + else + snac_debug(user, 1, xs_fmt("collect_outbox: post '%s' already here", id)); + + max--; + } +} + + void notify(snac *snac, const char *type, const char *utype, const char *actor, const xs_dict *msg) /* notifies the user of relevant events */ { diff --git a/main.c b/main.c index e01b6a2..474d684 100644 --- a/main.c +++ b/main.c @@ -738,6 +738,11 @@ int main(int argc, char *argv[]) return 0; } + if (strcmp(cmd, "collect_outbox") == 0) { /** **/ + collect_outbox(&snac, url); + return 0; + } + if (strcmp(cmd, "insert") == 0) { /** **/ int status; xs *data = NULL; diff --git a/snac.h b/snac.h index 403bba0..1366d04 100644 --- a/snac.h +++ b/snac.h @@ -336,6 +336,7 @@ const char *default_avatar_base64(void); xs_str *process_tags(snac *snac, const char *content, xs_list **tag); void collect_replies(snac *user, const char *id); +void collect_outbox(snac *user, const char *actor_id); const char *get_atto(const xs_dict *msg); const char *get_in_reply_to(const xs_dict *msg); -- cgit From d40e47f70964ad7e41fc06a8aa281db30a24050b Mon Sep 17 00:00:00 2001 From: grunfink Date: Wed, 3 Sep 2025 06:12:50 +0200 Subject: New function enqueue_collect_outbox(). --- activitypub.c | 6 ++++++ data.c | 13 +++++++++++++ main.c | 2 +- snac.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) (limited to 'snac.h') diff --git a/activitypub.c b/activitypub.c index b9ef86b..c186095 100644 --- a/activitypub.c +++ b/activitypub.c @@ -3079,6 +3079,12 @@ void process_user_queue_item(snac *user, xs_dict *q_item) collect_replies(user, post); } + else + if (strcmp(type, "collect_outbox") == 0) { + const char *actor_id = xs_dict_get(q_item, "message"); + + collect_outbox(user, actor_id); + } else snac_log(user, xs_fmt("unexpected user q_item type '%s'", type)); } diff --git a/data.c b/data.c index ca5e3ed..0ea74b7 100644 --- a/data.c +++ b/data.c @@ -3589,6 +3589,19 @@ void enqueue_collect_replies(snac *user, const char *post) } +void enqueue_collect_outbox(snac *user, const char *actor_id) +/* enqueues a collect outbox request */ +{ + xs *qmsg = _new_qmsg("collect_outbox", actor_id, 0); + const char *ntid = xs_dict_get(qmsg, "ntid"); + xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid); + + qmsg = _enqueue_put(fn, qmsg); + + snac_debug(user, 1, xs_fmt("enqueue_collect_outbox %s", actor_id)); +} + + int was_question_voted(snac *user, const char *id) /* returns true if the user voted in this poll */ { diff --git a/main.c b/main.c index 474d684..6abac61 100644 --- a/main.c +++ b/main.c @@ -739,7 +739,7 @@ int main(int argc, char *argv[]) } if (strcmp(cmd, "collect_outbox") == 0) { /** **/ - collect_outbox(&snac, url); + enqueue_collect_outbox(&snac, url); return 0; } diff --git a/snac.h b/snac.h index 1366d04..5cbfcae 100644 --- a/snac.h +++ b/snac.h @@ -298,6 +298,7 @@ void enqueue_actor_refresh(snac *user, const char *actor, int forward_secs); void enqueue_webmention(const xs_dict *msg); void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries); void enqueue_collect_replies(snac *user, const char *post); +void enqueue_collect_outbox(snac *user, const char *actor_id); int was_question_voted(snac *user, const char *id); -- cgit From 4661d7f5bc076be896c7192bb63a7c7d726993da Mon Sep 17 00:00:00 2001 From: grunfink Date: Wed, 3 Sep 2025 06:38:07 +0200 Subject: Renamed function list_content() to list_members(). --- data.c | 6 +++--- main.c | 6 +++--- mastoapi.c | 8 ++++---- snac.h | 2 +- utils.c | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'snac.h') diff --git a/data.c b/data.c index 0ea74b7..7e90a06 100644 --- a/data.c +++ b/data.c @@ -2429,8 +2429,8 @@ xs_list *list_timeline(snac *user, const char *list, int skip, int show) } -xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op) -/* list content management */ +xs_val *list_members(snac *user, const char *list, const char *actor_md5, int op) +/* list member management */ { xs_val *l = NULL; @@ -2443,7 +2443,7 @@ xs_val *list_content(snac *user, const char *list, const char *actor_md5, int op xs *fn = xs_fmt("%s/list/%s.lst", user->basedir, list); switch (op) { - case 0: /** list content **/ + case 0: /** list members **/ l = index_list(fn, XS_ALL); break; diff --git a/main.c b/main.c index 6abac61..882da33 100644 --- a/main.c +++ b/main.c @@ -354,7 +354,7 @@ int main(int argc, char *argv[]) xs *lid = list_maint(&snac, url, 4); if (lid != NULL) { - xs *lcont = list_content(&snac, lid, NULL, 0); + xs *lcont = list_members(&snac, lid, NULL, 0); const char *md5; xs_list_foreach(lcont, md5) { @@ -410,7 +410,7 @@ int main(int argc, char *argv[]) if (valid_status(webfinger_request(account, &actor, &uid))) { xs *md5 = xs_md5_hex(actor, strlen(actor)); - list_content(&snac, lid, md5, 1); + list_members(&snac, lid, md5, 1); printf("Actor %s (%s) added to list '%s' (%s)\n", actor, uid, url, lid); } else @@ -433,7 +433,7 @@ int main(int argc, char *argv[]) if (lid != NULL) { xs *md5 = xs_md5_hex(account, strlen(account)); - list_content(&snac, lid, md5, 2); + list_members(&snac, lid, md5, 2); printf("Actor %s deleted from list '%s' (%s)\n", account, url, lid); } else diff --git a/mastoapi.c b/mastoapi.c index 42f3a47..568426b 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -1560,7 +1560,7 @@ xs_list *mastoapi_account_lists(snac *user, const char *uid) const char *list_id = xs_list_get(li, 0); const char *list_title = xs_list_get(li, 1); if (uid) { - xs *users = list_content(user, list_id, NULL, 0); + xs *users = list_members(user, list_id, NULL, 0); if (xs_list_in(users, actor_md5) == -1) continue; } @@ -2087,7 +2087,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, p = xs_list_get(l, -2); if (p && xs_is_hex(p)) { - xs *actors = list_content(&snac1, p, NULL, 0); + xs *actors = list_members(&snac1, p, NULL, 0); xs *out = xs_list_new(); int c = 0; const char *v; @@ -3297,7 +3297,7 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, const char *v; while (xs_list_next(accts, &v, &c)) { - list_content(&snac, id, v, 1); + list_members(&snac, id, v, 1); } xs *out = xs_dict_new(); @@ -3507,7 +3507,7 @@ int mastoapi_delete_handler(const xs_dict *req, const char *q_path, const char *v; while (xs_list_next(accts, &v, &c)) { - list_content(&snac, p, v, 2); + list_members(&snac, p, v, 2); } } else { diff --git a/snac.h b/snac.h index 5cbfcae..a871576 100644 --- a/snac.h +++ b/snac.h @@ -233,7 +233,7 @@ xs_list *tag_search(const char *tag, int skip, int show); xs_val *list_maint(snac *user, const char *list, int op); xs_str *list_timeline_fn(snac *user, const char *list); xs_list *list_timeline(snac *user, const char *list, int skip, int show); -xs_val *list_content(snac *user, const char *list_id, const char *actor_md5, int op); +xs_val *list_members(snac *user, const char *list_id, const char *actor_md5, int op); void list_distribute(snac *user, const char *who, const xs_dict *post); int actor_add(const char *actor, const xs_dict *msg); diff --git a/utils.c b/utils.c index 8db20bd..9a60879 100644 --- a/utils.c +++ b/utils.c @@ -681,7 +681,7 @@ void export_csv(snac *user) const char *lid = xs_list_get(li, 0); const char *ltitle = xs_list_get(li, 1); - xs *actors = list_content(user, lid, NULL, 0); + xs *actors = list_members(user, lid, NULL, 0); const char *md5; xs_list_foreach(actors, md5) { @@ -907,7 +907,7 @@ void import_list_csv(snac *user, const char *ifn) if (valid_status(webfinger_request(acct, &url, &uid))) { xs *actor_md5 = xs_md5_hex(url, strlen(url)); - list_content(user, list_id, actor_md5, 1); + list_members(user, list_id, actor_md5, 1); snac_log(user, xs_fmt("Added %s to list %s", url, lname)); if (!following_check(user, url)) { -- cgit