commit 4127ec4

default  ·  2025-01-19 17:20:27 +0000 UTC
parent a80b15e
Also relay notes to the relays that follow us.
1 files changed,  +41, -17
+41, -17
  1@@ -2485,7 +2485,7 @@ int send_email(const char *msg)
  2 }
  3 
  4 
  5-void process_user_queue_item(snac *snac, xs_dict *q_item)
  6+void process_user_queue_item(snac *user, xs_dict *q_item)
  7 /* processes an item from the user queue */
  8 {
  9     const char *type;
 10@@ -2496,7 +2496,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
 11 
 12     if (strcmp(type, "message") == 0) {
 13         const xs_dict *msg = xs_dict_get(q_item, "message");
 14-        xs *rcpts = recipient_list(snac, msg, 1);
 15+        xs *rcpts = recipient_list(user, msg, 1);
 16         xs_set inboxes;
 17         const xs_str *actor;
 18 
 19@@ -2505,7 +2505,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
 20         /* add this shared inbox first */
 21         xs *this_shared_inbox = xs_fmt("%s/shared-inbox", srv_baseurl);
 22         xs_set_add(&inboxes, this_shared_inbox);
 23-        enqueue_output(snac, msg, this_shared_inbox, 0, 0);
 24+        enqueue_output(user, msg, this_shared_inbox, 0, 0);
 25 
 26         /* iterate the recipients */
 27         xs_list_foreach(rcpts, actor) {
 28@@ -2516,10 +2516,10 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
 29                 if (inbox != NULL) {
 30                     /* add to the set and, if it's not there, send message */
 31                     if (xs_set_add(&inboxes, inbox) == 1)
 32-                        enqueue_output(snac, msg, inbox, 0, 0);
 33+                        enqueue_output(user, msg, inbox, 0, 0);
 34                 }
 35                 else
 36-                    snac_log(snac, xs_fmt("cannot find inbox for %s", actor));
 37+                    snac_log(user, xs_fmt("cannot find inbox for %s", actor));
 38             }
 39         }
 40 
 41@@ -2531,12 +2531,36 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
 42 
 43                 xs_list_foreach(shibx, inbox) {
 44                     if (xs_set_add(&inboxes, inbox) == 1)
 45-                        enqueue_output(snac, msg, inbox, 0, 0);
 46+                        enqueue_output(user, msg, inbox, 0, 0);
 47                 }
 48             }
 49         }
 50 
 51         xs_set_free(&inboxes);
 52+
 53+        /* relay this note */
 54+        if (strcmp(user->uid, "relay") != 0) { /* avoid loops */
 55+            snac relay;
 56+            if (user_open(&relay, "relay")) {
 57+                /* a 'relay' user exists */
 58+                const char *type = xs_dict_get(msg, "type");
 59+
 60+                if (xs_is_string(type) && strcmp(type, "Create") == 0) {
 61+                    const xs_val *object = xs_dict_get(msg, "object");
 62+
 63+                    if (xs_is_dict(object)) {
 64+                        object = xs_dict_get(object, "id");
 65+
 66+                        snac_debug(&relay, 1, xs_fmt("relaying message %s", object));
 67+
 68+                        xs *boost = msg_admiration(&relay, object, "Announce");
 69+                        enqueue_message(&relay, boost);
 70+                    }
 71+                }
 72+
 73+                user_free(&relay);
 74+            }
 75+        }
 76     }
 77     else
 78     if (strcmp(type, "input") == 0) {
 79@@ -2548,13 +2572,13 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
 80         if (xs_is_null(msg))
 81             return;
 82 
 83-        if (!process_input_message(snac, msg, req)) {
 84+        if (!process_input_message(user, msg, req)) {
 85             if (retries > queue_retry_max)
 86-                snac_log(snac, xs_fmt("input giving up"));
 87+                snac_log(user, xs_fmt("input giving up"));
 88             else {
 89                 /* reenqueue */
 90-                enqueue_input(snac, msg, req, retries + 1);
 91-                snac_log(snac, xs_fmt("input requeue #%d", retries + 1));
 92+                enqueue_input(user, msg, req, retries + 1);
 93+                snac_log(user, xs_fmt("input requeue #%d", retries + 1));
 94             }
 95         }
 96     }
 97@@ -2564,7 +2588,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
 98         const char *id = xs_dict_get(q_item, "message");
 99 
100         if (!xs_is_null(id))
101-            update_question(snac, id);
102+            update_question(user, id);
103     }
104     else
105     if (strcmp(type, "object_request") == 0) {
106@@ -2574,17 +2598,17 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
107             int status;
108             xs *data = NULL;
109 
110-            status = activitypub_request(snac, id, &data);
111+            status = activitypub_request(user, id, &data);
112 
113             if (valid_status(status))
114                 object_add_ow(id, data);
115 
116-            snac_debug(snac, 1, xs_fmt("object_request %s %d", id, status));
117+            snac_debug(user, 1, xs_fmt("object_request %s %d", id, status));
118         }
119     }
120     else
121     if (strcmp(type, "verify_links") == 0) {
122-        verify_links(snac);
123+        verify_links(user);
124     }
125     else
126     if (strcmp(type, "actor_refresh") == 0) {
127@@ -2596,16 +2620,16 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
128             xs *actor_o = NULL;
129             int status;
130 
131-            if (valid_status((status = activitypub_request(snac, actor, &actor_o))))
132+            if (valid_status((status = activitypub_request(user, actor, &actor_o))))
133                 actor_add(actor, actor_o);
134             else
135                 object_touch(actor);
136 
137-            snac_log(snac, xs_fmt("actor_refresh %s %d", actor, status));
138+            snac_log(user, xs_fmt("actor_refresh %s %d", actor, status));
139         }
140     }
141     else
142-        snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type));
143+        snac_log(user, xs_fmt("unexpected user q_item type '%s'", type));
144 }
145 
146