diff options
author | default <nobody@localhost> | 2024-02-10 09:08:09 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2024-02-10 09:08:09 +0100 |
commit | 0930ce726fa5750eed4f1f53627428dab0944f1a (patch) | |
tree | 108b4d8b29f20b418c289777e81fbde5a2821477 | |
parent | 151c5aa6ec4fb0f3b0e0d8ca62f9dc5ad27b14e0 (diff) |
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) } +int is_msg_from_private_user(const xs_dict *msg) +/* checks if a message is from a local, private user */ +{ + int ret = 0; + + /* is this message from a local user? */ + if (xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) { + const char *atto = get_atto(msg); + xs *l = xs_split(atto, "/"); + const char *uid = xs_list_get(l, -1); + snac user; + + if (uid && user_open(&user, uid)) { + if (xs_type(xs_dict_get(user.config, "private")) == XSTYPE_TRUE) + ret = 1; + + user_free(&user); + } + } + + return ret; +} + + int is_msg_for_me(snac *snac, const xs_dict *c_msg) /* checks if this message is for me */ { @@ -1911,24 +1911,9 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, if (!valid_status(status)) continue; - /* if it's an instance page, discard private users */ - if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) { - const char *atto = get_atto(msg); - xs *l = xs_split(atto, "/"); - const char *uid = xs_list_get(l, -1); - snac user; - int skip = 1; - - if (uid && user_open(&user, uid)) { - if (xs_type(xs_dict_get(user.config, "private")) != XSTYPE_TRUE) - skip = 0; - - user_free(&user); - } - - if (skip) - continue; - } + /* if it's an instance page, discard messages from private users */ + if (user == NULL && is_msg_from_private_user(msg)) + continue; xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1); @@ -1500,24 +1500,9 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0) continue; - /* discard private users */ - { - const char *atto = get_atto(msg); - xs *l = xs_split(atto, "/"); - const char *uid = xs_list_get(l, -1); - snac p_user; - int skip = 1; - - if (uid && user_open(&p_user, uid)) { - if (xs_type(xs_dict_get(p_user.config, "private")) != XSTYPE_TRUE) - skip = 0; - - user_free(&p_user); - } - - if (skip) - continue; - } + /* discard messages from private users */ + if (is_msg_from_private_user(msg)) + continue; /* convert the Note into a Mastodon status */ xs *st = mastoapi_status(user, msg); @@ -1564,6 +1549,10 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (!is_msg_public(msg)) continue; + /* discard messages from private users */ + if (is_msg_from_private_user(msg)) + continue; + /* convert the Note into a Mastodon status */ xs *st = mastoapi_status(NULL, msg); @@ -277,6 +277,7 @@ xs_str *get_actor_inbox(const char *actor); int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, xs_val **payload, int *p_size, int timeout); int is_msg_public(const xs_dict *msg); +int is_msg_from_private_user(const xs_dict *msg); int is_msg_for_me(snac *snac, const xs_dict *msg); int process_user_queue(snac *snac); |