commit 0bbecf5
default
·
2024-12-22 08:26:17 +0000 UTC
parent 240f212
mastoapi: allow search for post URLs.
1 files changed,
+31,
-0
+31,
-0
1@@ -2377,6 +2377,37 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
2 if (xs_is_null(offset) || strcmp(offset, "0") == 0) {
3 /* reply something only for offset 0; otherwise,
4 apps like Tusky keep asking again and again */
5+ if (xs_startswith(q, "https://")) {
6+ xs *md5 = xs_md5_hex(q, strlen(q));
7+
8+ if (!timeline_here(&snac1, md5)) {
9+ xs *object = NULL;
10+ int status;
11+
12+ status = activitypub_request(&snac1, q, &object);
13+ snac_debug(&snac1, 1, xs_fmt("Request searched URL %s %d", q, status));
14+
15+ if (valid_status(status)) {
16+ /* got it; also request the actor */
17+ const char *attr_to = get_atto(object);
18+ xs *actor_obj = NULL;
19+
20+ if (!xs_is_null(attr_to)) {
21+ status = actor_request(&snac1, attr_to, &actor_obj);
22+
23+ snac_debug(&snac1, 1, xs_fmt("Request author %s of %s %d", attr_to, q, status));
24+
25+ if (valid_status(status)) {
26+ /* add the actor */
27+ actor_add(attr_to, actor_obj);
28+
29+ /* add the post to the timeline */
30+ timeline_add(&snac1, q, object);
31+ }
32+ }
33+ }
34+ }
35+ }
36
37 if (!xs_is_null(q)) {
38 if (xs_is_null(type) || strcmp(type, "accounts") == 0) {