summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-04-13 17:34:48 +0200
committerdefault <nobody@localhost>2023-04-13 17:34:48 +0200
commit1a27e67ed9e4c4b12d9ee4d151c7647043b54647 (patch)
treeee59fbe612da767a7f21db117d41b711b7a763ad /data.c
parent211bedd4978c4711f0e2399b38ccb6e76e39856d (diff)
New functions notify_get() and notify_list().
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,
}
+xs_dict *notify_get(snac *snac, const char *id)
+/* gets a notification */
+{
+ xs *fn = xs_fmt("%s/notify/%s.json", snac->basedir);
+ FILE *f;
+ xs_dict *out = NULL;
+
+ if ((f = fopen(fn, "r")) != NULL) {
+ xs *j = xs_readall(f);
+ fclose(f);
+
+ out = xs_json_loads(j);
+ }
+
+ return out;
+}
+
+
+xs_list *notify_list(snac *snac, int new_only)
+/* returns a list of notifications, optionally only the new ones */
+{
+ xs *t = NULL;
+
+ /* if only new ones are requested, get the last time */
+ if (new_only)
+ t = notify_check_time(snac, 0);
+
+ xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir);
+ xs *lst = xs_glob(spec, 1, 0);
+ xs_list *out = xs_list_new();
+ xs_list *p = lst;
+ xs_str *v;
+
+ while (xs_list_iter(&p, &v)) {
+ xs *id = xs_replace(v, ".json", "");
+
+ /* old? */
+ if (t != NULL && strcmp(id, t) < 0)
+ continue;
+
+ xs *noti = notify_get(snac, id);
+
+ out = xs_list_append(out, noti);
+ }
+
+ return out;
+}
+
+
/** the queue **/
static xs_dict *_enqueue_put(const char *fn, xs_dict *msg)