summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2024-02-05 10:18:38 +0100
committerdefault <nobody@localhost>2024-02-05 10:18:38 +0100
commit729ad476f081e0ea63f90263ce5959b9889356f9 (patch)
tree8e9e7e4949b587493aecebc4538d2d6a8979d1d8
parent823cb05fe53e364c4421512a9f1263ed54662de0 (diff)
notify_list() no longer has a new_only argument.
-rw-r--r--data.c35
-rw-r--r--html.c5
-rw-r--r--mastoapi.c2
-rw-r--r--snac.h3
4 files changed, 30 insertions, 15 deletions
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);
}
diff --git a/html.c b/html.c
index f0cda81..85ec786 100644
--- 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
index efcdae8..f1af7ba 100644
--- 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
index f6f7b0b..0190d12 100644
--- 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);