mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
New function is_msg_from_private_user().
This commit is contained in:
parent
151c5aa6ec
commit
0930ce726f
4 changed files with 35 additions and 36 deletions
|
@ -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)
|
int is_msg_for_me(snac *snac, const xs_dict *c_msg)
|
||||||
/* checks if this message is for me */
|
/* checks if this message is for me */
|
||||||
{
|
{
|
||||||
|
|
19
html.c
19
html.c
|
@ -1911,24 +1911,9 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
|
||||||
if (!valid_status(status))
|
if (!valid_status(status))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* if it's an instance page, discard private users */
|
/* if it's an instance page, discard messages from private users */
|
||||||
if (user == NULL && xs_startswith(xs_dict_get(msg, "id"), srv_baseurl)) {
|
if (user == NULL && is_msg_from_private_user(msg))
|
||||||
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;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1);
|
xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1);
|
||||||
|
|
||||||
|
|
23
mastoapi.c
23
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)
|
if (strcmp(type, "Note") != 0 && strcmp(type, "Question") != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* discard private users */
|
/* discard messages from private users */
|
||||||
{
|
if (is_msg_from_private_user(msg))
|
||||||
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;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
/* convert the Note into a Mastodon status */
|
/* convert the Note into a Mastodon status */
|
||||||
xs *st = mastoapi_status(user, msg);
|
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))
|
if (!is_msg_public(msg))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* discard messages from private users */
|
||||||
|
if (is_msg_from_private_user(msg))
|
||||||
|
continue;
|
||||||
|
|
||||||
/* convert the Note into a Mastodon status */
|
/* convert the Note into a Mastodon status */
|
||||||
xs *st = mastoapi_status(NULL, msg);
|
xs *st = mastoapi_status(NULL, msg);
|
||||||
|
|
||||||
|
|
1
snac.h
1
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,
|
int send_to_actor(snac *snac, const char *actor, const xs_dict *msg,
|
||||||
xs_val **payload, int *p_size, int timeout);
|
xs_val **payload, int *p_size, int timeout);
|
||||||
int is_msg_public(const xs_dict *msg);
|
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 is_msg_for_me(snac *snac, const xs_dict *msg);
|
||||||
|
|
||||||
int process_user_queue(snac *snac);
|
int process_user_queue(snac *snac);
|
||||||
|
|
Loading…
Reference in a new issue