summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/data.c b/data.c
index cf66b9a..939ede6 100644
--- a/data.c
+++ b/data.c
@@ -1537,6 +1537,55 @@ void notify_add(snac *snac, const char *type, const char *utype,
1537} 1537}
1538 1538
1539 1539
1540xs_dict *notify_get(snac *snac, const char *id)
1541/* gets a notification */
1542{
1543 xs *fn = xs_fmt("%s/notify/%s.json", snac->basedir);
1544 FILE *f;
1545 xs_dict *out = NULL;
1546
1547 if ((f = fopen(fn, "r")) != NULL) {
1548 xs *j = xs_readall(f);
1549 fclose(f);
1550
1551 out = xs_json_loads(j);
1552 }
1553
1554 return out;
1555}
1556
1557
1558xs_list *notify_list(snac *snac, int new_only)
1559/* returns a list of notifications, optionally only the new ones */
1560{
1561 xs *t = NULL;
1562
1563 /* if only new ones are requested, get the last time */
1564 if (new_only)
1565 t = notify_check_time(snac, 0);
1566
1567 xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir);
1568 xs *lst = xs_glob(spec, 1, 0);
1569 xs_list *out = xs_list_new();
1570 xs_list *p = lst;
1571 xs_str *v;
1572
1573 while (xs_list_iter(&p, &v)) {
1574 xs *id = xs_replace(v, ".json", "");
1575
1576 /* old? */
1577 if (t != NULL && strcmp(id, t) < 0)
1578 continue;
1579
1580 xs *noti = notify_get(snac, id);
1581
1582 out = xs_list_append(out, noti);
1583 }
1584
1585 return out;
1586}
1587
1588
1540/** the queue **/ 1589/** the queue **/
1541 1590
1542static xs_dict *_enqueue_put(const char *fn, xs_dict *msg) 1591static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)