commit 190d1d6

default  ·  2025-02-27 14:09:00 +0000 UTC
parent 771e987
New function blocked_hashtag_check().
1 files changed,  +27, -11
+27, -11
 1@@ -590,7 +590,7 @@ int is_msg_from_private_user(const xs_dict *msg)
 2 int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg)
 3 /* returns 1 if the message contains any of the list of hashtags */
 4 {
 5-    if (xs_is_list(hashtags)) {
 6+    if (xs_is_list(hashtags) && xs_is_dict(msg)) {
 7         const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
 8 
 9         if (xs_is_list(tags_in_msg)) {
10@@ -620,7 +620,7 @@ int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg)
11 
12 
13 int followed_hashtag_check(snac *user, const xs_dict *msg)
14-/* returns true if this message contains a hashtag followed by me */
15+/* returns 1 if this message contains a hashtag followed by me */
16 {
17     return hashtag_in_msg(xs_dict_get(user->config, "followed_hashtags"), msg);
18 }
19@@ -656,6 +656,13 @@ void followed_hashtag_distribute(const xs_dict *msg)
20 }
21 
22 
23+int blocked_hashtag_check(snac *user, const xs_dict *msg)
24+/* returns 1 if this message contains a hashtag blocked by me */
25+{
26+    return hashtag_in_msg(xs_dict_get(user->config, "blocked_hashtags"), msg);
27+}
28+
29+
30 int is_msg_for_me(snac *snac, const xs_dict *c_msg)
31 /* checks if this message is for me */
32 {
33@@ -678,23 +685,25 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
34         if (!xs_is_string(object))
35             return 0;
36 
37+        xs *obj = NULL;
38+        if (!valid_status(object_get(object, &obj)))
39+            return 0;
40+
41         /* if it's about one of our posts, accept it */
42         if (xs_startswith(object, snac->actor))
43             return 2;
44 
45+        /* blocked by hashtag? */
46+        if (blocked_hashtag_check(snac, obj))
47+            return 0;
48+
49         /* if it's by someone we follow, accept it */
50         if (following_check(snac, actor))
51             return 1;
52 
53         /* do we follow any hashtag? */
54-        if (xs_is_list(xs_dict_get(snac->config, "followed_hashtags"))) {
55-            xs *obj = NULL;
56-
57-            /* if the admired object contains any followed hashtag, accept it */
58-            if (valid_status(object_get(object, &obj)) &&
59-                followed_hashtag_check(snac, obj))
60-                return 7;
61-        }
62+        if (followed_hashtag_check(snac, obj))
63+            return 7;
64 
65         return 0;
66     }
67@@ -726,13 +735,20 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
68         return 1;
69     }
70 
71+    const xs_dict *msg = xs_dict_get(c_msg, "object");
72+
73+    /* any blocked hashtag? reject */
74+    if (blocked_hashtag_check(snac, msg)) {
75+        snac_debug(snac, 1, xs_fmt("blocked by hashtag %s", xs_dict_get(msg, "id")));
76+        return 0;
77+    }
78+
79     int pub_msg = is_msg_public(c_msg);
80 
81     /* if this message is public and we follow the actor of this post, allow */
82     if (pub_msg && following_check(snac, actor))
83         return 1;
84 
85-    const xs_dict *msg = xs_dict_get(c_msg, "object");
86     xs *rcpts = recipient_list(snac, msg, 0);
87     xs_list *p = rcpts;
88     const xs_str *v;