summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2025-01-19 18:20:27 +0100
committerGravatar default2025-01-19 18:20:27 +0100
commit4127ec4100ee6f87f42afacba185486ade670966 (patch)
tree000ea21771d9de62728462e18b9d978fa4dffcb1 /activitypub.c
parentUpdated documentation. (diff)
downloadsnac2-4127ec4100ee6f87f42afacba185486ade670966.tar.gz
snac2-4127ec4100ee6f87f42afacba185486ade670966.tar.xz
snac2-4127ec4100ee6f87f42afacba185486ade670966.zip
Also relay notes to the relays that follow us.
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c58
1 files changed, 41 insertions, 17 deletions
diff --git a/activitypub.c b/activitypub.c
index f0d9336..18b3c86 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -2485,7 +2485,7 @@ int send_email(const char *msg)
2485} 2485}
2486 2486
2487 2487
2488void process_user_queue_item(snac *snac, xs_dict *q_item) 2488void process_user_queue_item(snac *user, xs_dict *q_item)
2489/* processes an item from the user queue */ 2489/* processes an item from the user queue */
2490{ 2490{
2491 const char *type; 2491 const char *type;
@@ -2496,7 +2496,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2496 2496
2497 if (strcmp(type, "message") == 0) { 2497 if (strcmp(type, "message") == 0) {
2498 const xs_dict *msg = xs_dict_get(q_item, "message"); 2498 const xs_dict *msg = xs_dict_get(q_item, "message");
2499 xs *rcpts = recipient_list(snac, msg, 1); 2499 xs *rcpts = recipient_list(user, msg, 1);
2500 xs_set inboxes; 2500 xs_set inboxes;
2501 const xs_str *actor; 2501 const xs_str *actor;
2502 2502
@@ -2505,7 +2505,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2505 /* add this shared inbox first */ 2505 /* add this shared inbox first */
2506 xs *this_shared_inbox = xs_fmt("%s/shared-inbox", srv_baseurl); 2506 xs *this_shared_inbox = xs_fmt("%s/shared-inbox", srv_baseurl);
2507 xs_set_add(&inboxes, this_shared_inbox); 2507 xs_set_add(&inboxes, this_shared_inbox);
2508 enqueue_output(snac, msg, this_shared_inbox, 0, 0); 2508 enqueue_output(user, msg, this_shared_inbox, 0, 0);
2509 2509
2510 /* iterate the recipients */ 2510 /* iterate the recipients */
2511 xs_list_foreach(rcpts, actor) { 2511 xs_list_foreach(rcpts, actor) {
@@ -2516,10 +2516,10 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2516 if (inbox != NULL) { 2516 if (inbox != NULL) {
2517 /* add to the set and, if it's not there, send message */ 2517 /* add to the set and, if it's not there, send message */
2518 if (xs_set_add(&inboxes, inbox) == 1) 2518 if (xs_set_add(&inboxes, inbox) == 1)
2519 enqueue_output(snac, msg, inbox, 0, 0); 2519 enqueue_output(user, msg, inbox, 0, 0);
2520 } 2520 }
2521 else 2521 else
2522 snac_log(snac, xs_fmt("cannot find inbox for %s", actor)); 2522 snac_log(user, xs_fmt("cannot find inbox for %s", actor));
2523 } 2523 }
2524 } 2524 }
2525 2525
@@ -2531,12 +2531,36 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2531 2531
2532 xs_list_foreach(shibx, inbox) { 2532 xs_list_foreach(shibx, inbox) {
2533 if (xs_set_add(&inboxes, inbox) == 1) 2533 if (xs_set_add(&inboxes, inbox) == 1)
2534 enqueue_output(snac, msg, inbox, 0, 0); 2534 enqueue_output(user, msg, inbox, 0, 0);
2535 } 2535 }
2536 } 2536 }
2537 } 2537 }
2538 2538
2539 xs_set_free(&inboxes); 2539 xs_set_free(&inboxes);
2540
2541 /* relay this note */
2542 if (strcmp(user->uid, "relay") != 0) { /* avoid loops */
2543 snac relay;
2544 if (user_open(&relay, "relay")) {
2545 /* a 'relay' user exists */
2546 const char *type = xs_dict_get(msg, "type");
2547
2548 if (xs_is_string(type) && strcmp(type, "Create") == 0) {
2549 const xs_val *object = xs_dict_get(msg, "object");
2550
2551 if (xs_is_dict(object)) {
2552 object = xs_dict_get(object, "id");
2553
2554 snac_debug(&relay, 1, xs_fmt("relaying message %s", object));
2555
2556 xs *boost = msg_admiration(&relay, object, "Announce");
2557 enqueue_message(&relay, boost);
2558 }
2559 }
2560
2561 user_free(&relay);
2562 }
2563 }
2540 } 2564 }
2541 else 2565 else
2542 if (strcmp(type, "input") == 0) { 2566 if (strcmp(type, "input") == 0) {
@@ -2548,13 +2572,13 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2548 if (xs_is_null(msg)) 2572 if (xs_is_null(msg))
2549 return; 2573 return;
2550 2574
2551 if (!process_input_message(snac, msg, req)) { 2575 if (!process_input_message(user, msg, req)) {
2552 if (retries > queue_retry_max) 2576 if (retries > queue_retry_max)
2553 snac_log(snac, xs_fmt("input giving up")); 2577 snac_log(user, xs_fmt("input giving up"));
2554 else { 2578 else {
2555 /* reenqueue */ 2579 /* reenqueue */
2556 enqueue_input(snac, msg, req, retries + 1); 2580 enqueue_input(user, msg, req, retries + 1);
2557 snac_log(snac, xs_fmt("input requeue #%d", retries + 1)); 2581 snac_log(user, xs_fmt("input requeue #%d", retries + 1));
2558 } 2582 }
2559 } 2583 }
2560 } 2584 }
@@ -2564,7 +2588,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2564 const char *id = xs_dict_get(q_item, "message"); 2588 const char *id = xs_dict_get(q_item, "message");
2565 2589
2566 if (!xs_is_null(id)) 2590 if (!xs_is_null(id))
2567 update_question(snac, id); 2591 update_question(user, id);
2568 } 2592 }
2569 else 2593 else
2570 if (strcmp(type, "object_request") == 0) { 2594 if (strcmp(type, "object_request") == 0) {
@@ -2574,17 +2598,17 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2574 int status; 2598 int status;
2575 xs *data = NULL; 2599 xs *data = NULL;
2576 2600
2577 status = activitypub_request(snac, id, &data); 2601 status = activitypub_request(user, id, &data);
2578 2602
2579 if (valid_status(status)) 2603 if (valid_status(status))
2580 object_add_ow(id, data); 2604 object_add_ow(id, data);
2581 2605
2582 snac_debug(snac, 1, xs_fmt("object_request %s %d", id, status)); 2606 snac_debug(user, 1, xs_fmt("object_request %s %d", id, status));
2583 } 2607 }
2584 } 2608 }
2585 else 2609 else
2586 if (strcmp(type, "verify_links") == 0) { 2610 if (strcmp(type, "verify_links") == 0) {
2587 verify_links(snac); 2611 verify_links(user);
2588 } 2612 }
2589 else 2613 else
2590 if (strcmp(type, "actor_refresh") == 0) { 2614 if (strcmp(type, "actor_refresh") == 0) {
@@ -2596,16 +2620,16 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2596 xs *actor_o = NULL; 2620 xs *actor_o = NULL;
2597 int status; 2621 int status;
2598 2622
2599 if (valid_status((status = activitypub_request(snac, actor, &actor_o)))) 2623 if (valid_status((status = activitypub_request(user, actor, &actor_o))))
2600 actor_add(actor, actor_o); 2624 actor_add(actor, actor_o);
2601 else 2625 else
2602 object_touch(actor); 2626 object_touch(actor);
2603 2627
2604 snac_log(snac, xs_fmt("actor_refresh %s %d", actor, status)); 2628 snac_log(user, xs_fmt("actor_refresh %s %d", actor, status));
2605 } 2629 }
2606 } 2630 }
2607 else 2631 else
2608 snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type)); 2632 snac_log(user, xs_fmt("unexpected user q_item type '%s'", type));
2609} 2633}
2610 2634
2611 2635