commit 1cce6d8
default
·
2025-02-27 17:01:34 +0000 UTC
parent 7cc984c
Also check for blocked hashtags in timeline_request().
1 files changed,
+49,
-49
+49,
-49
1@@ -329,6 +329,52 @@ xs_list *get_attachments(const xs_dict *msg)
2 }
3
4
5+int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg)
6+/* returns 1 if the message contains any of the list of hashtags */
7+{
8+ if (xs_is_list(hashtags) && xs_is_dict(msg)) {
9+ const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
10+
11+ if (xs_is_list(tags_in_msg)) {
12+ const xs_dict *te;
13+
14+ /* iterate the tags in the message */
15+ xs_list_foreach(tags_in_msg, te) {
16+ if (xs_is_dict(te)) {
17+ const char *type = xs_dict_get(te, "type");
18+ const char *name = xs_dict_get(te, "name");
19+
20+ if (xs_is_string(type) && xs_is_string(name)) {
21+ if (strcmp(type, "Hashtag") == 0) {
22+ xs *lc_name = xs_utf8_to_lower(name);
23+
24+ if (xs_list_in(hashtags, lc_name) != -1)
25+ return 1;
26+ }
27+ }
28+ }
29+ }
30+ }
31+ }
32+
33+ return 0;
34+}
35+
36+
37+int followed_hashtag_check(snac *user, const xs_dict *msg)
38+/* returns 1 if this message contains a hashtag followed by me */
39+{
40+ return hashtag_in_msg(xs_dict_get(user->config, "followed_hashtags"), msg);
41+}
42+
43+
44+int blocked_hashtag_check(snac *user, const xs_dict *msg)
45+/* returns 1 if this message contains a hashtag blocked by me */
46+{
47+ return hashtag_in_msg(xs_dict_get(user->config, "blocked_hashtags"), msg);
48+}
49+
50+
51 int timeline_request(snac *snac, const char **id, xs_str **wrk, int level)
52 /* ensures that an entry and its ancestors are in the timeline */
53 {
54@@ -384,6 +430,9 @@ int timeline_request(snac *snac, const char **id, xs_str **wrk, int level)
55 if (xs_match(type, POSTLIKE_OBJECT_TYPE)) {
56 if (content_match("filter_reject.txt", object))
57 snac_log(snac, xs_fmt("timeline_request rejected by content %s", nid));
58+ else
59+ if (blocked_hashtag_check(snac, object))
60+ snac_log(snac, xs_fmt("timeline_request rejected by hashtag %s", nid));
61 else {
62 const char *actor = get_atto(object);
63
64@@ -587,45 +636,6 @@ int is_msg_from_private_user(const xs_dict *msg)
65 }
66
67
68-int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg)
69-/* returns 1 if the message contains any of the list of hashtags */
70-{
71- if (xs_is_list(hashtags) && xs_is_dict(msg)) {
72- const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
73-
74- if (xs_is_list(tags_in_msg)) {
75- const xs_dict *te;
76-
77- /* iterate the tags in the message */
78- xs_list_foreach(tags_in_msg, te) {
79- if (xs_is_dict(te)) {
80- const char *type = xs_dict_get(te, "type");
81- const char *name = xs_dict_get(te, "name");
82-
83- if (xs_is_string(type) && xs_is_string(name)) {
84- if (strcmp(type, "Hashtag") == 0) {
85- xs *lc_name = xs_utf8_to_lower(name);
86-
87- if (xs_list_in(hashtags, lc_name) != -1)
88- return 1;
89- }
90- }
91- }
92- }
93- }
94- }
95-
96- return 0;
97-}
98-
99-
100-int followed_hashtag_check(snac *user, const xs_dict *msg)
101-/* returns 1 if this message contains a hashtag followed by me */
102-{
103- return hashtag_in_msg(xs_dict_get(user->config, "followed_hashtags"), msg);
104-}
105-
106-
107 void followed_hashtag_distribute(const xs_dict *msg)
108 /* distribute this post to all users following the included hashtags */
109 {
110@@ -656,13 +666,6 @@ void followed_hashtag_distribute(const xs_dict *msg)
111 }
112
113
114-int blocked_hashtag_check(snac *user, const xs_dict *msg)
115-/* returns 1 if this message contains a hashtag blocked by me */
116-{
117- return hashtag_in_msg(xs_dict_get(user->config, "blocked_hashtags"), msg);
118-}
119-
120-
121 int is_msg_for_me(snac *snac, const xs_dict *c_msg)
122 /* checks if this message is for me */
123 {
124@@ -2352,9 +2355,6 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
125 /* bring the actor */
126 xs *who_o = NULL;
127
128- if (blocked_hashtag_check(snac, a_msg))
129- snac_debug(snac, 1, xs_fmt("blocked by hashtag %s", object));
130- else
131 if (valid_status(actor_request(snac, who, &who_o))) {
132 /* don't account as such announces by our own relay */
133 xs *this_relay = xs_fmt("%s/relay", srv_baseurl);