commit ac663a6
default
·
2025-01-22 09:07:39 +0000 UTC
parent f5e75f9
Moved followed hashtag check to its own function.
1 files changed,
+36,
-24
+36,
-24
1@@ -587,6 +587,40 @@ int is_msg_from_private_user(const xs_dict *msg)
2 }
3
4
5+int followed_hashtag_check(snac *user, const xs_dict *msg)
6+/* returns true if this message contains a hashtag followed by me */
7+{
8+ const xs_list *fw_tags = xs_dict_get(user->config, "followed_hashtags");
9+
10+ if (xs_is_list(fw_tags)) {
11+ const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
12+
13+ if (xs_is_list(tags_in_msg)) {
14+ const xs_dict *te;
15+
16+ /* iterate the tags in the message */
17+ xs_list_foreach(tags_in_msg, te) {
18+ if (xs_is_dict(te)) {
19+ const char *type = xs_dict_get(te, "type");
20+ const char *name = xs_dict_get(te, "name");
21+
22+ if (xs_is_string(type) && xs_is_string(name)) {
23+ if (strcmp(type, "Hashtag") == 0) {
24+ xs *lc_name = xs_utf8_to_lower(name);
25+
26+ if (xs_list_in(fw_tags, lc_name) != -1)
27+ return 1;
28+ }
29+ }
30+ }
31+ }
32+ }
33+ }
34+
35+ return 0;
36+}
37+
38+
39 int is_msg_for_me(snac *snac, const xs_dict *c_msg)
40 /* checks if this message is for me */
41 {
42@@ -708,30 +742,8 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
43 }
44
45 /* does this message contain a tag we are following? */
46- const xs_list *fw_tags = xs_dict_get(snac->config, "followed_hashtags");
47- if (pub_msg && xs_type(fw_tags) == XSTYPE_LIST) {
48- const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
49- if (xs_type(tags_in_msg) == XSTYPE_LIST) {
50- const xs_dict *te;
51-
52- /* iterate the tags in the message */
53- xs_list_foreach(tags_in_msg, te) {
54- if (xs_type(te) == XSTYPE_DICT) {
55- const char *type = xs_dict_get(te, "type");
56- const char *name = xs_dict_get(te, "name");
57-
58- if (xs_type(type) == XSTYPE_STRING && xs_type(name) == XSTYPE_STRING) {
59- if (strcmp(type, "Hashtag") == 0) {
60- xs *lc_name = xs_utf8_to_lower(name);
61-
62- if (xs_list_in(fw_tags, lc_name) != -1)
63- return 7;
64- }
65- }
66- }
67- }
68- }
69- }
70+ if (pub_msg && followed_hashtag_check(snac, msg))
71+ return 7;
72
73 return 0;
74 }