grunfink 1 год назад
Родитель
Сommit
5a2aef8666
2 измененных файлов с 43 добавлено и 1 удалено
  1. 33 0
      activitypub.c
  2. 10 1
      data.c

+ 33 - 0
activitypub.c

@@ -2765,6 +2765,39 @@ void process_user_queue_item(snac *user, xs_dict *q_item)
             snac_log(user, xs_fmt("actor_refresh %s %d", actor, status));
         }
     }
+    else
+    if (strcmp(type, "notify_webhook") == 0) {
+        const char *webhook = xs_dict_get(user->config, "notify_webhook");
+
+        if (xs_is_string(webhook)) {
+            const xs_dict *msg = xs_dict_get(q_item, "message");
+            int retries = xs_number_get(xs_dict_get(q_item, "retries"));
+
+            xs *hdrs = xs_dict_new();
+
+            hdrs = xs_dict_set(hdrs, "content-type", "application/json");
+            hdrs = xs_dict_set(hdrs, "user-agent",   USER_AGENT);
+
+            xs *body = xs_json_dumps(msg, 4);
+
+            int status;
+            xs *rsp = xs_http_request("POST", webhook, hdrs, body, strlen(body), &status, NULL, NULL, 0);
+
+            snac_debug(user, 0, xs_fmt("webhook post %s %d", webhook, status));
+
+            if (!valid_status(status)) {
+                retries++;
+
+                if (retries > queue_retry_max)
+                    snac_debug(user, 0, xs_fmt("webhook post giving up %s", webhook));
+                else {
+                    snac_debug(user, 0, xs_fmt("webhook post requeue %s %d", webhook, retries));
+
+                    enqueue_notify_webhook(user, msg, retries);
+                }
+            }
+        }
+    }
     else
         snac_log(user, xs_fmt("unexpected user q_item type '%s'", type));
 }

+ 10 - 1
data.c

@@ -3529,7 +3529,16 @@ void enqueue_notify_webhook(snac *user, const xs_dict *noti, int retries)
     const char *webhook = xs_dict_get(user->config, "notify_webhook");
 
     if (xs_is_string(webhook)) {
-        xs *qmsg = _new_qmsg("notify_webhook", noti, retries);
+        xs *msg = xs_dup(noti);
+
+        /* add more data */
+        msg = xs_dict_set(msg, "target", user->actor);
+        xs *actor_obj = NULL;
+
+        if (valid_status(object_get(xs_dict_get(noti, "actor"), &actor_obj)) && actor_obj)
+            msg = xs_dict_set(msg, "account", actor_obj);
+
+        xs *qmsg = _new_qmsg("notify_webhook", msg, retries);
         const char *ntid = xs_dict_get(qmsg, "ntid");
         xs *fn   = xs_fmt("%s/queue/%s.json", user->basedir, ntid);