commit cac1c6f

default  ·  2023-08-12 09:23:01 +0000 UTC
parent 4996972
Rewritten actor_get() to not depend on a user.
5 files changed,  +12, -20
M data.c
M html.c
M snac.h
+1, -1
1@@ -117,7 +117,7 @@ int actor_request(snac *snac, const char *actor, xs_dict **data)
2         *data = NULL;
3 
4     /* get from disk first */
5-    status = actor_get(snac, actor, data);
6+    status = actor_get(actor, data);
7 
8     if (status != 200) {
9         /* actor data non-existent or stale: get from the net */
M data.c
+1, -9
 1@@ -1439,20 +1439,12 @@ int actor_add(const char *actor, xs_dict *msg)
 2 }
 3 
 4 
 5-int actor_get(snac *snac1, const char *actor, xs_dict **data)
 6+int actor_get(const char *actor, xs_dict **data)
 7 /* returns an already downloaded actor */
 8 {
 9     int status = 200;
10     xs_dict *d = NULL;
11 
12-    if (strcmp(actor, snac1->actor) == 0) {
13-        /* this actor */
14-        if (data)
15-            *data = msg_actor(snac1);
16-
17-        return status;
18-    }
19-
20     if (xs_startswith(actor, srv_baseurl)) {
21         /* it's a (possible) local user */
22         xs *l = xs_split(actor, "/");
M html.c
+7, -7
 1@@ -188,7 +188,7 @@ xs_str *html_actor_icon(xs_str *os, char *actor,
 2 }
 3 
 4 
 5-xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
 6+xs_str *html_msg_icon(xs_str *os, const xs_dict *msg)
 7 {
 8     char *actor_id;
 9     xs *actor = NULL;
10@@ -196,7 +196,7 @@ xs_str *html_msg_icon(snac *snac, xs_str *os, const xs_dict *msg)
11     if ((actor_id = xs_dict_get(msg, "attributedTo")) == NULL)
12         actor_id = xs_dict_get(msg, "actor");
13 
14-    if (actor_id && valid_status(actor_get(snac, actor_id, &actor))) {
15+    if (actor_id && valid_status(actor_get(actor_id, &actor))) {
16         char *date  = NULL;
17         char *udate = NULL;
18         char *url   = NULL;
19@@ -870,7 +870,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
20         xs *s1 = xs_fmt("<div class=\"snac-origin\">%s</div>\n", L("follows you"));
21         s = xs_str_cat(s, s1);
22 
23-        s = html_msg_icon(snac, s, msg);
24+        s = html_msg_icon(s, msg);
25 
26         s = xs_str_cat(s, "</div>\n</div>\n");
27 
28@@ -894,7 +894,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
29     if (is_muted(snac, actor))
30         return os;
31 
32-    if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(snac, actor, NULL)))
33+    if (strcmp(actor, snac->actor) != 0 && !valid_status(actor_get(actor, NULL)))
34         return os;
35 
36     if (level == 0)
37@@ -990,7 +990,7 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
38         }
39     }
40 
41-    s = html_msg_icon(snac, s, msg);
42+    s = html_msg_icon(s, msg);
43 
44     /* add the content */
45     s = xs_str_cat(s, "</div>\n<div class=\"e-content snac-content\">\n"); /** **/
46@@ -1450,7 +1450,7 @@ xs_str *html_people_list(snac *snac, xs_str *os, xs_list *list, const char *head
47         xs *md5 = xs_md5_hex(actor_id, strlen(actor_id));
48         xs *actor = NULL;
49 
50-        if (valid_status(actor_get(snac, actor_id, &actor))) {
51+        if (valid_status(actor_get(actor_id, &actor))) {
52             s = xs_str_cat(s, "<div class=\"snac-post\">\n<div class=\"snac-post-header\">\n");
53 
54             s = html_actor_icon(s, actor, xs_dict_get(actor, "published"), NULL, NULL, 0);
55@@ -1608,7 +1608,7 @@ xs_str *html_notifications(snac *snac)
56         const char *actor_id = xs_dict_get(noti, "actor");
57         xs *actor = NULL;
58 
59-        if (!valid_status(actor_get(snac, actor_id, &actor)))
60+        if (!valid_status(actor_get(actor_id, &actor)))
61             continue;
62 
63         xs *a_name = actor_name(actor);
+2, -2
 1@@ -632,7 +632,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
 2 /* converts an ActivityPub note to a Mastodon status */
 3 {
 4     xs *actor = NULL;
 5-    actor_get(snac, xs_dict_get(msg, "attributedTo"), &actor);
 6+    actor_get(xs_dict_get(msg, "attributedTo"), &actor);
 7 
 8     /* if the author is not here, discard */
 9     if (actor == NULL)
10@@ -1310,7 +1310,7 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
11                 xs *actor = NULL;
12                 xs *entry = NULL;
13 
14-                if (!valid_status(actor_get(&snac1, xs_dict_get(noti, "actor"), &actor)))
15+                if (!valid_status(actor_get(xs_dict_get(noti, "actor"), &actor)))
16                     continue;
17 
18                 if (objid != NULL && !valid_status(object_get(objid, &entry)))
M snac.h
+1, -1
1@@ -141,7 +141,7 @@ void hide(snac *snac, const char *id);
2 int is_hidden(snac *snac, const char *id);
3 
4 int actor_add(const char *actor, xs_dict *msg);
5-int actor_get(snac *snac, const char *actor, xs_dict **data);
6+int actor_get(const char *actor, xs_dict **data);
7 
8 int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag);
9 void static_put(snac *snac, const char *id, const char *data, int size);