commit 729ad47

default  ·  2024-02-05 09:18:38 +0000 UTC
parent 823cb05
notify_list() no longer has a new_only argument.
4 files changed,  +30, -15
M data.c
M html.c
M snac.h
M data.c
+25, -10
 1@@ -2064,15 +2064,34 @@ xs_dict *notify_get(snac *snac, const char *id)
 2 }
 3 
 4 
 5-xs_list *notify_list(snac *snac, int new_only)
 6-/* returns a list of notification ids, optionally only the new ones */
 7+int notify_new_num(snac *snac)
 8+/* counts the number of new notifications */
 9 {
10-    xs *t = NULL;
11+    xs *t = notify_check_time(snac, 0);
12+    xs *spec = xs_fmt("%s/notify/" "*.json", snac->basedir);
13+    xs *lst = xs_glob(spec, 1, 1);
14+    int cnt = 0;
15+
16+    xs_list *p = lst;
17+    xs_str *v;
18+
19+    while (xs_list_iter(&p, &v)) {
20+        xs *id = xs_replace(v, ".json", "");
21 
22-    /* if only new ones are requested, get the last time */
23-    if (new_only)
24-        t = notify_check_time(snac, 0);
25+        /* old? count no more */
26+        if (strcmp(id, t) < 0)
27+            break;
28 
29+        cnt++;
30+    }
31+
32+    return cnt;
33+}
34+
35+
36+xs_list *notify_list(snac *snac)
37+/* returns a list of notification ids, optionally only the new ones */
38+{
39     xs *spec     = xs_fmt("%s/notify/" "*.json", snac->basedir);
40     xs *lst      = xs_glob(spec, 1, 1);
41     xs_list *out = xs_list_new();
42@@ -2082,10 +2101,6 @@ xs_list *notify_list(snac *snac, int new_only)
43     while (xs_list_iter(&p, &v)) {
44         xs *id = xs_replace(v, ".json", "");
45 
46-        /* old? */
47-        if (t != NULL && strcmp(id, t) < 0)
48-            continue;
49-
50         out = xs_list_append(out, id);
51     }
52 
M html.c
+2, -3
 1@@ -673,8 +673,7 @@ static xs_html *html_user_body(snac *user, int local)
 2                 xs_html_text(L("private"))));
 3     }
 4     else {
 5-        xs *n_list = notify_list(user, 1);
 6-        int n_len  = xs_list_len(n_list);
 7+        int n_len = notify_new_num(user);
 8         xs_html *notify_count = NULL;
 9 
10         /* show the number of new notifications, if there are any */
11@@ -2138,7 +2137,7 @@ xs_str *html_people(snac *user)
12 
13 xs_str *html_notifications(snac *user)
14 {
15-    xs *n_list = notify_list(user, 0);
16+    xs *n_list = notify_list(user);
17     xs *n_time = notify_check_time(user, 0);
18 
19     xs_html *body = html_user_body(user, 0);
+1, -1
1@@ -1542,7 +1542,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2     else
3     if (strcmp(cmd, "/v1/notifications") == 0) { /** **/
4         if (logged_in) {
5-            xs *l      = notify_list(&snac1, 0);
6+            xs *l      = notify_list(&snac1);
7             xs *out    = xs_list_new();
8             xs_list *p = l;
9             xs_dict *v;
M snac.h
+2, -1
 1@@ -187,7 +187,8 @@ xs_str *notify_check_time(snac *snac, int reset);
 2 void notify_add(snac *snac, const char *type, const char *utype,
 3                 const char *actor, const char *objid);
 4 xs_dict *notify_get(snac *snac, const char *id);
 5-xs_list *notify_list(snac *snac, int new_only);
 6+int notify_new_num(snac *snac);
 7+xs_list *notify_list(snac *snac);
 8 void notify_clear(snac *snac);
 9 
10 void inbox_add(const char *inbox);