commit f485dbd
default
·
2024-03-12 16:54:54 +0000 UTC
parent 3a1d531
Added actor refreshing via the user queue.
5 files changed,
+63,
-8
+16,
-0
1@@ -2244,6 +2244,22 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2 if (strcmp(type, "verify_links") == 0) {
3 verify_links(snac);
4 }
5+ else
6+ if (strcmp(type, "actor_request") == 0) {
7+ const char *actor = xs_dict_get(q_item, "actor");
8+ double mtime = object_mtime(actor);
9+ double max_time = 3600.0 * 36.0;
10+
11+ if (mtime + max_time < (double) time(NULL)) {
12+ xs *actor_o = NULL;
13+ int status;
14+
15+ if (valid_status((status = activitypub_request(snac, actor, &actor_o))))
16+ actor_add(actor, actor_o);
17+
18+ snac_log(snac, xs_fmt("refresh actor %s %d", actor, status));
19+ }
20+ }
21 else
22 snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type));
23 }
M
data.c
+41,
-6
1@@ -797,6 +797,20 @@ double object_ctime(const char *id)
2 }
3
4
5+double object_mtime_by_md5(const char *md5)
6+{
7+ xs *fn = _object_fn_by_md5(md5, "object_mtime_by_md5");
8+ return mtime(fn);
9+}
10+
11+
12+double object_mtime(const char *id)
13+{
14+ xs *md5 = xs_md5_hex(id, strlen(id));
15+ return object_mtime_by_md5(md5);
16+}
17+
18+
19 xs_str *_object_index_fn(const char *id, const char *idxsfx)
20 /* returns the filename of an object's index */
21 {
22@@ -1552,7 +1566,6 @@ int actor_get(const char *actor, xs_dict **data)
23 else
24 d = xs_free(d);
25
26-#ifdef STALE_ACTORS
27 xs *fn = _object_fn(actor);
28 double max_time;
29
30@@ -1561,13 +1574,20 @@ int actor_get(const char *actor, xs_dict **data)
31
32 if (mtime(fn) + max_time < (double) time(NULL)) {
33 /* actor data exists but also stinks */
34-
35- /* touch the file */
36- utimes(fn, NULL);
37-
38 status = 205; /* "205: Reset Content" "110: Response Is Stale" */
39 }
40-#endif /* STALE_ACTORS */
41+
42+ return status;
43+}
44+
45+
46+int actor_get_refresh(snac *user, const char *actor, xs_dict **data)
47+/* gets an actor and requests and refresh if it's stale */
48+{
49+ int status = actor_get(actor, data);
50+
51+ if (status == 205)
52+ enqueue_actor_request(user, actor);
53
54 return status;
55 }
56@@ -2429,6 +2449,21 @@ void enqueue_verify_links(snac *user)
57 }
58
59
60+void enqueue_actor_request(snac *user, const char *actor)
61+/* enqueues an actor request */
62+{
63+ xs *qmsg = _new_qmsg("actor_request", "", 0);
64+ char *ntid = xs_dict_get(qmsg, "ntid");
65+ xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
66+
67+ qmsg = xs_dict_append(qmsg, "actor", actor);
68+
69+ qmsg = _enqueue_put(fn, qmsg);
70+
71+ snac_debug(user, 1, xs_fmt("enqueue_actor_request %s", user->actor));
72+}
73+
74+
75 void enqueue_request_replies(snac *user, const char *id)
76 /* enqueues a request for the replies of a message */
77 {
M
html.c
+1,
-1
1@@ -245,7 +245,7 @@ xs_html *html_msg_icon(snac *user, char *actor_id, const xs_dict *msg)
2 xs *actor = NULL;
3 xs_html *actor_icon = NULL;
4
5- if (actor_id && valid_status(actor_get(actor_id, &actor))) {
6+ if (actor_id && valid_status(actor_get_refresh(user, actor_id, &actor))) {
7 char *date = NULL;
8 char *udate = NULL;
9 char *url = NULL;
+1,
-1
1@@ -746,7 +746,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(get_atto(msg), &actor);
6+ actor_get_refresh(snac, get_atto(msg), &actor);
7
8 /* if the author is not here, discard */
9 if (actor == NULL)
M
snac.h
+4,
-0
1@@ -110,6 +110,8 @@ int object_del(const char *id);
2 int object_del_if_unref(const char *id);
3 double object_ctime_by_md5(const char *md5);
4 double object_ctime(const char *id);
5+double object_mtime_by_md5(const char *md5);
6+double object_mtime(const char *id);
7 int object_admire(const char *id, const char *actor, int like);
8 int object_unadmire(const char *id, const char *actor, int like);
9
10@@ -172,6 +174,7 @@ xs_list *tag_search(char *tag, int skip, int show);
11
12 int actor_add(const char *actor, xs_dict *msg);
13 int actor_get(const char *actor, xs_dict **data);
14+int actor_get_refresh(snac *user, const char *actor, xs_dict **data);
15
16 int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag);
17 void static_put(snac *snac, const char *id, const char *data, int size);
18@@ -218,6 +221,7 @@ void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_t
19 void enqueue_message(snac *snac, const xs_dict *msg);
20 void enqueue_close_question(snac *user, const char *id, int end_secs);
21 void enqueue_verify_links(snac *user);
22+void enqueue_actor_request(snac *user, const char *actor);
23 void enqueue_request_replies(snac *user, const char *id);
24 int was_question_voted(snac *user, const char *id);
25