Some improvements to is_msg_for_me().

This commit is contained in:
default 2023-03-06 20:07:44 +01:00
parent b032e3d522
commit 946c29773a

View file

@ -289,31 +289,48 @@ int is_msg_public(snac *snac, xs_dict *msg)
} }
int is_msg_for_me(snac *snac, xs_dict *msg) int is_msg_for_me(snac *snac, xs_dict *c_msg)
/* checks if this message is for me */ /* checks if this message is for me */
{ {
int ret = 1; char *type = xs_dict_get(c_msg, "type");
char *type = xs_dict_get(msg, "type");
if (!xs_is_null(type) && strcmp(type, "Create") == 0) { /* if it's not a Create, allow */
xs *rcpts = recipient_list(snac, msg, 0); if (xs_is_null(type) || strcmp(type, "Create") != 0)
xs_list *p = rcpts; return 1;
xs_str *v;
while(xs_list_iter(&p, &v)) { xs_dict *msg = xs_dict_get(c_msg, "object");
/* explicitly for me? we're done */ xs *rcpts = recipient_list(snac, msg, 0);
if (strcmp(v, snac->actor) == 0) xs_list *p = rcpts;
goto done; xs_str *v;
}
/* if we're not following this fellow, then the answer is NO */ while(xs_list_iter(&p, &v)) {
char *actor = xs_dict_get(msg, "actor"); /* explicitly for me? we're done */
if (xs_is_null(actor) || !following_check(snac, actor)) if (strcmp(v, snac->actor) == 0)
ret = 0; return 2;
} }
done: /* accept if it's from someone we follow */
return ret; char *atto = xs_dict_get(msg, "attributedTo");
if (!xs_is_null(atto) && following_check(snac, atto))
return 3;
/* is this message a reply to another? */
char *irt = xs_dict_get(msg, "inReplyTo");
if (!xs_is_null(irt)) {
xs *r_msg = NULL;
/* try to get it */
if (valid_status(object_get(irt, &r_msg))) {
atto = xs_dict_get(r_msg, "attributedTo");
/* accept if the replied message is from someone we follow */
if (!xs_is_null(atto) && following_check(snac, atto))
return 4;
}
}
return 0;
} }
@ -921,7 +938,10 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
utype = "(null)"; utype = "(null)";
/* reject messages that are not for this user */ /* reject messages that are not for this user */
if (!is_msg_for_me(snac, msg)) { int d = is_msg_for_me(snac, msg);
snac_debug(snac, 0, xs_fmt("---> %s %d", xs_dict_get(msg, "id"), d));
if (!d) {
snac_debug(snac, 0, xs_fmt("message from %s not for us", actor)); snac_debug(snac, 0, xs_fmt("message from %s not for us", actor));
} }