snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit 729ad476f081e0ea63f90263ce5959b9889356f9
parent 823cb05fe53e364c4421512a9f1263ed54662de0
Author: default <nobody@localhost>
Date:   Mon,  5 Feb 2024 10:18:38 +0100

notify_list() no longer has a new_only argument.

Diffstat:
Mdata.c | 35+++++++++++++++++++++++++----------
Mhtml.c | 5++---
Mmastoapi.c | 2+-
Msnac.h | 3++-
4 files changed, 30 insertions(+), 15 deletions(-)

diff --git 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); } diff --git a/html.c b/html.c @@ -673,8 +673,7 @@ static xs_html *html_user_body(snac *user, int local) xs_html_text(L("private")))); } else { - xs *n_list = notify_list(user, 1); - int n_len = xs_list_len(n_list); + int n_len = notify_new_num(user); xs_html *notify_count = NULL; /* show the number of new notifications, if there are any */ @@ -2138,7 +2137,7 @@ xs_str *html_people(snac *user) xs_str *html_notifications(snac *user) { - xs *n_list = notify_list(user, 0); + xs *n_list = notify_list(user); xs *n_time = notify_check_time(user, 0); xs_html *body = html_user_body(user, 0); diff --git a/mastoapi.c b/mastoapi.c @@ -1542,7 +1542,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, else if (strcmp(cmd, "/v1/notifications") == 0) { /** **/ if (logged_in) { - xs *l = notify_list(&snac1, 0); + xs *l = notify_list(&snac1); xs *out = xs_list_new(); xs_list *p = l; xs_dict *v; diff --git a/snac.h b/snac.h @@ -187,7 +187,8 @@ xs_str *notify_check_time(snac *snac, int reset); void notify_add(snac *snac, const char *type, const char *utype, const char *actor, const char *objid); xs_dict *notify_get(snac *snac, const char *id); -xs_list *notify_list(snac *snac, int new_only); +int notify_new_num(snac *snac); +xs_list *notify_list(snac *snac); void notify_clear(snac *snac); void inbox_add(const char *inbox);