commit e3e45b7
default
·
2023-03-06 13:28:53 +0000 UTC
parent 1152450
New function is_msg_for_me().
2 files changed,
+35,
-1
M
snac.h
+34,
-1
1@@ -289,6 +289,34 @@ int is_msg_public(snac *snac, xs_dict *msg)
2 }
3
4
5+int is_msg_for_me(snac *snac, xs_dict *msg)
6+/* checks if this message is for me */
7+{
8+ int ret = 1;
9+ char *type = xs_dict_get(msg, "type");
10+
11+ if (!xs_is_null(type) && strcmp(type, "Note") == 0) {
12+ xs *rcpts = recipient_list(snac, msg, 0);
13+ xs_list *p = rcpts;
14+ xs_str *v;
15+
16+ while(xs_list_iter(&p, &v)) {
17+ /* explicitly for me? we're done */
18+ if (strcmp(v, snac->actor) == 0)
19+ goto done;
20+ }
21+
22+ /* if we're not following this fellow, then the answer is NO */
23+ char *atto = xs_dict_get(msg, "attributedTo");
24+ if (xs_is_null(atto) || !following_check(snac, atto))
25+ ret = 0;
26+ }
27+
28+done:
29+ return ret;
30+}
31+
32+
33 void process_tags(snac *snac, const char *content, d_char **n_content, d_char **tag)
34 /* parses mentions and tags from content */
35 {
36@@ -874,7 +902,7 @@ void notify(snac *snac, xs_str *type, xs_str *utype, xs_str *actor, xs_dict *msg
37
38 /** queues **/
39
40-int process_input_message(snac *snac, char *msg, char *req)
41+int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
42 /* processes an ActivityPub message from the input queue */
43 {
44 /* actor and type exist, were checked previously */
45@@ -892,6 +920,11 @@ int process_input_message(snac *snac, char *msg, char *req)
46 else
47 utype = "(null)";
48
49+ /* reject messages that are not for this user */
50+ if (!is_msg_for_me(snac, msg)) {
51+ snac_debug(snac, 0, xs_fmt("message from %s not for us", actor));
52+ }
53+
54 /* bring the actor */
55 a_status = actor_request(snac, actor, &actor_o);
56
M
snac.h
+1,
-0
1@@ -195,6 +195,7 @@ int send_to_inbox(snac *snac, const xs_str *inbox, const xs_dict *msg,
2 d_char *get_actor_inbox(snac *snac, char *actor);
3 int send_to_actor(snac *snac, char *actor, char *msg, d_char **payload, int *p_size, int timeout);
4 int is_msg_public(snac *snac, xs_dict *msg);
5+int is_msg_for_me(snac *snac, xs_dict *msg);
6
7 int process_user_queue(snac *snac);
8 void process_queue_item(xs_dict *q_item);