From 729ad476f081e0ea63f90263ce5959b9889356f9 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 5 Feb 2024 10:18:38 +0100 Subject: notify_list() no longer has a new_only argument. --- data.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'data.c') diff --git a/data.c b/data.c index d9816a0..d644eb3 100644 --- a/data.c +++ b/data.c @@ -2064,15 +2064,34 @@ xs_dict *notify_get(snac *snac, const char *id) } -xs_list *notify_list(snac *snac, int new_only) -/* returns a list of notification ids, optionally only the new ones */ +int notify_new_num(snac *snac) +/* counts the number of new notifications */ { - xs *t = NULL; + xs *t = notify_check_time(snac, 0); + xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir); + xs *lst = xs_glob(spec, 1, 1); + int cnt = 0; + + xs_list *p = lst; + xs_str *v; + + while (xs_list_iter(&p, &v)) { + xs *id = xs_replace(v, ".json", ""); - /* if only new ones are requested, get the last time */ - if (new_only) - t = notify_check_time(snac, 0); + /* old? count no more */ + if (strcmp(id, t) < 0) + break; + cnt++; + } + + return cnt; +} + + +xs_list *notify_list(snac *snac) +/* returns a list of notification ids, optionally only the new ones */ +{ xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir); xs *lst = xs_glob(spec, 1, 1); xs_list *out = xs_list_new(); @@ -2082,10 +2101,6 @@ xs_list *notify_list(snac *snac, int new_only) while (xs_list_iter(&p, &v)) { xs *id = xs_replace(v, ".json", ""); - /* old? */ - if (t != NULL && strcmp(id, t) < 0) - continue; - out = xs_list_append(out, id); } -- cgit v1.2.3