From bcde97c2d53f9c94c6ced2717945affa4ede554c Mon Sep 17 00:00:00 2001 From: default Date: Thu, 13 Apr 2023 16:59:17 +0200 Subject: New function notify_add(). --- data.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'data.c') 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) -- cgit v1.2.3