diff --git a/activitypub.c b/activitypub.c index 792080d..851699a 100644 --- a/activitypub.c +++ b/activitypub.c @@ -935,6 +935,9 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg if (!xs_is_null(bot) && !xs_is_null(chat_id) && *bot && *chat_id) enqueue_telegram(body, bot, chat_id); + + /* finally, store it in the notification folder */ + notify_add(snac, type, utype, actor, objid); } diff --git a/data.c b/data.c index b375cb2..a98e9e5 100644 --- a/data.c +++ b/data.c @@ -7,6 +7,7 @@ #include "xs_openssl.h" #include "xs_glob.h" #include "xs_set.h" +#include "xs_time.h" #include "snac.h" @@ -1474,6 +1475,40 @@ xs_list *inbox_list(void) } +/** notifications **/ + +void notify_add(snac *snac, const char *type, const char *utype, + const char *actor, const char *objid) +/* adds a new notification */ +{ + xs *ntid = tid(0); + xs *fn = xs_fmt("%s/notify/", snac->basedir); + xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ"); + FILE *f; + + /* create the directory */ + mkdirx(fn); + fn = xs_str_cat(fn, ntid); + fn = xs_str_cat(fn, ".json"); + + xs *noti = xs_dict_new(); + + noti = xs_dict_append(noti, "id", ntid); + noti = xs_dict_append(noti, "type", type); + noti = xs_dict_append(noti, "utype", utype); + noti = xs_dict_append(noti, "actor", actor); + noti = xs_dict_append(noti, "objid", objid); + noti = xs_dict_append(noti, "date", date); + + if ((f = fopen(fn, "w")) != NULL) { + xs *j = xs_json_dumps_pp(noti, 4); + + fwrite(j, strlen(j), 1, f); + fclose(f); + } +} + + /** the queue **/ static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) diff --git a/mastoapi.c b/mastoapi.c index 80f1619..7029dfb 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -855,11 +855,6 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, else if (strcmp(cmd, "/notifications") == 0) { /* TBD */ - { - xs *j = xs_json_dumps_pp(args, 4); - printf("notification args:\n%s\n", j); - } - *body = xs_dup("[]"); *ctype = "application/json"; status = 200; diff --git a/snac.h b/snac.h index 02ddfb1..a707f16 100644 --- a/snac.h +++ b/snac.h @@ -1,7 +1,7 @@ /* snac - A simple, minimalistic ActivityPub instance */ /* copyright (c) 2022 - 2023 grunfink / MIT license */ -#define VERSION "2.27" +#define VERSION "2.28-dev" #define USER_AGENT "snac/" VERSION @@ -137,6 +137,9 @@ d_char *history_list(snac *snac); void lastlog_write(snac *snac); +void notify_add(snac *snac, const char *type, const char *utype, + const char *actor, const char *objid); + void inbox_add(const char *inbox); void inbox_add_by_actor(const xs_dict *actor); xs_list *inbox_list(void);