From dcf5acaf538924aab532ea95bb311e4b80538856 Mon Sep 17 00:00:00 2001 From: byte Date: Sun, 14 Sep 2025 00:30:00 +0200 Subject: implementing visibility scopes --- mastoapi.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'mastoapi.c') diff --git a/mastoapi.c b/mastoapi.c index 568426b..ed46b89 100644 --- a/mastoapi.c +++ b/mastoapi.c @@ -884,8 +884,16 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) st = xs_dict_append(st, "content", s1); } - st = xs_dict_append(st, "visibility", - is_msg_public(msg) ? "public" : "private"); + /* determine visibility: https://docs.joinmastodon.org/entities/Status/#visibility */ + const int scope = get_msg_visibility(msg); + if (scope == SCOPE_PUBLIC) + st = xs_dict_append(st, "visibility", "public"); + else if (scope == SCOPE_FOLLOWERS) + st = xs_dict_append(st, "visibility", "private"); + else if (scope == SCOPE_MENTIONED) + st = xs_dict_append(st, "visibility", "direct"); + else if (scope == SCOPE_UNLISTED) + st = xs_dict_append(st, "visibility", "unlisted"); tmp = xs_dict_get(msg, "sensitive"); if (xs_is_null(tmp)) @@ -1767,7 +1775,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path, if (valid_status(timeline_get_by_md5(&snac2, v, &msg))) { /* add only posts by the author */ if (strcmp(xs_dict_get(msg, "type"), "Note") == 0 && - xs_startswith(xs_dict_get(msg, "id"), snac2.actor)) { + xs_startswith(xs_dict_get(msg, "id"), snac2.actor) && is_msg_public(msg)) { xs *st = mastoapi_status(&snac2, msg); if (st) @@ -2856,12 +2864,15 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, } /* prepare the message */ - int scope = 1; + int scope = SCOPE_MENTIONED; if (strcmp(visibility, "unlisted") == 0) - scope = 2; + scope = SCOPE_UNLISTED; else if (strcmp(visibility, "public") == 0) - scope = 0; + scope = SCOPE_PUBLIC; + else + if (strcmp(visibility, "private") == 0) + scope = SCOPE_FOLLOWERS; xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language, NULL); -- cgit v1.2.3