diff options
author | grunfink <grunfink@noreply.codeberg.org> | 2024-01-12 17:09:58 +0000 |
---|---|---|
committer | grunfink <grunfink@noreply.codeberg.org> | 2024-01-12 17:09:58 +0000 |
commit | a0cb5c60cdbf7855fa0c2842113797be2a206226 (patch) | |
tree | 3cff6166192f8bc8f34149a0a18ca103cfb1384e /activitypub.c | |
parent | d8e7fe69eda030b960bda8eecfdcc126a09ce14f (diff) | |
parent | 82d57557bb9a16f18ed5acc874d283ef0e9f47f5 (diff) |
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.c | 41 |
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, objid = actor; notify_add(snac, type, utype, actor, objid != NULL ? objid : id); -} + /* ntfy */ + char *ntfy_server = xs_dict_get(snac->config, "ntfy_server"); + char *ntfy_token = xs_dict_get(snac->config, "ntfy_token"); + + if (!xs_is_null(ntfy_server) && *ntfy_server) + enqueue_ntfy(body, ntfy_server, ntfy_token); + + /* finally, store it in the notification folder */ + if (strcmp(type, "Follow") == 0) + objid = id; + else + if (strcmp(utype, "Follow") == 0) + objid = actor; + + notify_add(snac, type, utype, actor, objid != NULL ? objid : id); +} /** messages **/ @@ -2133,6 +2148,30 @@ void process_queue_item(xs_dict *q_item) srv_debug(0, xs_fmt("telegram post %d", status)); } else + if (strcmp(type, "ntfy") == 0) { + /* send this via ntfy */ + char *ntfy_server = xs_dict_get(q_item, "ntfy_server"); + char *msg = xs_dict_get(q_item, "message"); + char *ntfy_token = xs_dict_get(q_item, "ntfy_token"); + int status = 0; + + xs *url = xs_fmt("%s", ntfy_server); + xs *body = xs_fmt("%s", msg); + + xs *headers = xs_dict_new(); + headers = xs_dict_append(headers, "content-type", "text/plain"); + // Append the Authorization header only if ntfy_token is not NULL + if (ntfy_token != NULL) { + headers = xs_dict_append(headers, "Authorization", xs_fmt("Bearer %s", ntfy_token)); + } + + xs *rsp = xs_http_request("POST", url, headers, + body, strlen(body), &status, NULL, NULL, 0); + rsp = xs_free(rsp); + + srv_debug(0, xs_fmt("ntfy post %d", status)); + } + else if (strcmp(type, "purge") == 0) { srv_log(xs_dup("purge start")); |