diff options
| author | 2024-02-10 09:08:09 +0100 | |
|---|---|---|
| committer | 2024-02-10 09:08:09 +0100 | |
| commit | 0930ce726fa5750eed4f1f53627428dab0944f1a (patch) | |
| tree | 108b4d8b29f20b418c289777e81fbde5a2821477 | |
| parent | mastoapi: Skip non-public posts from timelines by tag. (diff) | |
| download | penes-snac2-0930ce726fa5750eed4f1f53627428dab0944f1a.tar.gz penes-snac2-0930ce726fa5750eed4f1f53627428dab0944f1a.tar.xz penes-snac2-0930ce726fa5750eed4f1f53627428dab0944f1a.zip | |
New function is_msg_from_private_user().
| -rw-r--r-- | activitypub.c | 24 | ||||
| -rw-r--r-- | html.c | 21 | ||||
| -rw-r--r-- | mastoapi.c | 25 | ||||
| -rw-r--r-- | snac.h | 1 |
4 files changed, 35 insertions, 36 deletions
diff --git a/activitypub.c b/activitypub.c index df4877b..9893470 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -593,6 +593,30 @@ int is_msg_public(const xs_dict *msg) | |||
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | 595 | ||
| 596 | int is_msg_from_private_user(const xs_dict *msg) | ||
| 597 | /* checks if a message is from a local, private user */ | ||
| 598 | { | ||
| 599 | int ret = 0; | ||
| 600 | |||
| 601 | /* is this message from a local user? */ | ||
| 602 | if (xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) { | ||
| 603 | const char *atto = get_atto(msg); | ||
| 604 | xs *l = xs_split(atto, "/"); | ||
| 605 | const char *uid = xs_list_get(l, -1); | ||
| 606 | snac user; | ||
| 607 | |||
| 608 | if (uid && user_open(&user, uid)) { | ||
| 609 | if (xs_type(xs_dict_get(user.config, "private")) == XSTYPE_TRUE) | ||
| 610 | ret = 1; | ||
| 611 | |||
| 612 | user_free(&user); | ||
| 613 | } | ||
| 614 | } | ||
| 615 | |||
| 616 | return ret; | ||
| 617 | } | ||
| 618 | |||
| 619 | |||
| 596 | int is_msg_for_me(snac *snac, const xs_dict *c_msg) | 620 | int is_msg_for_me(snac *snac, const xs_dict *c_msg) |
| 597 | /* checks if this message is for me */ | 621 | /* checks if this message is for me */ |
| 598 | { | 622 | { |
| @@ -1911,24 +1911,9 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, | |||
| 1911 | if (!valid_status(status)) | 1911 | if (!valid_status(status)) |
| 1912 | continue; | 1912 | continue; |
| 1913 | 1913 | ||
| 1914 | /* if it's an instance page, discard private users */ | 1914 | /* if it's an instance page, discard messages from private users */ |
| 1915 | if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) { | 1915 | if (user == NULL && is_msg_from_private_user(msg)) |
| 1916 | const char *atto = get_atto(msg); | 1916 | continue; |
| 1917 | xs *l = xs_split(atto, "/"); | ||
| 1918 | const char *uid = xs_list_get(l, -1); | ||
| 1919 | snac user; | ||
| 1920 | int skip = 1; | ||
| 1921 | |||
| 1922 | if (uid && user_open(&user, uid)) { | ||
| 1923 | if (xs_type(xs_dict_get(user.config, "private")) != XSTYPE_TRUE) | ||
| 1924 | skip = 0; | ||
| 1925 | |||
| 1926 | user_free(&user); | ||
| 1927 | } | ||
| 1928 | |||
| 1929 | if (skip) | ||
| 1930 | continue; | ||
| 1931 | } | ||
| 1932 | 1917 | ||
| 1933 | xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1); | 1918 | xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1); |
| 1934 | 1919 | ||
| @@ -1500,24 +1500,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1500 | if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) | 1500 | if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) |
| 1501 | continue; | 1501 | continue; |
| 1502 | 1502 | ||
| 1503 | /* discard private users */ | 1503 | /* discard messages from private users */ |
| 1504 | { | 1504 | if (is_msg_from_private_user(msg)) |
| 1505 | const char *atto = get_atto(msg); | 1505 | continue; |
| 1506 | xs *l = xs_split(atto, "/"); | ||
| 1507 | const char *uid = xs_list_get(l, -1); | ||
| 1508 | snac p_user; | ||
| 1509 | int skip = 1; | ||
| 1510 | |||
| 1511 | if (uid && user_open(&p_user, uid)) { | ||
| 1512 | if (xs_type(xs_dict_get(p_user.config, "private")) != XSTYPE_TRUE) | ||
| 1513 | skip = 0; | ||
| 1514 | |||
| 1515 | user_free(&p_user); | ||
| 1516 | } | ||
| 1517 | |||
| 1518 | if (skip) | ||
| 1519 | continue; | ||
| 1520 | } | ||
| 1521 | 1506 | ||
| 1522 | /* convert the Note into a Mastodon status */ | 1507 | /* convert the Note into a Mastodon status */ |
| 1523 | xs *st = mastoapi_status(user, msg); | 1508 | xs *st = mastoapi_status(user, msg); |
| @@ -1564,6 +1549,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, | |||
| 1564 | if (!is_msg_public(msg)) | 1549 | if (!is_msg_public(msg)) |
| 1565 | continue; | 1550 | continue; |
| 1566 | 1551 | ||
| 1552 | /* discard messages from private users */ | ||
| 1553 | if (is_msg_from_private_user(msg)) | ||
| 1554 | continue; | ||
| 1555 | |||
| 1567 | /* convert the Note into a Mastodon status */ | 1556 | /* convert the Note into a Mastodon status */ |
| 1568 | xs *st = mastoapi_status(NULL, msg); | 1557 | xs *st = mastoapi_status(NULL, msg); |
| 1569 | 1558 | ||
| @@ -277,6 +277,7 @@ xs_str *get_actor_inbox(const char *actor); | |||
| 277 | int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, | 277 | int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, |
| 278 | xs_val **payload, int *p_size, int timeout); | 278 | xs_val **payload, int *p_size, int timeout); |
| 279 | int is_msg_public(const xs_dict *msg); | 279 | int is_msg_public(const xs_dict *msg); |
| 280 | int is_msg_from_private_user(const xs_dict *msg); | ||
| 280 | int is_msg_for_me(snac *snac, const xs_dict *msg); | 281 | int is_msg_for_me(snac *snac, const xs_dict *msg); |
| 281 | 282 | ||
| 282 | int process_user_queue(snac *snac); | 283 | int process_user_queue(snac *snac); |