diff options
| author | 2023-08-12 09:43:01 +0200 | |
|---|---|---|
| committer | 2023-08-12 09:43:01 +0200 | |
| commit | 499697258d2c266be69dc13dae96083fc78cd3ef (patch) | |
| tree | 9339a03de6c31cf4c30f4e6269815825fc561544 /activitypub.c | |
| 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.
Diffstat (limited to 'activitypub.c')
| -rw-r--r-- | activitypub.c | 31 |
1 files changed, 24 insertions, 7 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 | ||