commit 946c297

default  ·  2023-03-06 19:07:44 +0000 UTC
parent b032e3d
Some improvements to is_msg_for_me().
1 files changed,  +39, -19
+39, -19
 1@@ -289,31 +289,48 @@ int is_msg_public(snac *snac, xs_dict *msg)
 2 }
 3 
 4 
 5-int is_msg_for_me(snac *snac, xs_dict *msg)
 6+int is_msg_for_me(snac *snac, xs_dict *c_msg)
 7 /* checks if this message is for me */
 8 {
 9-    int ret = 1;
10-    char *type = xs_dict_get(msg, "type");
11+    char *type = xs_dict_get(c_msg, "type");
12 
13-    if (!xs_is_null(type) && strcmp(type, "Create") == 0) {
14-        xs *rcpts = recipient_list(snac, msg, 0);
15-        xs_list *p = rcpts;
16-        xs_str *v;
17+    /* if it's not a Create, allow */
18+    if (xs_is_null(type) || strcmp(type, "Create") != 0)
19+        return 1;
20 
21-        while(xs_list_iter(&p, &v)) {
22-            /* explicitly for me? we're done */
23-            if (strcmp(v, snac->actor) == 0)
24-                goto done;
25-        }
26+    xs_dict *msg = xs_dict_get(c_msg, "object");
27+    xs *rcpts = recipient_list(snac, msg, 0);
28+    xs_list *p = rcpts;
29+    xs_str *v;
30+
31+    while(xs_list_iter(&p, &v)) {
32+        /* explicitly for me? we're done */
33+        if (strcmp(v, snac->actor) == 0)
34+            return 2;
35+    }
36 
37-        /* if we're not following this fellow, then the answer is NO */
38-        char *actor = xs_dict_get(msg, "actor");
39-        if (xs_is_null(actor) || !following_check(snac, actor))
40-            ret = 0;
41+    /* accept if it's from someone we follow */
42+    char *atto = xs_dict_get(msg, "attributedTo");
43+
44+    if (!xs_is_null(atto) && following_check(snac, atto))
45+        return 3;
46+
47+    /* is this message a reply to another? */
48+    char *irt = xs_dict_get(msg, "inReplyTo");
49+    if (!xs_is_null(irt)) {
50+        xs *r_msg = NULL;
51+
52+        /* try to get it */
53+        if (valid_status(object_get(irt, &r_msg))) {
54+            atto = xs_dict_get(r_msg, "attributedTo");
55+
56+            /* accept if the replied message is from someone we follow */
57+            if (!xs_is_null(atto) && following_check(snac, atto))
58+                return 4;
59+        }
60     }
61 
62-done:
63-    return ret;
64+    return 0;
65 }
66 
67 
68@@ -921,7 +938,10 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
69         utype = "(null)";
70 
71     /* reject messages that are not for this user */
72-    if (!is_msg_for_me(snac, msg)) {
73+    int d = is_msg_for_me(snac, msg);
74+    snac_debug(snac, 0, xs_fmt("---> %s %d", xs_dict_get(msg, "id"), d));
75+
76+    if (!d) {
77         snac_debug(snac, 0, xs_fmt("message from %s not for us", actor));
78     }
79