mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Hide posts from the public web for accounts with 'private' == true.
This commit is contained in:
parent
8676d87299
commit
8524ace23f
3 changed files with 53 additions and 0 deletions
31
html.c
31
html.c
|
@ -1567,6 +1567,25 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int
|
||||||
if (!valid_status(status))
|
if (!valid_status(status))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* if it's an instance page, discard private users */
|
||||||
|
if (user == NULL) {
|
||||||
|
const char *atto = xs_dict_get(msg, "attributedTo");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
s = html_entry(user, s, msg, local, 0, v, user ? 0 : 1);
|
s = html_entry(user, s, msg, local, 0, v, user ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1940,6 +1959,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
|
||||||
show = atoi(v), cache = 0, save = 0;
|
show = atoi(v), cache = 0, save = 0;
|
||||||
|
|
||||||
if (p_path == NULL) { /** public timeline **/
|
if (p_path == NULL) { /** public timeline **/
|
||||||
|
if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
|
||||||
|
return 403;
|
||||||
|
|
||||||
xs *h = xs_str_localtime(0, "%Y-%m.html");
|
xs *h = xs_str_localtime(0, "%Y-%m.html");
|
||||||
|
|
||||||
if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) {
|
if (cache && history_mtime(&snac, h) > timeline_mtime(&snac)) {
|
||||||
|
@ -2022,6 +2044,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xs_startswith(p_path, "p/")) { /** a timeline with just one entry **/
|
if (xs_startswith(p_path, "p/")) { /** a timeline with just one entry **/
|
||||||
|
if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
|
||||||
|
return 403;
|
||||||
|
|
||||||
xs *id = xs_fmt("%s/%s", snac.actor, p_path);
|
xs *id = xs_fmt("%s/%s", snac.actor, p_path);
|
||||||
xs *msg = NULL;
|
xs *msg = NULL;
|
||||||
|
|
||||||
|
@ -2054,6 +2079,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (xs_startswith(p_path, "h/")) { /** an entry from the history **/
|
if (xs_startswith(p_path, "h/")) { /** an entry from the history **/
|
||||||
|
if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
|
||||||
|
return 403;
|
||||||
|
|
||||||
xs *l = xs_split(p_path, "/");
|
xs *l = xs_split(p_path, "/");
|
||||||
char *id = xs_list_get(l, 1);
|
char *id = xs_list_get(l, 1);
|
||||||
|
|
||||||
|
@ -2070,6 +2098,9 @@ int html_get_handler(const xs_dict *req, const char *q_path,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/
|
if (strcmp(p_path, ".rss") == 0) { /** public timeline in RSS format **/
|
||||||
|
if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
|
||||||
|
return 403;
|
||||||
|
|
||||||
xs_str *rss;
|
xs_str *rss;
|
||||||
xs *elems = timeline_simple_list(&snac, "public", 0, 20);
|
xs *elems = timeline_simple_list(&snac, "public", 0, 20);
|
||||||
xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
|
xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
|
||||||
|
|
3
httpd.c
3
httpd.c
|
@ -284,6 +284,9 @@ void httpd_connection(FILE *f)
|
||||||
status = 404;
|
status = 404;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (status == 403)
|
||||||
|
body = xs_str_new("<h1>403 Forbidden</h1>");
|
||||||
|
|
||||||
if (status == 404)
|
if (status == 404)
|
||||||
body = xs_str_new("<h1>404 Not Found</h1>");
|
body = xs_str_new("<h1>404 Not Found</h1>");
|
||||||
|
|
||||||
|
|
19
mastoapi.c
19
mastoapi.c
|
@ -1377,6 +1377,25 @@ 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 */
|
||||||
|
{
|
||||||
|
const char *atto = xs_dict_get(msg, "attributedTo");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/* 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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue