Selaa lähdekoodia

Use endpoints/sharedInbox instead of inbox, if there is one.

default 3 vuotta sitten
vanhempi
sitoutus
afce422785
1 muutettua tiedostoa jossa 23 lisäystä ja 12 poistoa
  1. 23 12
      activitypub.c

+ 23 - 12
activitypub.c

@@ -133,24 +133,35 @@ int send_to_inbox(snac *snac, char *inbox, char *msg, d_char **payload, int *p_s
 }
 
 
-int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size)
-/* sends a message to an actor */
+d_char *get_actor_inbox(snac *snac, char *actor)
+/* gets an actor's inbox */
 {
-    int status;
     xs *data = NULL;
+    char *v = NULL;
 
-    /* resolve the actor first */
-    status = actor_request(snac, actor, &data);
-
-    if (valid_status(status)) {
-        char *inbox = xs_dict_get(data, "inbox");
+    if (valid_status(actor_request(snac, actor, &data))) {
+        /* try first endpoints/sharedInbox */
+        if ((v = xs_dict_get(data, "endpoints")))
+            v = xs_dict_get(v, "sharedInbox");
 
-        if (inbox != NULL)
-            status = send_to_inbox(snac, inbox, msg, payload, p_size);
-        else
-            status = 400;
+        /* try then the regular inbox */
+        if (xs_is_null(v))
+            v = xs_dict_get(data, "inbox");
     }
 
+    return xs_is_null(v) ? NULL : xs_dup(v);
+}
+
+
+int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size)
+/* sends a message to an actor */
+{
+    int status = 400;
+    xs *inbox = get_actor_inbox(snac, actor);
+
+    if (!xs_is_null(inbox))
+        status = send_to_inbox(snac, inbox, msg, payload, p_size);
+
     snac_log(snac, xs_fmt("send_to_actor %s %d", actor, status));
 
     return status;