diff options
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c index dc492ca..d937726 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -800,8 +800,23 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor, | |||
| 800 | objid = actor; | 800 | objid = actor; |
| 801 | 801 | ||
| 802 | notify_add(snac, type, utype, actor, objid != NULL ? objid : id); | 802 | notify_add(snac, type, utype, actor, objid != NULL ? objid : id); |
| 803 | } | ||
| 804 | 803 | ||
| 804 | /* ntfy */ | ||
| 805 | char *ntfy_server = xs_dict_get(snac->config, "ntfy_server"); | ||
| 806 | char *ntfy_token = xs_dict_get(snac->config, "ntfy_token"); | ||
| 807 | |||
| 808 | if (!xs_is_null(ntfy_server) && *ntfy_server ) | ||
| 809 | enqueue_ntfy(body, ntfy_server, ntfy_token); | ||
| 810 | |||
| 811 | /* finally, store it in the notification folder */ | ||
| 812 | if (strcmp(type, "Follow") == 0) | ||
| 813 | objid = id; | ||
| 814 | else | ||
| 815 | if (strcmp(utype, "Follow") == 0) | ||
| 816 | objid = actor; | ||
| 817 | |||
| 818 | notify_add(snac, type, utype, actor, objid != NULL ? objid : id); | ||
| 819 | } | ||
| 805 | 820 | ||
| 806 | /** messages **/ | 821 | /** messages **/ |
| 807 | 822 | ||
| @@ -2133,6 +2148,31 @@ void process_queue_item(xs_dict *q_item) | |||
| 2133 | srv_debug(0, xs_fmt("telegram post %d", status)); | 2148 | srv_debug(0, xs_fmt("telegram post %d", status)); |
| 2134 | } | 2149 | } |
| 2135 | else | 2150 | else |
| 2151 | if (strcmp(type, "ntfy") == 0) { | ||
| 2152 | /* send this via ntfy */ | ||
| 2153 | char *ntfy_server = xs_dict_get(q_item, "ntfy_server"); | ||
| 2154 | char *msg = xs_dict_get(q_item, "message"); | ||
| 2155 | char *ntfy_token = xs_dict_get(q_item, "ntfy_token"); | ||
| 2156 | int status = 0; | ||
| 2157 | |||
| 2158 | xs *url = xs_fmt("%s", ntfy_server); | ||
| 2159 | //xs *body = xs_fmt("\"text\":\"%s\"}", msg); | ||
| 2160 | xs *body = xs_fmt("%s", msg); | ||
| 2161 | |||
| 2162 | xs *headers = xs_dict_new(); | ||
| 2163 | headers = xs_dict_append(headers, "content-type", "text/plain"); | ||
| 2164 | // Append the Authorization header only if ntfy_token is not NULL | ||
| 2165 | if (ntfy_token != NULL) { | ||
| 2166 | headers = xs_dict_append(headers, "Authorization", xs_fmt("Bearer %s", ntfy_token)); | ||
| 2167 | } | ||
| 2168 | |||
| 2169 | xs *rsp = xs_http_request("POST", url, headers, | ||
| 2170 | body, strlen(body), &status, NULL, NULL, 0); | ||
| 2171 | rsp = xs_free(rsp); | ||
| 2172 | |||
| 2173 | srv_debug(0, xs_fmt("ntfy post %d", status)); | ||
| 2174 | } | ||
| 2175 | else | ||
| 2136 | if (strcmp(type, "purge") == 0) { | 2176 | if (strcmp(type, "purge") == 0) { |
| 2137 | srv_log(xs_dup("purge start")); | 2177 | srv_log(xs_dup("purge start")); |
| 2138 | 2178 | ||