mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-26 01:03:37 +00:00
Rewritten is_msg_public() to not depend on a user.
This commit is contained in:
parent
b5cab5bddd
commit
499697258d
5 changed files with 30 additions and 13 deletions
|
@ -408,12 +408,29 @@ xs_list *recipient_list(snac *snac, const xs_dict *msg, int expand_public)
|
|||
}
|
||||
|
||||
|
||||
int is_msg_public(snac *snac, const xs_dict *msg)
|
||||
int is_msg_public(const xs_dict *msg)
|
||||
/* checks if a message is public */
|
||||
{
|
||||
xs *rcpts = recipient_list(snac, msg, 0);
|
||||
const char *to = xs_dict_get(msg, "to");
|
||||
const char *cc = xs_dict_get(msg, "cc");
|
||||
int n;
|
||||
|
||||
return xs_list_in(rcpts, public_address) != -1;
|
||||
const char *lists[] = { to, cc, NULL };
|
||||
for (n = 0; lists[n]; n++) {
|
||||
const xs_val *l = lists[n];
|
||||
|
||||
if (xs_type(l) == XSTYPE_STRING) {
|
||||
if (strcmp(l, public_address) == 0)
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
if (xs_type(l) == XSTYPE_LIST) {
|
||||
if (xs_list_in(l, public_address) != -1)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -867,7 +884,7 @@ xs_dict *msg_admiration(snac *snac, char *object, char *type)
|
|||
|
||||
msg = msg_base(snac, type, "@dummy", snac->actor, "@now", object);
|
||||
|
||||
if (is_msg_public(snac, a_msg))
|
||||
if (is_msg_public(a_msg))
|
||||
rcpts = xs_list_append(rcpts, public_address);
|
||||
|
||||
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,
|
|||
ctxt = xs_dup(v);
|
||||
|
||||
/* if this message is public, ours will also be */
|
||||
if (!priv && is_msg_public(snac, p_msg) && xs_list_in(to, public_address) == -1)
|
||||
if (!priv && is_msg_public(p_msg) && xs_list_in(to, public_address) == -1)
|
||||
to = xs_list_append(to, public_address);
|
||||
}
|
||||
|
||||
|
@ -1419,7 +1436,7 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
|
|||
|
||||
/* if it's a DM from someone we don't follow, reject the message */
|
||||
if (xs_type(xs_dict_get(snac->config, "drop_dm_from_unknown")) == XSTYPE_TRUE) {
|
||||
if (strcmp(utype, "Note") == 0 && !is_msg_public(snac, msg) &&
|
||||
if (strcmp(utype, "Note") == 0 && !is_msg_public(msg) &&
|
||||
!following_check(snac, actor)) {
|
||||
snac_log(snac, xs_fmt("DM rejected from unknown actor %s", actor));
|
||||
|
||||
|
@ -1726,7 +1743,7 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
|
|||
}
|
||||
|
||||
/* if it's public, send to the collected inboxes */
|
||||
if (is_msg_public(snac, msg)) {
|
||||
if (is_msg_public(msg)) {
|
||||
xs *shibx = inbox_list();
|
||||
xs_str *inbox;
|
||||
|
||||
|
|
2
data.c
2
data.c
|
@ -1041,7 +1041,7 @@ void timeline_update_indexes(snac *snac, const char *id)
|
|||
|
||||
if (valid_status(object_get(id, &msg))) {
|
||||
/* if its ours and is public, also store in public */
|
||||
if (is_msg_public(snac, msg)) {
|
||||
if (is_msg_public(msg)) {
|
||||
object_user_cache_add(snac, id, "public");
|
||||
|
||||
/* also add it to the instance public timeline */
|
||||
|
|
6
html.c
6
html.c
|
@ -206,7 +206,7 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
|
|||
if (strcmp(type, "Note") == 0 || strcmp(type, "Question") == 0 || strcmp(type, "Page") == 0)
|
||||
url = xs_dict_get(msg, "id");
|
||||
|
||||
priv = !is_msg_public(snac, msg);
|
||||
priv = !is_msg_public(msg);
|
||||
|
||||
date = xs_dict_get(msg, "published");
|
||||
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
|
|||
s = html_button(s, "pin", L("Pin"), L("Pin this post to the top of your timeline"));
|
||||
}
|
||||
|
||||
if (is_msg_public(snac, msg)) {
|
||||
if (is_msg_public(msg)) {
|
||||
if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) {
|
||||
/* not already boosted or us; add button */
|
||||
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,
|
|||
xs *boosts = NULL;
|
||||
|
||||
/* do not show non-public messages in the public timeline */
|
||||
if (local && !is_msg_public(snac, msg))
|
||||
if (local && !is_msg_public(msg))
|
||||
return os;
|
||||
|
||||
/* hidden? do nothing more for this conversation */
|
||||
|
|
|
@ -658,7 +658,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
|
|||
st = xs_dict_append(st, "content", xs_dict_get(msg, "content"));
|
||||
|
||||
st = xs_dict_append(st, "visibility",
|
||||
is_msg_public(snac, msg) ? "public" : "private");
|
||||
is_msg_public(msg) ? "public" : "private");
|
||||
|
||||
tmp = xs_dict_get(msg, "sensitive");
|
||||
if (xs_is_null(tmp))
|
||||
|
|
2
snac.h
2
snac.h
|
@ -242,7 +242,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg,
|
|||
xs_str *get_actor_inbox(snac *snac, const char *actor);
|
||||
int send_to_actor(snac *snac, const char *actor, const xs_dict *msg,
|
||||
xs_val **payload, int *p_size, int timeout);
|
||||
int is_msg_public(snac *snac, const xs_dict *msg);
|
||||
int is_msg_public(const xs_dict *msg);
|
||||
int is_msg_for_me(snac *snac, const xs_dict *msg);
|
||||
|
||||
int process_user_queue(snac *snac);
|
||||
|
|
Loading…
Reference in a new issue