snac2

Fork of https://codeberg.org/grunfink/snac2
git clone https://git.inz.fi/snac2
Log | Files | Refs | README | LICENSE

commit ac663a6b4dd5eee1fb3c676524b8e141eb2529ed
parent f5e75f90058665f413e1535e8001ec5b4e0a7a19
Author: default <nobody@localhost>
Date:   Wed, 22 Jan 2025 10:07:39 +0100

Moved followed hashtag check to its own function.

Diffstat:
Mactivitypub.c | 60++++++++++++++++++++++++++++++++++++------------------------
1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/activitypub.c b/activitypub.c @@ -587,6 +587,40 @@ int is_msg_from_private_user(const xs_dict *msg) } +int followed_hashtag_check(snac *user, const xs_dict *msg) +/* returns true if this message contains a hashtag followed by me */ +{ + const xs_list *fw_tags = xs_dict_get(user->config, "followed_hashtags"); + + if (xs_is_list(fw_tags)) { + const xs_list *tags_in_msg = xs_dict_get(msg, "tag"); + + if (xs_is_list(tags_in_msg)) { + const xs_dict *te; + + /* iterate the tags in the message */ + xs_list_foreach(tags_in_msg, te) { + if (xs_is_dict(te)) { + const char *type = xs_dict_get(te, "type"); + const char *name = xs_dict_get(te, "name"); + + if (xs_is_string(type) && xs_is_string(name)) { + if (strcmp(type, "Hashtag") == 0) { + xs *lc_name = xs_utf8_to_lower(name); + + if (xs_list_in(fw_tags, lc_name) != -1) + return 1; + } + } + } + } + } + } + + return 0; +} + + int is_msg_for_me(snac *snac, const xs_dict *c_msg) /* checks if this message is for me */ { @@ -708,30 +742,8 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg) } /* does this message contain a tag we are following? */ - const xs_list *fw_tags = xs_dict_get(snac->config, "followed_hashtags"); - if (pub_msg && xs_type(fw_tags) == XSTYPE_LIST) { - const xs_list *tags_in_msg = xs_dict_get(msg, "tag"); - if (xs_type(tags_in_msg) == XSTYPE_LIST) { - const xs_dict *te; - - /* iterate the tags in the message */ - xs_list_foreach(tags_in_msg, te) { - if (xs_type(te) == XSTYPE_DICT) { - const char *type = xs_dict_get(te, "type"); - const char *name = xs_dict_get(te, "name"); - - if (xs_type(type) == XSTYPE_STRING && xs_type(name) == XSTYPE_STRING) { - if (strcmp(type, "Hashtag") == 0) { - xs *lc_name = xs_utf8_to_lower(name); - - if (xs_list_in(fw_tags, lc_name) != -1) - return 7; - } - } - } - } - } - } + if (pub_msg && followed_hashtag_check(snac, msg)) + return 7; return 0; }