commit cb616d6

default  ·  2023-04-14 10:23:32 +0000 UTC
parent f38de8c
New notifications web page.
2 files changed,  +88, -2
M html.c
M html.c
+85, -2
  1@@ -289,14 +289,15 @@ d_char *html_user_header(snac *snac, d_char *s, int local)
  2 
  3             /* show the notification number, if there are any */
  4             if (n_len)
  5-                n_str = xs_fmt("<sup style=\"background-color: red; color: white;\"> %d </sup> ", n_len);
  6+                n_str = xs_fmt("<sup style=\"background-color: red; "
  7+                               "color: white;\"> %d </sup> ", n_len);
  8             else
  9                 n_str = xs_str_new("");
 10 
 11             s1 = xs_fmt(
 12                 "<a href=\"%s\">%s</a> - "
 13                 "<a href=\"%s/admin\">%s</a> - "
 14-                "<a href=\"%s/admin\">%s</a>%s - "
 15+                "<a href=\"%s/notifications\">%s</a>%s - "
 16                 "<a href=\"%s/people\">%s</a></nav>\n",
 17                 snac->actor, L("public"),
 18                 snac->actor, L("private"),
 19@@ -1184,6 +1185,76 @@ d_char *html_people(snac *snac)
 20 }
 21 
 22 
 23+xs_str *html_notifications(snac *snac)
 24+{
 25+    xs_str *s  = xs_str_new(NULL);
 26+    xs *n_list = notify_list(snac, 0);
 27+    xs *n_time = notify_check_time(snac, 0);
 28+    xs_list *p = n_list;
 29+    xs_str *v;
 30+    enum { NHDR_NONE, NHDR_NEW, NHDR_OLD } stage = NHDR_NONE;
 31+
 32+    s = html_user_header(snac, s, 0);
 33+
 34+    while (xs_list_iter(&p, &v)) {
 35+        xs *noti = notify_get(snac, v);
 36+
 37+        if (noti == NULL)
 38+            continue;
 39+
 40+        xs *obj = NULL;
 41+        const char *type = xs_dict_get(noti, "type");
 42+        const char *id   = xs_dict_get(noti, strcmp(type, "Follow") == 0 ? "actor" : "objid");
 43+
 44+        if (!valid_status(object_get(id, &obj)))
 45+            continue;
 46+
 47+        if (is_hidden(snac, id))
 48+            continue;
 49+
 50+        if (strcmp(v, n_time) > 0) {
 51+            /* unseen notification */
 52+            if (stage == NHDR_NONE) {
 53+                xs *s1 = xs_fmt("<h2>%s</h2>\n", L("New"));
 54+                s = xs_str_cat(s, s1);
 55+
 56+                stage = NHDR_NEW;
 57+            }
 58+        }
 59+        else {
 60+            /* already seen notification */
 61+            if (stage != NHDR_OLD) {
 62+                xs *s1 = xs_fmt("<h2>%s</h2>\n", L("Older"));
 63+                s = xs_str_cat(s, s1);
 64+
 65+                stage = NHDR_OLD;
 66+            }
 67+        }
 68+
 69+        s = xs_str_cat(s, "<div>\n");
 70+
 71+        xs *s1 = xs_fmt("<p><b>%s</b>:</p>\n", strcmp("Create", type) == 0 ? "Mention" : type);
 72+        s = xs_str_cat(s, s1);
 73+
 74+        xs *md5 = xs_md5_hex(id, strlen(id));
 75+        s = html_entry(snac, s, obj, 0, 0, md5);
 76+
 77+        s = xs_str_cat(s, "</div>\n");
 78+    }
 79+
 80+    if (stage == NHDR_NONE) {
 81+        xs *s1 = xs_fmt("<h2>%s</h2>\n", L("None"));
 82+         s = xs_str_cat(s, s1);
 83+    }
 84+
 85+    s = html_user_footer(snac, s);
 86+
 87+    s = xs_str_cat(s, "</body>\n</html>\n");
 88+
 89+    return s;
 90+}
 91+
 92+
 93 int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char **ctype)
 94 {
 95     char *accept = xs_dict_get(req, "accept");
 96@@ -1305,6 +1376,18 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
 97         }
 98     }
 99     else
100+    if (strcmp(p_path, "notifications") == 0) {
101+        /* the list of notifications */
102+
103+        if (!login(&snac, req))
104+            status = 401;
105+        else {
106+            *body   = html_notifications(&snac);
107+            *b_size = strlen(*body);
108+            status  = 200;
109+        }
110+    }
111+    else
112     if (xs_startswith(p_path, "p/")) {
113         /* a timeline with just one entry */
114         xs *id  = xs_fmt("%s/%s", snac.actor, p_path);
+3, -0
 1@@ -882,6 +882,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2                 if (objid != NULL && !valid_status(object_get(objid, &entry)))
 3                     continue;
 4 
 5+                if (is_hidden(&snac1, objid))
 6+                    continue;
 7+
 8                 /* convert the type */
 9                 if (strcmp(type, "Like") == 0)
10                     type = "favourite";