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 */ { diff --git a/html.c b/html.c index 5f3dead..a340a96 100644 --- a/html.c +++ b/html.c @@ -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); diff --git a/mastoapi.c b/mastoapi.c index 000bdea..e2b7bba 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -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); diff --git a/snac.h b/snac.h index cf2cf38..fd79a9d 100644 --- a/snac.h +++ b/snac.h @@ -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);