summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2024-03-12 17:54:54 +0100
committerGravatar default2024-03-12 17:54:54 +0100
commitf485dbdaf0f6372b9815be3d78ae2839e80d6946 (patch)
treeb7ddb23b52f9a199fd38f85168f46119fb4ff757
parentUpdated documentation. (diff)
downloadsnac2-f485dbdaf0f6372b9815be3d78ae2839e80d6946.tar.gz
snac2-f485dbdaf0f6372b9815be3d78ae2839e80d6946.tar.xz
snac2-f485dbdaf0f6372b9815be3d78ae2839e80d6946.zip
Added actor refreshing via the user queue.
-rw-r--r--activitypub.c16
-rw-r--r--data.c47
-rw-r--r--html.c2
-rw-r--r--mastoapi.c2
-rw-r--r--snac.h4
5 files changed, 63 insertions, 8 deletions
diff --git a/activitypub.c b/activitypub.c
index b6a07c9..08f79ed 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -2245,6 +2245,22 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
2245 verify_links(snac); 2245 verify_links(snac);
2246 } 2246 }
2247 else 2247 else
2248 if (strcmp(type, "actor_request") == 0) {
2249 const char *actor = xs_dict_get(q_item, "actor");
2250 double mtime = object_mtime(actor);
2251 double max_time = 3600.0 * 36.0;
2252
2253 if (mtime + max_time < (double) time(NULL)) {
2254 xs *actor_o = NULL;
2255 int status;
2256
2257 if (valid_status((status = activitypub_request(snac, actor, &actor_o))))
2258 actor_add(actor, actor_o);
2259
2260 snac_log(snac, xs_fmt("refresh actor %s %d", actor, status));
2261 }
2262 }
2263 else
2248 snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type)); 2264 snac_log(snac, xs_fmt("unexpected user q_item type '%s'", type));
2249} 2265}
2250 2266
diff --git a/data.c b/data.c
index 44ce628..77d81d5 100644
--- a/data.c
+++ b/data.c
@@ -797,6 +797,20 @@ double object_ctime(const char *id)
797} 797}
798 798
799 799
800double object_mtime_by_md5(const char *md5)
801{
802 xs *fn = _object_fn_by_md5(md5, "object_mtime_by_md5");
803 return mtime(fn);
804}
805
806
807double object_mtime(const char *id)
808{
809 xs *md5 = xs_md5_hex(id, strlen(id));
810 return object_mtime_by_md5(md5);
811}
812
813
800xs_str *_object_index_fn(const char *id, const char *idxsfx) 814xs_str *_object_index_fn(const char *id, const char *idxsfx)
801/* returns the filename of an object's index */ 815/* returns the filename of an object's index */
802{ 816{
@@ -1552,7 +1566,6 @@ int actor_get(const char *actor, xs_dict **data)
1552 else 1566 else
1553 d = xs_free(d); 1567 d = xs_free(d);
1554 1568
1555#ifdef STALE_ACTORS
1556 xs *fn = _object_fn(actor); 1569 xs *fn = _object_fn(actor);
1557 double max_time; 1570 double max_time;
1558 1571
@@ -1561,13 +1574,20 @@ int actor_get(const char *actor, xs_dict **data)
1561 1574
1562 if (mtime(fn) + max_time < (double) time(NULL)) { 1575 if (mtime(fn) + max_time < (double) time(NULL)) {
1563 /* actor data exists but also stinks */ 1576 /* actor data exists but also stinks */
1564
1565 /* touch the file */
1566 utimes(fn, NULL);
1567
1568 status = 205; /* "205: Reset Content" "110: Response Is Stale" */ 1577 status = 205; /* "205: Reset Content" "110: Response Is Stale" */
1569 } 1578 }
1570#endif /* STALE_ACTORS */ 1579
1580 return status;
1581}
1582
1583
1584int actor_get_refresh(snac *user, const char *actor, xs_dict **data)
1585/* gets an actor and requests and refresh if it's stale */
1586{
1587 int status = actor_get(actor, data);
1588
1589 if (status == 205)
1590 enqueue_actor_request(user, actor);
1571 1591
1572 return status; 1592 return status;
1573} 1593}
@@ -2429,6 +2449,21 @@ void enqueue_verify_links(snac *user)
2429} 2449}
2430 2450
2431 2451
2452void enqueue_actor_request(snac *user, const char *actor)
2453/* enqueues an actor request */
2454{
2455 xs *qmsg = _new_qmsg("actor_request", "", 0);
2456 char *ntid = xs_dict_get(qmsg, "ntid");
2457 xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
2458
2459 qmsg = xs_dict_append(qmsg, "actor", actor);
2460
2461 qmsg = _enqueue_put(fn, qmsg);
2462
2463 snac_debug(user, 1, xs_fmt("enqueue_actor_request %s", user->actor));
2464}
2465
2466
2432void enqueue_request_replies(snac *user, const char *id) 2467void enqueue_request_replies(snac *user, const char *id)
2433/* enqueues a request for the replies of a message */ 2468/* enqueues a request for the replies of a message */
2434{ 2469{
diff --git a/html.c b/html.c
index 59fd6c9..da37558 100644
--- a/html.c
+++ b/html.c
@@ -245,7 +245,7 @@ xs_html *html_msg_icon(snac *user, char *actor_id, const xs_dict *msg)
245 xs *actor = NULL; 245 xs *actor = NULL;
246 xs_html *actor_icon = NULL; 246 xs_html *actor_icon = NULL;
247 247
248 if (actor_id && valid_status(actor_get(actor_id, &actor))) { 248 if (actor_id && valid_status(actor_get_refresh(user, actor_id, &actor))) {
249 char *date = NULL; 249 char *date = NULL;
250 char *udate = NULL; 250 char *udate = NULL;
251 char *url = NULL; 251 char *url = NULL;
diff --git a/mastoapi.c b/mastoapi.c
index e14fc47..10fa40b 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -746,7 +746,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
746/* converts an ActivityPub note to a Mastodon status */ 746/* converts an ActivityPub note to a Mastodon status */
747{ 747{
748 xs *actor = NULL; 748 xs *actor = NULL;
749 actor_get(get_atto(msg), &actor); 749 actor_get_refresh(snac, get_atto(msg), &actor);
750 750
751 /* if the author is not here, discard */ 751 /* if the author is not here, discard */
752 if (actor == NULL) 752 if (actor == NULL)
diff --git a/snac.h b/snac.h
index f2bcedb..6876747 100644
--- a/snac.h
+++ b/snac.h
@@ -110,6 +110,8 @@ int object_del(const char *id);
110int object_del_if_unref(const char *id); 110int object_del_if_unref(const char *id);
111double object_ctime_by_md5(const char *md5); 111double object_ctime_by_md5(const char *md5);
112double object_ctime(const char *id); 112double object_ctime(const char *id);
113double object_mtime_by_md5(const char *md5);
114double object_mtime(const char *id);
113int object_admire(const char *id, const char *actor, int like); 115int object_admire(const char *id, const char *actor, int like);
114int object_unadmire(const char *id, const char *actor, int like); 116int object_unadmire(const char *id, const char *actor, int like);
115 117
@@ -172,6 +174,7 @@ xs_list *tag_search(char *tag, int skip, int show);
172 174
173int actor_add(const char *actor, xs_dict *msg); 175int actor_add(const char *actor, xs_dict *msg);
174int actor_get(const char *actor, xs_dict **data); 176int actor_get(const char *actor, xs_dict **data);
177int actor_get_refresh(snac *user, const char *actor, xs_dict **data);
175 178
176int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag); 179int static_get(snac *snac, const char *id, xs_val **data, int *size, const char *inm, xs_str **etag);
177void static_put(snac *snac, const char *id, const char *data, int size); 180void static_put(snac *snac, const char *id, const char *data, int size);
@@ -218,6 +221,7 @@ void enqueue_ntfy(const xs_str *msg, const char *ntfy_server, const char *ntfy_t
218void enqueue_message(snac *snac, const xs_dict *msg); 221void enqueue_message(snac *snac, const xs_dict *msg);
219void enqueue_close_question(snac *user, const char *id, int end_secs); 222void enqueue_close_question(snac *user, const char *id, int end_secs);
220void enqueue_verify_links(snac *user); 223void enqueue_verify_links(snac *user);
224void enqueue_actor_request(snac *user, const char *actor);
221void enqueue_request_replies(snac *user, const char *id); 225void enqueue_request_replies(snac *user, const char *id);
222int was_question_voted(snac *user, const char *id); 226int was_question_voted(snac *user, const char *id);
223 227