commit df78584

default  ·  2023-04-11 17:59:02 +0000 UTC
parent a4051f7
Added support for statuses/:id and statuses/:id/context.
1 files changed,  +36, -1
+36, -1
 1@@ -789,11 +789,46 @@ int mastoapi_get_handler(const xs_dict *req, const char *q_path,
 2             if (valid_status(timeline_get_by_md5(&snac, id, &msg))) {
 3                 if (op == NULL) {
 4                     /* return the status itself */
 5+                    out = mastoapi_status(&snac, msg);
 6                 }
 7                 else
 8                 if (strcmp(op, "context") == 0) {
 9                     /* return ancestors and children */
10-                    srv_debug(0, xs_fmt("mastoapi status: context requested for %s", id));
11+                    xs *anc = xs_list_new();
12+                    xs *des = xs_list_new();
13+                    xs_list *p;
14+                    xs_str *v;
15+                    char pid[64];
16+
17+                    /* build the [grand]parent list, moving up */
18+                    strcpy(pid, id);
19+
20+                    while (object_parent(pid, pid, sizeof(pid))) {
21+                        xs *m2 = NULL;
22+
23+                        if (valid_status(timeline_get_by_md5(&snac, pid, &m2))) {
24+                            xs *st = mastoapi_status(&snac, m2);
25+                            anc = xs_list_append(anc, st);
26+                        }
27+                        else
28+                            break;
29+                    }
30+
31+                    /* build the children list */
32+                    xs *children = object_children(xs_dict_get(msg, "id"));
33+                    p = children;
34+                    while (xs_list_iter(&p, &v)) {
35+                        xs *m2 = NULL;
36+
37+                        if (valid_status(timeline_get_by_md5(&snac, v, &m2))) {
38+                            xs *st = mastoapi_status(&snac, m2);
39+                            des = xs_list_append(des, st);
40+                        }
41+                    }
42+
43+                    out = xs_dict_new();
44+                    out = xs_dict_append(out, "ancestors",   anc);
45+                    out = xs_dict_append(out, "descendants", des);
46                 }
47                 else
48                 if (strcmp(op, "reblogged_by") == 0) {