Forráskód Böngészése

Added filtering for cool posts.

grunfink 1 hete
szülő
commit
ab05857522
2 módosított fájl, 32 hozzáadás és 2 törlés
  1. 28 2
      data.c
  2. 4 0
      html.c

+ 28 - 2
data.c

@@ -3647,6 +3647,7 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show)
     int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def));
     int n_polls_on  = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def));
     int n_webmen_on  = xs_is_true(xs_dict_get_def(n_filter, "webmentions", n_def));
+    int n_cool_posts_on  = xs_is_true(xs_dict_get_def(n_filter, "cool_posts", n_def));
 
     const xs_str *v;
     xs_list *flt = xs_list_new();
@@ -3660,10 +3661,35 @@ xs_list *notify_filter_list(snac *snac, xs_list *notifs, int skip, int show)
         const char *type  = xs_dict_get(noti, "type");
         const char *utype = xs_dict_get(noti, "utype");
         const char *actor_id = xs_dict_get(noti, "actor");
+        const xs_dict *msg = xs_dict_get(noti, "msg");
+        const xs_dict *obj = xs_dict_get_def(msg, "object", xs_stock(XSTYPE_DICT));
+
         if (strcmp(type, "EmojiReact") == 0 && xs_is_true(xs_dict_get(srv_config, "disable_emojireact")))
             continue;
-        if (strcmp(type, "Create") == 0 && !n_ments_on)
-            continue;
+        if (strcmp(type, "Create") == 0) {
+            int is_mention = 0;
+            const xs_list *l = xs_dict_get_def(obj, "tag", xs_stock(XSTYPE_LIST));
+            const xs_dict *d;
+
+            xs_list_foreach(l, d) {
+                const char *type = xs_dict_get_def(d, "type", "");
+                const char *href = xs_dict_get_def(d, "href", "");
+
+                if (strcmp(type, "Mention") == 0 && strcmp(href, snac->actor) == 0) {
+                    is_mention = 1;
+                    break;
+                }
+            }
+
+            if (is_mention) {
+                if (!n_ments_on)
+                    continue;
+            }
+            else {
+                if (!n_cool_posts_on)
+                    continue;
+            }
+        }
         if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0 && !n_polls_on)
             continue;
         if (strcmp(type, "Undo") == 0 && strcmp(utype, "Follow") == 0 && !n_unfol_on)

+ 4 - 0
html.c

@@ -4313,6 +4313,7 @@ void notify_filter(snac *user, const xs_dict *p_vars)
     int blocks_on = (v = xs_dict_get(p_vars, "blocks_on")) ? strcmp(v, "on") == 0 : 0;
     int polls_on  = (v = xs_dict_get(p_vars, "polls_on")) ? strcmp(v, "on") == 0 : 0;
     int webmen_on  = (v = xs_dict_get(p_vars, "webmentions_on")) ? strcmp(v, "on") == 0 : 0;
+    int cool_posts_on  = (v = xs_dict_get(p_vars, "cool_posts_on")) ? strcmp(v, "on") == 0 : 0;
     xs *filter = xs_dict_new();
     filter = xs_dict_set(filter, "likes", xs_stock(likes_on ? XSTYPE_TRUE : XSTYPE_FALSE));
     filter = xs_dict_set(filter, "reacts", xs_stock(reacts_on ? XSTYPE_TRUE : XSTYPE_FALSE));
@@ -4324,6 +4325,7 @@ void notify_filter(snac *user, const xs_dict *p_vars)
     filter = xs_dict_set(filter, "blocks", xs_stock(blocks_on ? XSTYPE_TRUE : XSTYPE_FALSE));
     filter = xs_dict_set(filter, "polls", xs_stock(polls_on ? XSTYPE_TRUE : XSTYPE_FALSE));
     filter = xs_dict_set(filter, "webmentions", xs_stock(webmen_on ? XSTYPE_TRUE : XSTYPE_FALSE));
+    filter = xs_dict_set(filter, "cool_posts", xs_stock(cool_posts_on ? XSTYPE_TRUE : XSTYPE_FALSE));
     user->config = xs_dict_set(user->config, "notify_filter", filter);
     user->tz = xs_dict_get_def(user->config, "tz", "UTC"); // previous line invalidates user->tz
 }
@@ -4359,6 +4361,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
     int n_blocks_on = xs_is_true(xs_dict_get_def(n_filter, "blocks", n_def));
     int n_polls_on  = xs_is_true(xs_dict_get_def(n_filter, "polls", n_def));
     int n_webmen_on  = xs_is_true(xs_dict_get_def(n_filter, "webmentions", n_def));
+    int n_cool_posts_on  = xs_is_true(xs_dict_get_def(n_filter, "cool_posts", n_def));
 
     xs_html *html = xs_html_tag("html",
         html_user_head(user, NULL, NULL),
@@ -4386,6 +4389,7 @@ xs_str *html_notifications(snac *user, int skip, int show)
         html_checkbox("blocks_on", L("Blocks"), n_blocks_on),
         html_checkbox("polls_on", L("Polls"), n_polls_on),
         html_checkbox("webmentions_on", L("Webmentions"), n_webmen_on),
+        html_checkbox("cool_posts_on", L("Posts from cool users"), n_cool_posts_on),
         xs_html_sctag("input",
             xs_html_attr("type",     "submit"),
             xs_html_attr("class",    "button"),