commit 4996972
default
·
2023-08-12 07:43:01 +0000 UTC
parent b5cab5b
Rewritten is_msg_public() to not depend on a user.
5 files changed,
+30,
-13
+24,
-7
1@@ -408,12 +408,29 @@ xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public)
2 }
3
4
5-int is_msg_public(snac *snac, const xs_dict *msg)
6+int is_msg_public(const xs_dict *msg)
7 /* checks if a message is public */
8 {
9- xs *rcpts = recipient_list(snac, msg, 0);
10+ const char *to = xs_dict_get(msg, "to");
11+ const char *cc = xs_dict_get(msg, "cc");
12+ int n;
13+
14+ const char *lists[] = { to, cc, NULL };
15+ for (n = 0; lists[n]; n++) {
16+ const xs_val *l = lists[n];
17
18- return xs_list_in(rcpts, public_address) != -1;
19+ if (xs_type(l) == XSTYPE_STRING) {
20+ if (strcmp(l, public_address) == 0)
21+ return 1;
22+ }
23+ else
24+ if (xs_type(l) == XSTYPE_LIST) {
25+ if (xs_list_in(l, public_address) != -1)
26+ return 1;
27+ }
28+ }
29+
30+ return 0;
31 }
32
33
34@@ -867,7 +884,7 @@ xs_dict *msg_admiration(snac *snac, char *object, char *type)
35
36 msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object);
37
38- if (is_msg_public(snac, a_msg))
39+ if (is_msg_public(a_msg))
40 rcpts = xs_list_append(rcpts, public_address);
41
42 rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo"));
43@@ -1097,7 +1114,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts,
44 ctxt = xs_dup(v);
45
46 /* if this message is public, ours will also be */
47- if (!priv && is_msg_public(snac, p_msg) && xs_list_in(to, public_address) == -1)
48+ if (!priv && is_msg_public(p_msg) && xs_list_in(to, public_address) == -1)
49 to = xs_list_append(to, public_address);
50 }
51
52@@ -1419,7 +1436,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
53
54 /* if it's a DM from someone we don't follow, reject the message */
55 if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) {
56- if (strcmp(utype, "Note") == 0 && !is_msg_public(snac, msg) &&
57+ if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) &&
58 !following_check(snac, actor)) {
59 snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor));
60
61@@ -1726,7 +1743,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
62 }
63
64 /* if it's public, send to the collected inboxes */
65- if (is_msg_public(snac, msg)) {
66+ if (is_msg_public(msg)) {
67 xs *shibx = inbox_list();
68 xs_str *inbox;
69
M
data.c
+1,
-1
1@@ -1041,7 +1041,7 @@ void timeline_update_indexes(snac *snac, const char *id)
2
3 if (valid_status(object_get(id, &msg))) {
4 /* if its ours and is public, also store in public */
5- if (is_msg_public(snac, msg)) {
6+ if (is_msg_public(msg)) {
7 object_user_cache_add(snac, id, "public");
8
9 /* also add it to the instance public timeline */
M
html.c
+3,
-3
1@@ -206,7 +206,7 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
2 if (strcmp(type, "Note") == 0 || strcmp(type, "Question") == 0 || strcmp(type, "Page") == 0)
3 url = xs_dict_get(msg, "id");
4
5- priv = !is_msg_public(snac, msg);
6+ priv = !is_msg_public(msg);
7
8 date = xs_dict_get(msg, "published");
9 udate = xs_dict_get(msg, "updated");
10@@ -700,7 +700,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
11 s = html_button(s, "pin", L("Pin"), L("Pin this post to the top of your timeline"));
12 }
13
14- if (is_msg_public(snac, msg)) {
15+ if (is_msg_public(msg)) {
16 if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) {
17 /* not already boosted or us; add button */
18 s = html_button(s, "boost", L("Boost"), L("Announce this post to your followers"));
19@@ -845,7 +845,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
20 xs *boosts = NULL;
21
22 /* do not show non-public messages in the public timeline */
23- if (local && !is_msg_public(snac, msg))
24+ if (local && !is_msg_public(msg))
25 return os;
26
27 /* hidden? do nothing more for this conversation */
+1,
-1
1@@ -658,7 +658,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
2 st = xs_dict_append(st, "content", xs_dict_get(msg, "content"));
3
4 st = xs_dict_append(st, "visibility",
5- is_msg_public(snac, msg) ? "public" : "private");
6+ is_msg_public(msg) ? "public" : "private");
7
8 tmp = xs_dict_get(msg, "sensitive");
9 if (xs_is_null(tmp))
M
snac.h
+1,
-1
1@@ -242,7 +242,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg,
2 xs_str *get_actor_inbox(snac *snac, const char *actor);
3 int send_to_actor(snac *snac, const char *actor, const xs_dict *msg,
4 xs_val **payload, int *p_size, int timeout);
5-int is_msg_public(snac *snac, const xs_dict *msg);
6+int is_msg_public(const xs_dict *msg);
7 int is_msg_for_me(snac *snac, const xs_dict *msg);
8
9 int process_user_queue(snac *snac);