diff options
| author | 2023-08-12 09:43:01 +0200 | |
|---|---|---|
| committer | 2023-08-12 09:43:01 +0200 | |
| commit | 499697258d2c266be69dc13dae96083fc78cd3ef (patch) | |
| tree | 9339a03de6c31cf4c30f4e6269815825fc561544 | |
| parent | Backport from xs. (diff) | |
| download | snac2-499697258d2c266be69dc13dae96083fc78cd3ef.tar.gz snac2-499697258d2c266be69dc13dae96083fc78cd3ef.tar.xz snac2-499697258d2c266be69dc13dae96083fc78cd3ef.zip | |
Rewritten is_msg_public() to not depend on a user.
| -rw-r--r-- | activitypub.c | 31 | ||||
| -rw-r--r-- | data.c | 2 | ||||
| -rw-r--r-- | html.c | 6 | ||||
| -rw-r--r-- | mastoapi.c | 2 | ||||
| -rw-r--r-- | snac.h | 2 |
5 files changed, 30 insertions, 13 deletions
diff --git a/activitypub.c b/activitypub.c index 7a08ceb..2c20e63 100644 --- a/activitypub.c +++ b/activitypub.c | |||
| @@ -408,12 +408,29 @@ xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public) | |||
| 408 | } | 408 | } |
| 409 | 409 | ||
| 410 | 410 | ||
| 411 | int is_msg_public(snac *snac, const xs_dict *msg) | 411 | int is_msg_public(const xs_dict *msg) |
| 412 | /* checks if a message is public */ | 412 | /* checks if a message is public */ |
| 413 | { | 413 | { |
| 414 | xs *rcpts = recipient_list(snac, msg, 0); | 414 | const char *to = xs_dict_get(msg, "to"); |
| 415 | const char *cc = xs_dict_get(msg, "cc"); | ||
| 416 | int n; | ||
| 417 | |||
| 418 | const char *lists[] = { to, cc, NULL }; | ||
| 419 | for (n = 0; lists[n]; n++) { | ||
| 420 | const xs_val *l = lists[n]; | ||
| 415 | 421 | ||
| 416 | return xs_list_in(rcpts, public_address) != -1; | 422 | if (xs_type(l) == XSTYPE_STRING) { |
| 423 | if (strcmp(l, public_address) == 0) | ||
| 424 | return 1; | ||
| 425 | } | ||
| 426 | else | ||
| 427 | if (xs_type(l) == XSTYPE_LIST) { | ||
| 428 | if (xs_list_in(l, public_address) != -1) | ||
| 429 | return 1; | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | return 0; | ||
| 417 | } | 434 | } |
| 418 | 435 | ||
| 419 | 436 | ||
| @@ -867,7 +884,7 @@ xs_dict *msg_admiration(snac *snac, char *object, char *type) | |||
| 867 | 884 | ||
| 868 | msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object); | 885 | msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object); |
| 869 | 886 | ||
| 870 | if (is_msg_public(snac, a_msg)) | 887 | if (is_msg_public(a_msg)) |
| 871 | rcpts = xs_list_append(rcpts, public_address); | 888 | rcpts = xs_list_append(rcpts, public_address); |
| 872 | 889 | ||
| 873 | rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); | 890 | rcpts = xs_list_append(rcpts, xs_dict_get(a_msg, "attributedTo")); |
| @@ -1097,7 +1114,7 @@ xs_dict *msg_note(snac *snac, const xs_str *content, const xs_val *rcpts, | |||
| 1097 | ctxt = xs_dup(v); | 1114 | ctxt = xs_dup(v); |
| 1098 | 1115 | ||
| 1099 | /* if this message is public, ours will also be */ | 1116 | /* if this message is public, ours will also be */ |
| 1100 | if (!priv && is_msg_public(snac, p_msg) && xs_list_in(to, public_address) == -1) | 1117 | if (!priv && is_msg_public(p_msg) && xs_list_in(to, public_address) == -1) |
| 1101 | to = xs_list_append(to, public_address); | 1118 | to = xs_list_append(to, public_address); |
| 1102 | } | 1119 | } |
| 1103 | 1120 | ||
| @@ -1419,7 +1436,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) | |||
| 1419 | 1436 | ||
| 1420 | /* if it's a DM from someone we don't follow, reject the message */ | 1437 | /* if it's a DM from someone we don't follow, reject the message */ |
| 1421 | if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) { | 1438 | if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) { |
| 1422 | if (strcmp(utype, "Note") == 0 && !is_msg_public(snac, msg) && | 1439 | if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) && |
| 1423 | !following_check(snac, actor)) { | 1440 | !following_check(snac, actor)) { |
| 1424 | snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor)); | 1441 | snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor)); |
| 1425 | 1442 | ||
| @@ -1726,7 +1743,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item) | |||
| 1726 | } | 1743 | } |
| 1727 | 1744 | ||
| 1728 | /* if it's public, send to the collected inboxes */ | 1745 | /* if it's public, send to the collected inboxes */ |
| 1729 | if (is_msg_public(snac, msg)) { | 1746 | if (is_msg_public(msg)) { |
| 1730 | xs *shibx = inbox_list(); | 1747 | xs *shibx = inbox_list(); |
| 1731 | xs_str *inbox; | 1748 | xs_str *inbox; |
| 1732 | 1749 | ||
| @@ -1041,7 +1041,7 @@ void timeline_update_indexes(snac *snac, const char *id) | |||
| 1041 | 1041 | ||
| 1042 | if (valid_status(object_get(id, &msg))) { | 1042 | if (valid_status(object_get(id, &msg))) { |
| 1043 | /* if its ours and is public, also store in public */ | 1043 | /* if its ours and is public, also store in public */ |
| 1044 | if (is_msg_public(snac, msg)) { | 1044 | if (is_msg_public(msg)) { |
| 1045 | object_user_cache_add(snac, id, "public"); | 1045 | object_user_cache_add(snac, id, "public"); |
| 1046 | 1046 | ||
| 1047 | /* also add it to the instance public timeline */ | 1047 | /* also add it to the instance public timeline */ |
| @@ -206,7 +206,7 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg) | |||
| 206 | if (strcmp(type, "Note") == 0 || strcmp(type, "Question") == 0 || strcmp(type, "Page") == 0) | 206 | if (strcmp(type, "Note") == 0 || strcmp(type, "Question") == 0 || strcmp(type, "Page") == 0) |
| 207 | url = xs_dict_get(msg, "id"); | 207 | url = xs_dict_get(msg, "id"); |
| 208 | 208 | ||
| 209 | priv = !is_msg_public(snac, msg); | 209 | priv = !is_msg_public(msg); |
| 210 | 210 | ||
| 211 | date = xs_dict_get(msg, "published"); | 211 | date = xs_dict_get(msg, "published"); |
| 212 | udate = xs_dict_get(msg, "updated"); | 212 | udate = xs_dict_get(msg, "updated"); |
| @@ -700,7 +700,7 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch | |||
| 700 | s = html_button(s, "pin", L("Pin"), L("Pin this post to the top of your timeline")); | 700 | s = html_button(s, "pin", L("Pin"), L("Pin this post to the top of your timeline")); |
| 701 | } | 701 | } |
| 702 | 702 | ||
| 703 | if (is_msg_public(snac, msg)) { | 703 | if (is_msg_public(msg)) { |
| 704 | if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) { | 704 | if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) { |
| 705 | /* not already boosted or us; add button */ | 705 | /* not already boosted or us; add button */ |
| 706 | s = html_button(s, "boost", L("Boost"), L("Announce this post to your followers")); | 706 | s = html_button(s, "boost", L("Boost"), L("Announce this post to your followers")); |
| @@ -845,7 +845,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local, | |||
| 845 | xs *boosts = NULL; | 845 | xs *boosts = NULL; |
| 846 | 846 | ||
| 847 | /* do not show non-public messages in the public timeline */ | 847 | /* do not show non-public messages in the public timeline */ |
| 848 | if (local && !is_msg_public(snac, msg)) | 848 | if (local && !is_msg_public(msg)) |
| 849 | return os; | 849 | return os; |
| 850 | 850 | ||
| 851 | /* hidden? do nothing more for this conversation */ | 851 | /* hidden? do nothing more for this conversation */ |
| @@ -658,7 +658,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg) | |||
| 658 | st = xs_dict_append(st, "content", xs_dict_get(msg, "content")); | 658 | st = xs_dict_append(st, "content", xs_dict_get(msg, "content")); |
| 659 | 659 | ||
| 660 | st = xs_dict_append(st, "visibility", | 660 | st = xs_dict_append(st, "visibility", |
| 661 | is_msg_public(snac, msg) ? "public" : "private"); | 661 | is_msg_public(msg) ? "public" : "private"); |
| 662 | 662 | ||
| 663 | tmp = xs_dict_get(msg, "sensitive"); | 663 | tmp = xs_dict_get(msg, "sensitive"); |
| 664 | if (xs_is_null(tmp)) | 664 | if (xs_is_null(tmp)) |
| @@ -242,7 +242,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg, | |||
| 242 | xs_str *get_actor_inbox(snac *snac, const char *actor); | 242 | xs_str *get_actor_inbox(snac *snac, const char *actor); |
| 243 | int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, | 243 | int send_to_actor(snac *snac, const char *actor, const xs_dict *msg, |
| 244 | xs_val **payload, int *p_size, int timeout); | 244 | xs_val **payload, int *p_size, int timeout); |
| 245 | int is_msg_public(snac *snac, const xs_dict *msg); | 245 | int is_msg_public(const xs_dict *msg); |
| 246 | int is_msg_for_me(snac *snac, const xs_dict *msg); | 246 | int is_msg_for_me(snac *snac, const xs_dict *msg); |
| 247 | 247 | ||
| 248 | int process_user_queue(snac *snac); | 248 | int process_user_queue(snac *snac); |