summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2025-02-27 15:09:00 +0100
committerGravatar default2025-02-27 15:09:00 +0100
commit190d1d68db733fa71edc5e4ac4e1d23caaae5963 (patch)
treef6d4780ee61820df935f4f440db217cd03629d83
parentNew function hashtag_in_msg(). (diff)
downloadsnac2-190d1d68db733fa71edc5e4ac4e1d23caaae5963.tar.gz
snac2-190d1d68db733fa71edc5e4ac4e1d23caaae5963.tar.xz
snac2-190d1d68db733fa71edc5e4ac4e1d23caaae5963.zip
New function blocked_hashtag_check().
-rw-r--r--activitypub.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/activitypub.c b/activitypub.c
index 2813beb..a7b6c0b 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -590,7 +590,7 @@ int is_msg_from_private_user(const xs_dict *msg)
590int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg) 590int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg)
591/* returns 1 if the message contains any of the list of hashtags */ 591/* returns 1 if the message contains any of the list of hashtags */
592{ 592{
593 if (xs_is_list(hashtags)) { 593 if (xs_is_list(hashtags) && xs_is_dict(msg)) {
594 const xs_list *tags_in_msg = xs_dict_get(msg, "tag"); 594 const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
595 595
596 if (xs_is_list(tags_in_msg)) { 596 if (xs_is_list(tags_in_msg)) {
@@ -620,7 +620,7 @@ int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg)
620 620
621 621
622int followed_hashtag_check(snac *user, const xs_dict *msg) 622int followed_hashtag_check(snac *user, const xs_dict *msg)
623/* returns true if this message contains a hashtag followed by me */ 623/* returns 1 if this message contains a hashtag followed by me */
624{ 624{
625 return hashtag_in_msg(xs_dict_get(user->config, "followed_hashtags"), msg); 625 return hashtag_in_msg(xs_dict_get(user->config, "followed_hashtags"), msg);
626} 626}
@@ -656,6 +656,13 @@ void followed_hashtag_distribute(const xs_dict *msg)
656} 656}
657 657
658 658
659int blocked_hashtag_check(snac *user, const xs_dict *msg)
660/* returns 1 if this message contains a hashtag blocked by me */
661{
662 return hashtag_in_msg(xs_dict_get(user->config, "blocked_hashtags"), msg);
663}
664
665
659int is_msg_for_me(snac *snac, const xs_dict *c_msg) 666int is_msg_for_me(snac *snac, const xs_dict *c_msg)
660/* checks if this message is for me */ 667/* checks if this message is for me */
661{ 668{
@@ -678,23 +685,25 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
678 if (!xs_is_string(object)) 685 if (!xs_is_string(object))
679 return 0; 686 return 0;
680 687
688 xs *obj = NULL;
689 if (!valid_status(object_get(object, &obj)))
690 return 0;
691
681 /* if it's about one of our posts, accept it */ 692 /* if it's about one of our posts, accept it */
682 if (xs_startswith(object, snac->actor)) 693 if (xs_startswith(object, snac->actor))
683 return 2; 694 return 2;
684 695
696 /* blocked by hashtag? */
697 if (blocked_hashtag_check(snac, obj))
698 return 0;
699
685 /* if it's by someone we follow, accept it */ 700 /* if it's by someone we follow, accept it */
686 if (following_check(snac, actor)) 701 if (following_check(snac, actor))
687 return 1; 702 return 1;
688 703
689 /* do we follow any hashtag? */ 704 /* do we follow any hashtag? */
690 if (xs_is_list(xs_dict_get(snac->config, "followed_hashtags"))) { 705 if (followed_hashtag_check(snac, obj))
691 xs *obj = NULL; 706 return 7;
692
693 /* if the admired object contains any followed hashtag, accept it */
694 if (valid_status(object_get(object, &obj)) &&
695 followed_hashtag_check(snac, obj))
696 return 7;
697 }
698 707
699 return 0; 708 return 0;
700 } 709 }
@@ -726,13 +735,20 @@ int is_msg_for_me(snac *snac, const xs_dict *c_msg)
726 return 1; 735 return 1;
727 } 736 }
728 737
738 const xs_dict *msg = xs_dict_get(c_msg, "object");
739
740 /* any blocked hashtag? reject */
741 if (blocked_hashtag_check(snac, msg)) {
742 snac_debug(snac, 1, xs_fmt("blocked by hashtag %s", xs_dict_get(msg, "id")));
743 return 0;
744 }
745
729 int pub_msg = is_msg_public(c_msg); 746 int pub_msg = is_msg_public(c_msg);
730 747
731 /* if this message is public and we follow the actor of this post, allow */ 748 /* if this message is public and we follow the actor of this post, allow */
732 if (pub_msg && following_check(snac, actor)) 749 if (pub_msg && following_check(snac, actor))
733 return 1; 750 return 1;
734 751
735 const xs_dict *msg = xs_dict_get(c_msg, "object");
736 xs *rcpts = recipient_list(snac, msg, 0); 752 xs *rcpts = recipient_list(snac, msg, 0);
737 xs_list *p = rcpts; 753 xs_list *p = rcpts;
738 const xs_str *v; 754 const xs_str *v;