commit 5c303d5

default  ·  2025-01-24 13:54:55 +0000 UTC
parent 1cb7b37
Improved notification messages.
1 files changed,  +36, -10
M html.c
M html.c
+36, -10
 1@@ -2967,8 +2967,8 @@ xs_str *html_notifications(snac *user, int skip, int show)
 2         xs_html_attr("class", "snac-posts"));
 3     xs_html_add(body, posts);
 4 
 5-    xs_set rep;
 6-    xs_set_init(&rep);
 7+    /* dict to store previous notification labels */
 8+    xs *admiration_labels = xs_dict_new();
 9 
10     const xs_str *v;
11 
12@@ -2995,8 +2995,8 @@ xs_str *html_notifications(snac *user, int skip, int show)
13 
14         const char *msg_id = NULL;
15 
16-        if (xs_is_dict(obj) && (msg_id = xs_dict_get(obj, "id")) && xs_set_add(&rep, msg_id) != 1)
17-            continue;
18+        if (xs_is_dict(obj))
19+            msg_id = xs_dict_get(obj, "id");
20 
21         const char *actor_id = xs_dict_get(noti, "actor");
22         xs *actor = NULL;
23@@ -3030,9 +3030,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
24 
25         xs *s_date = xs_crop_i(xs_dup(date), 0, 10);
26 
27-        xs_html *entry = xs_html_tag("div",
28-            xs_html_attr("class", "snac-post-with-desc"),
29-            xs_html_tag("p",
30+        xs_html *this_html_label = xs_html_container(
31                 xs_html_tag("b",
32                     xs_html_text(label),
33                     xs_html_text(" by "),
34@@ -3043,7 +3041,37 @@ xs_str *html_notifications(snac *user, int skip, int show)
35                 xs_html_tag("time",
36                     xs_html_attr("class", "dt-published snac-pubdate"),
37                     xs_html_attr("title", date),
38-                    xs_html_text(s_date))));
39+                    xs_html_text(s_date)));
40+
41+        xs_html *html_label = NULL;
42+
43+        if (xs_is_string(msg_id)) {
44+            const xs_val *prev_label = xs_dict_get(admiration_labels, msg_id);
45+
46+            if (xs_type(prev_label) == XSTYPE_DATA) {
47+                /* there is a previous list of admiration labels! */
48+                xs_data_get(&html_label, prev_label);
49+
50+                xs_html_add(html_label,
51+                    xs_html_sctag("br", NULL),
52+                    this_html_label);
53+
54+                continue;
55+            }
56+        }
57+
58+        xs_html *entry = NULL;
59+
60+        html_label = xs_html_tag("p",
61+            this_html_label);
62+
63+        /* store in the admiration labels dict */
64+        xs *pl = xs_data_new(&html_label, sizeof(html_label));
65+        admiration_labels = xs_dict_set(admiration_labels, msg_id, pl);
66+
67+        entry = xs_html_tag("div",
68+            xs_html_attr("class", "snac-post-with-desc"),
69+            html_label);
70 
71         if (strcmp(type, "Follow") == 0 || strcmp(utype, "Follow") == 0 || strcmp(type, "Block") == 0) {
72             xs_html_add(entry,
73@@ -3111,8 +3139,6 @@ xs_str *html_notifications(snac *user, int skip, int show)
74         }
75     }
76 
77-    xs_set_free(&rep);
78-
79     if (noti_new == NULL && noti_seen == NULL)
80         xs_html_add(body,
81             xs_html_tag("h2",