summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authorGravatar default2023-04-13 16:59:17 +0200
committerGravatar default2023-04-13 16:59:17 +0200
commitbcde97c2d53f9c94c6ced2717945affa4ede554c (patch)
treee57442ff4bd0f2bc25ae516241ca5bcdaa0c3878 /data.c
parentStarted working on a notification list. (diff)
downloadsnac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.tar.gz
snac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.tar.xz
snac2-bcde97c2d53f9c94c6ced2717945affa4ede554c.zip
New function notify_add().
Diffstat (limited to 'data.c')
-rw-r--r--data.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/data.c b/data.c
index b375cb2..a98e9e5 100644
--- a/data.c
+++ b/data.c
@@ -7,6 +7,7 @@
7#include "xs_openssl.h" 7#include "xs_openssl.h"
8#include "xs_glob.h" 8#include "xs_glob.h"
9#include "xs_set.h" 9#include "xs_set.h"
10#include "xs_time.h"
10 11
11#include "snac.h" 12#include "snac.h"
12 13
@@ -1474,6 +1475,40 @@ xs_list *inbox_list(void)
1474} 1475}
1475 1476
1476 1477
1478/** notifications **/
1479
1480void notify_add(snac *snac, const char *type, const char *utype,
1481 const char *actor, const char *objid)
1482/* adds a new notification */
1483{
1484 xs *ntid = tid(0);
1485 xs *fn = xs_fmt("%s/notify/", snac->basedir);
1486 xs *date = xs_str_utctime(0, "%Y-%m-%dT%H:%M:%SZ");
1487 FILE *f;
1488
1489 /* create the directory */
1490 mkdirx(fn);
1491 fn = xs_str_cat(fn, ntid);
1492 fn = xs_str_cat(fn, ".json");
1493
1494 xs *noti = xs_dict_new();
1495
1496 noti = xs_dict_append(noti, "id", ntid);
1497 noti = xs_dict_append(noti, "type", type);
1498 noti = xs_dict_append(noti, "utype", utype);
1499 noti = xs_dict_append(noti, "actor", actor);
1500 noti = xs_dict_append(noti, "objid", objid);
1501 noti = xs_dict_append(noti, "date", date);
1502
1503 if ((f = fopen(fn, "w")) != NULL) {
1504 xs *j = xs_json_dumps_pp(noti, 4);
1505
1506 fwrite(j, strlen(j), 1, f);
1507 fclose(f);
1508 }
1509}
1510
1511
1477/** the queue **/ 1512/** the queue **/
1478 1513
1479static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) 1514static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)