summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar grunfink2024-01-12 17:09:58 +0000
committerGravatar grunfink2024-01-12 17:09:58 +0000
commita0cb5c60cdbf7855fa0c2842113797be2a206226 (patch)
tree3cff6166192f8bc8f34149a0a18ca103cfb1384e /activitypub.c
parentIn README.md, document how to add -lrt to make (for older distributions). (diff)
parentntfy code cleanup (diff)
downloadsnac2-a0cb5c60cdbf7855fa0c2842113797be2a206226.tar.gz
snac2-a0cb5c60cdbf7855fa0c2842113797be2a206226.tar.xz
snac2-a0cb5c60cdbf7855fa0c2842113797be2a206226.zip
Merge pull request 'Added support for ntfy notifications with enhanced privacy when utilizing a self-hosted server, eliminating the need for external services.' (#102) from draga79/snac2:master into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/102
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/activitypub.c b/activitypub.c
index dc492ca..566c240 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,30 @@ 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("%s", msg);
2160
2161 xs *headers = xs_dict_new();
2162 headers = xs_dict_append(headers, "content-type", "text/plain");
2163 // Append the Authorization header only if ntfy_token is not NULL
2164 if (ntfy_token != NULL) {
2165 headers = xs_dict_append(headers, "Authorization", xs_fmt("Bearer %s", ntfy_token));
2166 }
2167
2168 xs *rsp = xs_http_request("POST", url, headers,
2169 body, strlen(body), &status, NULL, NULL, 0);
2170 rsp = xs_free(rsp);
2171
2172 srv_debug(0, xs_fmt("ntfy post %d", status));
2173 }
2174 else
2136 if (strcmp(type, "purge") == 0) { 2175 if (strcmp(type, "purge") == 0) {
2137 srv_log(xs_dup("purge start")); 2176 srv_log(xs_dup("purge start"));
2138 2177