commit ab05857

grunfink  ·  2026-09-10 14:29:39 +0000 UTC
parent 23828b5
Added filtering for cool posts.
2 files changed,  +32, -2
M data.c
M html.c
M data.c
+28, -2
 1@@ -3647,6 +3647,7 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show)
 2     int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def));
 3     int n_polls_on  = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def));
 4     int n_webmen_on  = xs_is_true(xs_dict_get_def(n_filter, "webmentions", n_def));
 5+    int n_cool_posts_on  = xs_is_true(xs_dict_get_def(n_filter, "cool_posts", n_def));
 6 
 7     const xs_str *v;
 8     xs_list *flt = xs_list_new();
 9@@ -3660,10 +3661,35 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show)
10         const char *type  = xs_dict_get(noti, "type");
11         const char *utype = xs_dict_get(noti, "utype");
12         const char *actor_id = xs_dict_get(noti, "actor");
13+        const xs_dict *msg = xs_dict_get(noti, "msg");
14+        const xs_dict *obj = xs_dict_get_def(msg, "object", xs_stock(XSTYPE_DICT));
15+
16         if (strcmp(type, "EmojiReact") == 0 && xs_is_true(xs_dict_get(srv_config, "disable_emojireact")))
17             continue;
18-        if (strcmp(type, "Create") == 0 && !n_ments_on)
19-            continue;
20+        if (strcmp(type, "Create") == 0) {
21+            int is_mention = 0;
22+            const xs_list *l = xs_dict_get_def(obj, "tag", xs_stock(XSTYPE_LIST));
23+            const xs_dict *d;
24+
25+            xs_list_foreach(l, d) {
26+                const char *type = xs_dict_get_def(d, "type", "");
27+                const char *href = xs_dict_get_def(d, "href", "");
28+
29+                if (strcmp(type, "Mention") == 0 && strcmp(href, snac->actor) == 0) {
30+                    is_mention = 1;
31+                    break;
32+                }
33+            }
34+
35+            if (is_mention) {
36+                if (!n_ments_on)
37+                    continue;
38+            }
39+            else {
40+                if (!n_cool_posts_on)
41+                    continue;
42+            }
43+        }
44         if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0 && !n_polls_on)
45             continue;
46         if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0 && !n_unfol_on)
M html.c
+4, -0
 1@@ -4313,6 +4313,7 @@ void notify_filter(snac *user, const xs_dict *p_vars)
 2     int blocks_on = (v = xs_dict_get(p_vars, "blocks_on")) ? strcmp(v, "on") == 0 : 0;
 3     int polls_on  = (v = xs_dict_get(p_vars, "polls_on")) ? strcmp(v, "on") == 0 : 0;
 4     int webmen_on  = (v = xs_dict_get(p_vars, "webmentions_on")) ? strcmp(v, "on") == 0 : 0;
 5+    int cool_posts_on  = (v = xs_dict_get(p_vars, "cool_posts_on")) ? strcmp(v, "on") == 0 : 0;
 6     xs *filter = xs_dict_new();
 7     filter = xs_dict_set(filter, "likes", xs_stock(likes_on ? XSTYPE_TRUE : XSTYPE_FALSE));
 8     filter = xs_dict_set(filter, "reacts", xs_stock(reacts_on ? XSTYPE_TRUE : XSTYPE_FALSE));
 9@@ -4324,6 +4325,7 @@ void notify_filter(snac *user, const xs_dict *p_vars)
10     filter = xs_dict_set(filter, "blocks", xs_stock(blocks_on ? XSTYPE_TRUE : XSTYPE_FALSE));
11     filter = xs_dict_set(filter, "polls", xs_stock(polls_on ? XSTYPE_TRUE : XSTYPE_FALSE));
12     filter = xs_dict_set(filter, "webmentions", xs_stock(webmen_on ? XSTYPE_TRUE : XSTYPE_FALSE));
13+    filter = xs_dict_set(filter, "cool_posts", xs_stock(cool_posts_on ? XSTYPE_TRUE : XSTYPE_FALSE));
14     user->config = xs_dict_set(user->config, "notify_filter", filter);
15     user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz
16 }
17@@ -4359,6 +4361,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
18     int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def));
19     int n_polls_on  = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def));
20     int n_webmen_on  = xs_is_true(xs_dict_get_def(n_filter, "webmentions", n_def));
21+    int n_cool_posts_on  = xs_is_true(xs_dict_get_def(n_filter, "cool_posts", n_def));
22 
23     xs_html *html = xs_html_tag("html",
24         html_user_head(user, NULL, NULL),
25@@ -4386,6 +4389,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
26         html_checkbox("blocks_on", L("Blocks"), n_blocks_on),
27         html_checkbox("polls_on", L("Polls"), n_polls_on),
28         html_checkbox("webmentions_on", L("Webmentions"), n_webmen_on),
29+        html_checkbox("cool_posts_on", L("Posts from cool users"), n_cool_posts_on),
30         xs_html_sctag("input",
31             xs_html_attr("type",     "submit"),
32             xs_html_attr("class",    "button"),