summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2025-02-27 18:01:34 +0100
committerGravatar default2025-02-27 18:01:34 +0100
commit1cce6d86fa6b6828d395305c85b7d252ae53469f (patch)
treefc695381c9a61535ba977ff198be2b24413d751e /activitypub.c
parentMore hashtag block tweaks. (diff)
downloadpenes-snac2-1cce6d86fa6b6828d395305c85b7d252ae53469f.tar.gz
penes-snac2-1cce6d86fa6b6828d395305c85b7d252ae53469f.tar.xz
penes-snac2-1cce6d86fa6b6828d395305c85b7d252ae53469f.zip
Also check for blocked hashtags in timeline_request().
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/activitypub.c b/activitypub.c
index 960a2a1..1dedd17 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -329,6 +329,52 @@ xs_list *get_attachments(const xs_dict *msg)
329} 329}
330 330
331 331
332int hashtag_in_msg(const xs_list *hashtags, const xs_dict *msg)
333/* returns 1 if the message contains any of the list of hashtags */
334{
335 if (xs_is_list(hashtags) && xs_is_dict(msg)) {
336 const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
337
338 if (xs_is_list(tags_in_msg)) {
339 const xs_dict *te;
340
341 /* iterate the tags in the message */
342 xs_list_foreach(tags_in_msg, te) {
343 if (xs_is_dict(te)) {
344 const char *type = xs_dict_get(te, "type");
345 const char *name = xs_dict_get(te, "name");
346
347 if (xs_is_string(type) && xs_is_string(name)) {
348 if (strcmp(type, "Hashtag") == 0) {
349 xs *lc_name = xs_utf8_to_lower(name);
350
351 if (xs_list_in(hashtags, lc_name) != -1)
352 return 1;
353 }
354 }
355 }
356 }
357 }
358 }
359
360 return 0;
361}
362
363
364int followed_hashtag_check(snac *user, const xs_dict *msg)
365/* returns 1 if this message contains a hashtag followed by me */
366{
367 return hashtag_in_msg(xs_dict_get(user->config, "followed_hashtags"), msg);
368}
369
370
371int blocked_hashtag_check(snac *user, const xs_dict *msg)
372/* returns 1 if this message contains a hashtag blocked by me */
373{
374 return hashtag_in_msg(xs_dict_get(user->config, "blocked_hashtags"), msg);
375}
376
377
332int timeline_request(snac *snac, const char **id, xs_str **wrk, int level) 378int timeline_request(snac *snac, const char **id, xs_str **wrk, int level)
333/* ensures that an entry and its ancestors are in the timeline */ 379/* ensures that an entry and its ancestors are in the timeline */
334{ 380{
@@ -384,6 +430,9 @@ int timeline_request(snac *snac, const char **id, xs_str **wrk, int level)
384 if (xs_match(type, POSTLIKE_OBJECT_TYPE)) { 430 if (xs_match(type, POSTLIKE_OBJECT_TYPE)) {
385 if (content_match("filter_reject.txt", object)) 431 if (content_match("filter_reject.txt", object))
386 snac_log(snac, xs_fmt("timeline_request rejected by content %s", nid)); 432 snac_log(snac, xs_fmt("timeline_request rejected by content %s", nid));
433 else
434 if (blocked_hashtag_check(snac, object))
435 snac_log(snac, xs_fmt("timeline_request rejected by hashtag %s", nid));
387 else { 436 else {
388 const char *actor = get_atto(object); 437 const char *actor = get_atto(object);
389 438
@@ -587,45 +636,6 @@ int is_msg_from_private_user(const xs_dict *msg)
587} 636}
588 637
589 638
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 */
592{
593 if (xs_is_list(hashtags) && xs_is_dict(msg)) {
594 const xs_list *tags_in_msg = xs_dict_get(msg, "tag");
595
596 if (xs_is_list(tags_in_msg)) {
597 const xs_dict *te;
598
599 /* iterate the tags in the message */
600 xs_list_foreach(tags_in_msg, te) {
601 if (xs_is_dict(te)) {
602 const char *type = xs_dict_get(te, "type");
603 const char *name = xs_dict_get(te, "name");
604
605 if (xs_is_string(type) && xs_is_string(name)) {
606 if (strcmp(type, "Hashtag") == 0) {
607 xs *lc_name = xs_utf8_to_lower(name);
608
609 if (xs_list_in(hashtags, lc_name) != -1)
610 return 1;
611 }
612 }
613 }
614 }
615 }
616 }
617
618 return 0;
619}
620
621
622int followed_hashtag_check(snac *user, const xs_dict *msg)
623/* returns 1 if this message contains a hashtag followed by me */
624{
625 return hashtag_in_msg(xs_dict_get(user->config, "followed_hashtags"), msg);
626}
627
628
629void followed_hashtag_distribute(const xs_dict *msg) 639void followed_hashtag_distribute(const xs_dict *msg)
630/* distribute this post to all users following the included hashtags */ 640/* distribute this post to all users following the included hashtags */
631{ 641{
@@ -656,13 +666,6 @@ void followed_hashtag_distribute(const xs_dict *msg)
656} 666}
657 667
658 668
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
666int is_msg_for_me(snac *snac, const xs_dict *c_msg) 669int is_msg_for_me(snac *snac, const xs_dict *c_msg)
667/* checks if this message is for me */ 670/* checks if this message is for me */
668{ 671{
@@ -2352,9 +2355,6 @@ int process_input_message(snac *snac, const xs_dict *msg, const xs_dict *req)
2352 /* bring the actor */ 2355 /* bring the actor */
2353 xs *who_o = NULL; 2356 xs *who_o = NULL;
2354 2357
2355 if (blocked_hashtag_check(snac, a_msg))
2356 snac_debug(snac, 1, xs_fmt("blocked by hashtag %s", object));
2357 else
2358 if (valid_status(actor_request(snac, who, &who_o))) { 2358 if (valid_status(actor_request(snac, who, &who_o))) {
2359 /* don't account as such announces by our own relay */ 2359 /* don't account as such announces by our own relay */
2360 xs *this_relay = xs_fmt("%s/relay", srv_baseurl); 2360 xs *this_relay = xs_fmt("%s/relay", srv_baseurl);